################################ # Tivo Connector v0.3 # Author: John R. Tipton # Site: http://trylinux.org ################################ ################################ # Settings ################################ url="https://tivo_ip" mac="media access code" ################################ # Dont change the following ################################ import pycurl import re import urllib import commands import sys,urllib from htmlentitydefs import name2codepoint charrefpat = re.compile(r'&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?') def htmldecode(text): """Decode HTML entities in the given text.""" if type(text) is unicode: uchr = unichr else: uchr = lambda value: value > 255 and unichr(value) or chr(value) def entitydecode(match, uchr=uchr): entity = match.group(1) if entity.startswith('#x'): return uchr(int(entity[2:], 16)) elif entity.startswith('#'): return uchr(int(entity[1:])) elif entity in name2codepoint: return uchr(name2codepoint[entity]) else: return match.group(0) return charrefpat.sub(entitydecode, text) def htc(m): return chr(int(m.group(1),16)) def urldecode(url): rex=re.compile('%([0-9a-hA-H][0-9a-hA-H])',re.M) return rex.sub(htc,url) c = pycurl.Curl() c.setopt(pycurl.URL, url) c.setopt(pycurl.HTTPHEADER, ["Accept:"]) c.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_DIGEST) c.setopt(pycurl.SSL_VERIFYPEER, 0) c.setopt(pycurl.SSL_VERIFYHOST, 0) c.setopt(pycurl.USERPWD, "tivo:" + mac) import StringIO b = StringIO.StringIO() c.setopt(pycurl.WRITEFUNCTION, b.write) c.setopt(pycurl.FOLLOWLOCATION, 1) c.setopt(pycurl.MAXREDIRS, 5) c.perform() r1 = b.getvalue() shows_count = r1.count("left") print shows_count , "shows in Now Playing\n" showlist = r1.split("left") shows = [] show_counter = 0 for show in showlist: m = re.match(".*?([^<]*).*?(http://[^\"]*)\"", show) if m: show_details = show_counter, htmldecode(m.group(1)), htmldecode(urldecode(m.group(2))).replace(' ', '%20') shows.append(show_details) show_counter = show_counter+1 for (count, show, url) in shows: print count, "-", show request = raw_input("Which show do you want to select? ") action = raw_input("Watch or get?(w/g)") if (action == 'w'): cmd = "curl -c cookies --digest --insecure -u tivo:" + mac +" \"" + shows[request][2] + "\" | tivodecode -m " + mac + " - | mplayer -cache 50000 -" else: cmd = "curl -c cookies --digest --insecure -o \"" + shows[request][1] + ".tivo\" -u tivo:" + mac +" \"" + shows[request][2] + "\"" #print cmd status = commands.getoutput(cmd) print status