diff --git a/configuration.yaml b/configuration.yaml index ce242d5..a2105e9 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -38,6 +38,7 @@ updater: logger: default: warning logs: + homeassistant.components.shell_command: debug homeassistant.components.amcrest: error zigpy.util: error diff --git a/custom_scripts/youtube_download.py b/custom_scripts/youtube_download.py new file mode 100644 index 0000000..11fbae8 --- /dev/null +++ b/custom_scripts/youtube_download.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3.7 + +import sys +import youtube_dl +import os + +youtube_url = sys.argv[1] +out_name = sys.argv[2] if len(sys.argv) > 2 else 'temp' +out_folder = sys.argv[3] if len(sys.argv) > 3 else '' + +full_file_path = f"""~/.homeassistant/www/audio/youtube/{out_folder}{out_name}""" + +ydl = youtube_dl.YoutubeDL({'format': 'bestaudio', 'outtmpl': full_file_path}) + +with ydl: + result = ydl.extract_info(youtube_url, download=True) + os.system( + f"""ffmpeg -i {full_file_path} -acodec libmp3lame {full_file_path}.mp3""") + os.system(f"""rm {full_file_path}""") diff --git a/lovelace/00_home.yaml b/lovelace/00_home.yaml index 7671001..f17bcc9 100644 --- a/lovelace/00_home.yaml +++ b/lovelace/00_home.yaml @@ -122,7 +122,7 @@ cards: title: Packages - type: "custom:travel-time-card" - title: "Travel time" + title: Travel time columns: - name - duration diff --git a/lovelace/04_media.yaml b/lovelace/04_media.yaml new file mode 100644 index 0000000..b7628e1 --- /dev/null +++ b/lovelace/04_media.yaml @@ -0,0 +1,45 @@ +title: Media +path: media +panel: false +icon: mdi:play-circle-outline +badges: [] +cards: + - type: entities + title: Youtube controls + icon: mdi:youtube + show_header_toggle: false + entities: + - entity: input_text.youtube_download_url + type: "custom:text-input-row" + - entity: input_text.youtube_download_name + type: "custom:text-input-row" + + - type: entity-button + name: Download + icon: mdi:download + icon_height: 48px + tap_action: + action: call-service + service: script.youtube_download_selected + + - type: custom:config-template-card + entities: + - sensor.philip_defranco + - sensor.available_pds + card: + type: vertical-stack + cards: + - type: picture-entity + entity: sensor.philip_defranco + image: "${states['sensor.philip_defranco'].attributes.entity_picture}" + name: "Play the latest PDS" + show_state: false + tap_action: + action: call-service + service: script.youtube_play_latest_pds + - type: custom:text-element + text: "${states['sensor.philip_defranco'].state}" + - type: custom:text-element + text: "Available:" + - type: custom:text-element + text: "${states['sensor.available_pds'].state.split(',')}" diff --git a/lovelace/04_system.yaml b/lovelace/05_system.yaml similarity index 98% rename from lovelace/04_system.yaml rename to lovelace/05_system.yaml index fc44a50..5b0b005 100644 --- a/lovelace/04_system.yaml +++ b/lovelace/05_system.yaml @@ -7,6 +7,8 @@ cards: title: Automations show_header_toggle: false entities: + - automation.youtube_download_latest_pds + - type: custom:fold-entity-row head: type: custom:dummy-entity-row diff --git a/lovelace/05_covid_19.yaml b/lovelace/06_covid_19.yaml similarity index 100% rename from lovelace/05_covid_19.yaml rename to lovelace/06_covid_19.yaml diff --git a/lovelace/06_test.yaml b/lovelace/07_test.yaml similarity index 100% rename from lovelace/06_test.yaml rename to lovelace/07_test.yaml diff --git a/packages/modules/system.yaml b/packages/modules/system.yaml index 872b793..a498c5f 100644 --- a/packages/modules/system.yaml +++ b/packages/modules/system.yaml @@ -1,3 +1,10 @@ +sensor: + - platform: template + sensors: + sarah_url: + friendly_name: "SARAH's URL" + value_template: !secret sarah_url + script: sarah_restart: alias: System · Restart SARAH diff --git a/packages/modules/youtube.yaml b/packages/modules/youtube.yaml new file mode 100644 index 0000000..b42b82e --- /dev/null +++ b/packages/modules/youtube.yaml @@ -0,0 +1,65 @@ +sensor: + - platform: youtube + channel_id: UClFSU9_bUb4Rc6OYfTt5SPw + - platform: command_line + name: Available PDS + command: !secret youtube_pds_list_command + scan_interval: 30 + - platform: command_line + name: Available Youtube clips + command: !secret youtube_list_command + scan_interval: 30 + +input_text: + youtube_download_url: + name: Youtube download URL + icon: mdi:link + initial: "" + youtube_download_name: + name: Youtube download name + icon: mdi:format-letter-case + initial: "" + +shell_command: + youtube_download: !secret youtube_download_command + +script: + youtube_play_latest_pds: + alias: Youtube · Play latest PDS + sequence: + - service: script.music_join_sonoses + - service: media_player.play_media + data_template: + entity_id: media_player.master_bedroom + media_content_id: "{{ states('sensor.sarah_url') }}/local/audio/youtube/pds/{{ states('sensor.available_pds').split(',') | last }}" + media_content_type: "music" + + youtube_download_selected: + alias: Youtube · Download selected video + sequence: + - service: shell_command.youtube_download + data_template: + url: "{{ states('input_text.youtube_download_url') }}" + name: "{{ states('input_text.youtube_download_name') }}" + - service: input_text.set_value + entity_id: + - input_text.youtube_download_url + - input_text.youtube_download_name + data: + value: "" + +automation: + - id: youtube_download_latest_pds + alias: Youtube · Download latest PDS + trigger: + platform: state + entity_id: sensor.philip_defranco + action: + - service: shell_command.youtube_download + data_template: + url: "{{ state_attr('sensor.philip_defranco', 'url') }}" + name: "{{ state_attr('sensor.philip_defranco', 'published')[0:10] }}" + folder: "pds/" + - service: script.say + data: + message: "Just wanted to let you know - a new PDS is available!" diff --git a/ui-lovelace.yaml b/ui-lovelace.yaml index 213311f..27a44a6 100644 --- a/ui-lovelace.yaml +++ b/ui-lovelace.yaml @@ -37,6 +37,10 @@ resources: url: /hacsfiles/lovelace-dummy-entity-row/dummy-entity-row.js - type: module url: /hacsfiles/lovelace-slider-entity-row/slider-entity-row.js + - type: module + url: /hacsfiles/lovelace-text-input-row/lovelace-text-input-row.js + - type: module + url: /hacsfiles/text-element/text-element.js title: Sarah views: @@ -44,6 +48,7 @@ views: - !include lovelace/01_living_room.yaml - !include lovelace/02_master_bedroom.yaml - !include lovelace/03_kitchen.yaml - - !include lovelace/04_system.yaml - - !include lovelace/05_covid_19.yaml - - !include lovelace/06_test.yaml + - !include lovelace/04_media.yaml + - !include lovelace/05_system.yaml + - !include lovelace/06_covid_19.yaml + - !include lovelace/07_test.yaml