mirror of
https://github.com/GeorgeSG/sarah.git
synced 2026-09-07 10:18:44 +00:00
Add Youtube integraion
- add python script to download youtube videos - add new Media tab in UI to download youtube videos - track PDS - Script to play latest PDS, play from Media tab - Automate latest PDS download
This commit is contained in:
@@ -38,6 +38,7 @@ updater:
|
||||
logger:
|
||||
default: warning
|
||||
logs:
|
||||
homeassistant.components.shell_command: debug
|
||||
homeassistant.components.amcrest: error
|
||||
zigpy.util: error
|
||||
|
||||
|
||||
@@ -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}""")
|
||||
@@ -122,7 +122,7 @@ cards:
|
||||
title: Packages
|
||||
|
||||
- type: "custom:travel-time-card"
|
||||
title: "Travel time"
|
||||
title: Travel time
|
||||
columns:
|
||||
- name
|
||||
- duration
|
||||
|
||||
@@ -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(',')}"
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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!"
|
||||
+8
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user