| | 133 | password = '1586767899' #TiVo MAK |
|---|
| | 134 | |
|---|
| | 135 | r=urllib2.Request(theurl) |
|---|
| | 136 | auth_handler = urllib2.HTTPDigestAuthHandler() |
|---|
| | 137 | auth_handler.add_password('TiVo DVR', '192.168.1.150', 'tivo', password) |
|---|
| | 138 | opener = urllib2.build_opener(auth_handler) |
|---|
| | 139 | urllib2.install_opener(opener) |
|---|
| | 140 | |
|---|
| | 141 | try: |
|---|
| | 142 | handle = urllib2.urlopen(r) |
|---|
| | 143 | except IOError, e: |
|---|
| | 144 | print "Possibly wrong Media Access Key, or IP address for your TiVo." |
|---|
| | 145 | handler.send_response(404) |
|---|
| | 146 | handler.end_headers() |
|---|
| | 147 | return |
|---|
| | 148 | thepage = handle.read() |
|---|
| | 149 | |
|---|
| | 150 | xmldoc = minidom.parseString(thepage) |
|---|
| | 151 | items = xmldoc.getElementsByTagName('Item') |
|---|
| | 152 | |
|---|
| | 153 | data = [] |
|---|
| | 154 | for item in items: |
|---|
| | 155 | entry = {} |
|---|
| | 156 | entry['Title'] = item.getElementsByTagName("Title")[0].firstChild.data |
|---|
| | 157 | entry['ContentType'] = item.getElementsByTagName("ContentType")[0].firstChild.data |
|---|
| | 158 | if (len(item.getElementsByTagName("UniqueId")) >= 1): |
|---|
| | 159 | entry['UniqueId'] = item.getElementsByTagName("UniqueId")[0].firstChild.data |
|---|
| | 160 | if entry['ContentType'] != 'x-tivo-container/folder': |
|---|
| | 161 | link = item.getElementsByTagName("Links")[0] |
|---|
| | 162 | if (len(link.getElementsByTagName("CustomIcon")) >= 1): |
|---|
| | 163 | entry['Icon'] = link.getElementsByTagName("CustomIcon")[0].getElementsByTagName("Url")[0].firstChild.data |
|---|
| | 164 | keys = ['SourceSize', 'Duration', 'CaptureDate', 'EpisodeTitle', 'Description', 'SourceChannel', 'SourceStation'] |
|---|
| | 165 | for key in keys: |
|---|
| | 166 | try: |
|---|
| | 167 | entry[key] = item.getElementsByTagName(key)[0].firstChild.data |
|---|
| | 168 | except: |
|---|
| | 169 | entry[key] = '' |
|---|
| | 170 | entry['SourceSize'] = "%.3f GB" % float(float(entry['SourceSize'])/(1024*1024*1024)) |
|---|
| | 171 | entry['Duration'] = str(int(entry['Duration'])/(60*60*1000)).zfill(2) + ':' \ |
|---|
| | 172 | + str((int(entry['Duration'])/60*1000)%60).zfill(2) + ':' \ |
|---|
| | 173 | + str((int(entry['Duration'])/1000)%60).zfill(2) |
|---|
| | 174 | entry['CaptureDate'] = time.strftime("%b %d, %Y <br> %H:%M:%S", time.localtime(int(entry['CaptureDate'], 16))) |
|---|
| | 175 | |
|---|
| | 176 | data.append(entry) |
|---|
| | 177 | |
|---|
| | 178 | subcname = query['Container'][0] |
|---|
| | 179 | cname = subcname.split('/')[0] |
|---|
| | 180 | handler.send_response(200) |
|---|
| | 181 | handler.end_headers() |
|---|
| | 182 | t = Template(file=os.path.join(SCRIPTDIR,'templates', 'npl.tmpl')) |
|---|
| | 183 | t.container = cname |
|---|
| | 184 | t.data = data |
|---|
| | 185 | handler.wfile.write(t) |
|---|