Last active
August 29, 2015 14:22
-
-
Save vgmoose/c881f605a9226344c29c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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