Skip to content

Instantly share code, notes, and snippets.

Last active Mar 25, 2020
What would you like to do?
#!/usr/bin/env python3
import sys
import re
import json
import urllib.request
import pychromecast
from import YouTubeController
# Your Chromecast device name here
CAST_NAME = 'Your Chromecast device name here'
# Your Google API key here (using YouTube Data API v3)
API_KEY = 'Your Google API key here'
# Your AsaCoco pusher
PLAYLIST_ID = 'PLw58RgSzDmjr7hbo0zrfaQ027uMc6WHfO'
url = '{0}&maxResults=1&key={1}'.format(PLAYLIST_ID, API_KEY)
res = urllib.request.urlopen(url)
data = json.loads('utf-8'))
# find the freshest AsaCoco
item = data['items'][0]
title = item['snippet']['title']
video_id = item['snippet']['resourceId']['videoId']
print("found: {0} {1}".format(title, video_id))
# play it on Chromecast
chromecasts = pychromecast.get_chromecasts()
cast = next(cc for cc in chromecasts if cc.device.friendly_name == CAST_NAME)
yt = YouTubeController()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment