Input_text / Alexa Intent => youtube search => media_player

Hi,
Wonderful script, sadly stuck with hass login failed errors. Anyone can help out to complete youtube.py with hass token, not able to get it working with authorization bearer token.

I tried below but didn’t work out:

token = ‘MYTOKEN’

headers = {‘Content-type’: ‘application/json’, ‘Authorization’: 'Bearer ’ + token}

thanks

1 Like

@RobDYI
Short note to thank you for this script; works great. Tested with chromecast and performs well.
Unfortunately it doesn’t with Bose-Soundtouch and that’s just another flaw of these speakers. They’re “smart” integration is rubbish to be polite.

This might help. If it doesn’t you can publish the url on a mqtt topic and get HA to automate playing that url by watching the mqtt topic.

Example: Python

import requests

url = "https://your.awesome.home/api/error/all"
headers = {
    'Authorization': "Bearer ABCDEFGH",
}
response = requests.request('GET', url, headers=headers)

print(response.text)
1 Like

Much cleaner youtube.py which does not require any additional pip installs.
Usage: youtube.py 'search term’

import requests
import json
import sys

key = 'YOUR KEY'
address = 'https://home.assistant:8123/'
auth = 'bearer token for webrequest authentication'

requests.post(address + "api/states/input_text.youtube", data=json.dumps({"state": "https://www.youtube.com/watch?v="+requests.get('https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=' +  sys.argv[1] + '&type=video&key=' + key).json()["items"][0]["id"]["videoId"]}), headers={'Content-type': 'application/json', 'Authorization': 'Bearer ' + auth},verify=False)
3 Likes

Hello,
I want to play from youtube the first result of a spoken searched phrase.
I’m confused from all the posts, can someone please explain me step by step how to do this?
I’m on HASS.IO