Skip to content

Instantly share code, notes, and snippets.

@vgmoose
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgmoose/c881f605a9226344c29c to your computer and use it in GitHub Desktop.
Save vgmoose/c881f605a9226344c29c to your computer and use it in GitHub Desktop.
import urllib, subprocess, os
# fetches latest youtube video from specified channel and casts to chromecast
# needs to be run as root to scan the network for the mac address
# requires: castnow and arp-scan installed
author = "rhettandlink2" # youtube channel
mac = "UR:MA:CA:DD:RE:SS" # chromecast mac address
iface = "wlan0" # interface to LAN
inp = urllib.urlopen(r'https://www.youtube.com/user/'+author+'/videos')
first = '<a href="/watch?v='
content = inp.read()
inp.close()
loc = content.find(first)
if loc < 0:
exit()
trimcontent = content[loc+len(first):]
loc2 = trimcontent.find("\"")
if loc2 < 0:
exit()
output = trimcontent[:loc2]
try:
network = subprocess.check_output("arp-scan --interface="+iface+" --localnet | grep "+mac, shell=True)
except:
print "arp-scan failed, make sure it is installed and you are root"
exit()
ip = network.split()[0]
url = "https://youtube.com/watch?v="+output
os.system("castnow --quiet --address "+ip+" "+url+" &")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment