Changeset 5d5b39ad7a7b0586f6da77ad6db7351b81f185a2
- Timestamp:
- 03/11/08 00:55:11 (8 months ago)
- git-parent:
- Files:
-
- plugins/admin/admin.py (modified) (7 diffs)
- plugins/admin/templates/npl.tmpl (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/admin/admin.py
r6e208fc r5d5b39a 149 149 if 'Folder' in query: 150 150 folder += '/' + str(query['Folder'][0]) 151 tivoIP = tivo_mak.split(':')[0] 152 theurl = 'https://'+ tivoIP +'/TiVoConnect?Command=QueryContainer&Container=' + folder 153 154 password = tivo_mak.split(':')[1] #TiVo MAK 155 156 r=urllib2.Request(theurl) 157 auth_handler = urllib2.HTTPDigestAuthHandler() 158 auth_handler.add_password('TiVo DVR', tivoIP, 'tivo', password) 159 opener = urllib2.build_opener(auth_handler) 160 urllib2.install_opener(opener) 161 162 if theurl in tivo_cache: #check to see if we have accessed this page before 163 if tivo_cache[theurl]['thepage'] == '' or (time.time() - tivo_cache[theurl]['thepage_time']) >= 60: #if page is empty or old then retreive it 151 if 'TiVo' in query: 152 tivoIP = query['TiVo'][0] 153 theurl = 'https://'+ tivoIP +'/TiVoConnect?Command=QueryContainer&Container=' + folder 154 155 password = tivo_mak #TiVo MAK 156 157 r=urllib2.Request(theurl) 158 auth_handler = urllib2.HTTPDigestAuthHandler() 159 auth_handler.add_password('TiVo DVR', tivoIP, 'tivo', password) 160 opener = urllib2.build_opener(auth_handler) 161 urllib2.install_opener(opener) 162 163 if theurl in tivo_cache: #check to see if we have accessed this page before 164 if tivo_cache[theurl]['thepage'] == '' or (time.time() - tivo_cache[theurl]['thepage_time']) >= 60: #if page is empty or old then retreive it 165 try: 166 handle = urllib2.urlopen(r) 167 except IOError, e: 168 print "Possibly wrong Media Access Key, or IP address for your TiVo." 169 handler.send_response(404) 170 handler.end_headers() 171 return 172 tivo_cache[theurl]['thepage'] = handle.read() 173 tivo_cache[theurl]['thepage_time'] = time.time() 174 else: #not in cache 164 175 try: 165 176 handle = urllib2.urlopen(r) … … 168 179 handler.send_response(404) 169 180 handler.end_headers() 170 return 181 return 182 tivo_cache[theurl] = {} 171 183 tivo_cache[theurl]['thepage'] = handle.read() 172 184 tivo_cache[theurl]['thepage_time'] = time.time() 173 else: #not in cache 174 tivo_cache[theurl] = {} 175 try: 176 handle = urllib2.urlopen(r) 177 except IOError, e: 178 print "Possibly wrong Media Access Key, or IP address for your TiVo." 179 handler.send_response(404) 180 handler.end_headers() 181 return 182 tivo_cache[theurl]['thepage'] = handle.read() 183 tivo_cache[theurl]['thepage_time'] = time.time() 184 185 xmldoc = minidom.parseString(tivo_cache[theurl]['thepage']) 186 items = xmldoc.getElementsByTagName('Item') 187 188 data = [] 189 for item in items: 190 entry = {} 191 entry['Title'] = item.getElementsByTagName("Title")[0].firstChild.data 192 entry['ContentType'] = item.getElementsByTagName("ContentType")[0].firstChild.data 193 if (len(item.getElementsByTagName("UniqueId")) >= 1): 194 entry['UniqueId'] = item.getElementsByTagName("UniqueId")[0].firstChild.data 195 if entry['ContentType'] == 'x-tivo-container/folder': 196 entry['TotalItems'] = item.getElementsByTagName("TotalItems")[0].firstChild.data 197 entry['LastChangeDate'] = item.getElementsByTagName("LastChangeDate")[0].firstChild.data 198 entry['LastChangeDate'] = time.strftime("%b %d, %Y", time.localtime(int(entry['LastChangeDate'], 16))) 199 else: 200 link = item.getElementsByTagName("Links")[0] 201 if (len(link.getElementsByTagName("CustomIcon")) >= 1): 202 entry['Icon'] = link.getElementsByTagName("CustomIcon")[0].getElementsByTagName("Url")[0].firstChild.data 203 if (len(link.getElementsByTagName("Content")) >= 1): 204 entry['Url'] = link.getElementsByTagName("Content")[0].getElementsByTagName("Url")[0].firstChild.data 205 parse_url = urlparse(entry['Url']) 206 entry['Url'] = quote('http://' + parse_url[1].split(':')[0] + parse_url[2] + "?" + parse_url[4]) 207 print entry['Url'] 208 keys = ['SourceSize', 'Duration', 'CaptureDate', 'EpisodeTitle', 'Description', 'SourceChannel', 'SourceStation'] 209 for key in keys: 210 try: 211 entry[key] = item.getElementsByTagName(key)[0].firstChild.data 212 except: 213 entry[key] = '' 214 entry['SourceSize'] = "%.3f GB" % float(float(entry['SourceSize'])/(1024*1024*1024)) 215 entry['Duration'] = str(int(entry['Duration'])/(60*60*1000)).zfill(2) + ':' \ 216 + str((int(entry['Duration'])%(60*60*1000))/(60*1000)).zfill(2) + ':' \ 217 + str((int(entry['Duration'])/1000)%60).zfill(2) 218 entry['CaptureDate'] = time.strftime("%b %d, %Y", time.localtime(int(entry['CaptureDate'], 16))) 219 220 data.append(entry) 221 185 186 xmldoc = minidom.parseString(tivo_cache[theurl]['thepage']) 187 items = xmldoc.getElementsByTagName('Item') 188 189 data = [] 190 for item in items: 191 entry = {} 192 entry['Title'] = item.getElementsByTagName("Title")[0].firstChild.data 193 entry['ContentType'] = item.getElementsByTagName("ContentType")[0].firstChild.data 194 if (len(item.getElementsByTagName("UniqueId")) >= 1): 195 entry['UniqueId'] = item.getElementsByTagName("UniqueId")[0].firstChild.data 196 if entry['ContentType'] == 'x-tivo-container/folder': 197 entry['TotalItems'] = item.getElementsByTagName("TotalItems")[0].firstChild.data 198 entry['LastChangeDate'] = item.getElementsByTagName("LastChangeDate")[0].firstChild.data 199 entry['LastChangeDate'] = time.strftime("%b %d, %Y", time.localtime(int(entry['LastChangeDate'], 16))) 200 else: 201 link = item.getElementsByTagName("Links")[0] 202 if (len(link.getElementsByTagName("CustomIcon")) >= 1): 203 entry['Icon'] = link.getElementsByTagName("CustomIcon")[0].getElementsByTagName("Url")[0].firstChild.data 204 if (len(link.getElementsByTagName("Content")) >= 1): 205 entry['Url'] = link.getElementsByTagName("Content")[0].getElementsByTagName("Url")[0].firstChild.data 206 parse_url = urlparse(entry['Url']) 207 entry['Url'] = quote('http://' + parse_url[1].split(':')[0] + parse_url[2] + "?" + parse_url[4]) 208 keys = ['SourceSize', 'Duration', 'CaptureDate', 'EpisodeTitle', 'Description', 'SourceChannel', 'SourceStation'] 209 for key in keys: 210 try: 211 entry[key] = item.getElementsByTagName(key)[0].firstChild.data 212 except: 213 entry[key] = '' 214 entry['SourceSize'] = "%.3f GB" % float(float(entry['SourceSize'])/(1024*1024*1024)) 215 entry['Duration'] = str(int(entry['Duration'])/(60*60*1000)).zfill(2) + ':' \ 216 + str((int(entry['Duration'])%(60*60*1000))/(60*1000)).zfill(2) + ':' \ 217 + str((int(entry['Duration'])/1000)%60).zfill(2) 218 entry['CaptureDate'] = time.strftime("%b %d, %Y", time.localtime(int(entry['CaptureDate'], 16))) 219 220 data.append(entry) 221 else: 222 data = [] 223 tivoIP = '' 224 225 print len(data) 222 226 subcname = query['Container'][0] 223 227 cname = subcname.split('/')[0] … … 229 233 t.subfolder = True 230 234 t.status = status 235 print handler.tivos 236 t.tivos = handler.tivos 237 t.tivoIP = tivoIP 231 238 t.container = cname 232 239 t.data = data 233 240 t.unquote = unquote 241 t.len = len 234 242 handler.wfile.write(t) 235 243 … … 294 302 parse_url = urlparse(str(query['Url'][0])) 295 303 theurl = 'http://' + parse_url[1].split(':')[0] + parse_url[2] + "?" + parse_url[4] 296 print theurl 297 password = tivo_mak.split(':')[1] #TiVo MAK 298 tivoIP = str(tivo_mak.split(':')[0]) 304 password = tivo_mak #TiVo MAK 305 tivoIP = query['TiVo'][0] 299 306 name = unquote(parse_url[2])[10:300].split('.') 300 307 name.insert(-1," - " + unquote(parse_url[4]).split("id=")[1] + ".") … … 310 317 t.container = cname 311 318 t.time = '3' 312 t.url = '/TiVoConnect?Command=NPL&Container=' + cname 319 t.url = '/TiVoConnect?Command=NPL&Container=' + cname + '&TiVo=' + query['TiVo'][0] 313 320 t.text = '<h3>Transfer Initiated.</h3> <br>You selected transfer has been initiated.'+\ 314 '<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '"> ToGo</a> page will reload in 3 seconds.'321 '<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '&TiVo=' + query['TiVo'][0] +'"> ToGo</a> page will reload in 3 seconds.' 315 322 handler.wfile.write(t) 316 323 else: … … 320 327 t.container = cname 321 328 t.time = '10' 322 t.url = '/TiVoConnect?Command=NPL&Container=' + cname 329 t.url = '/TiVoConnect?Command=NPL&Container=' + cname + '&TiVo=' + query['TiVo'][0] 323 330 t.text = '<h3>Missing Data.</h3> <br>You must set both "tivo_mak" and "togo_path" before using this function.'+\ 324 '<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '"> ToGo</a> page will reload in 10 seconds.'331 '<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '&TiVo=' + query['TiVo'][0] +'"> ToGo</a> page will reload in 10 seconds.' 325 332 handler.wfile.write(t) 326 333 … … 338 345 t.container = cname 339 346 t.time = '3' 340 t.url = '/TiVoConnect?Command=NPL&Container=' + cname 347 t.url = '/TiVoConnect?Command=NPL&Container=' + cname + '&TiVo=' + query['TiVo'][0] 341 348 t.text = '<h3>Transfer Stopped.</h3> <br>Your transfer has been stopped.'+\ 342 '<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '"> ToGo</a> page will reload in 3 seconds.'343 handler.wfile.write(t) 349 '<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '&TiVo=' + query['TiVo'][0] +'"> ToGo</a> page will reload in 3 seconds.' 350 handler.wfile.write(t) plugins/admin/templates/npl.tmpl
r9d2b62c r5d5b39a 12 12 <tr> 13 13 <td style="height: 48px; width: 483px;"> 14 <select name="tivoList"> 15 <option selected="selected">My Tivo</option> 16 <option>Your TiVo</option> 14 <form method="get" action="/TiVoConnect"> 15 <input type="hidden" name="Command" value="NPL"> 16 <input type="hidden" name="Container" value="$(container)"> 17 <select name="TiVo"> 18 #for $tsn in $tivos 19 <option selected="selected" value="$tivos[$tsn]">$tsn</option> 20 #end for 17 21 </select> 18 <input value="View Now Playing List" name="NPL" type="button"> </td> 22 <input value="View Now Playing List" type="submit"> 23 </form> 24 </td> 19 25 </tr> 20 26 <tr> … … 23 29 <table> 24 30 #if $subfolder == True 25 <tr><td colspan=5><a href="/TiVoConnect?Command=NPL&Container=$container ">Back to Now Playing List</a></td></tr>31 <tr><td colspan=5><a href="/TiVoConnect?Command=NPL&Container=$container&TiVo=$tivoIP">Back to Now Playing List</a></td></tr> 26 32 #end if 27 33 #set $i = 0 28 #for $row in $data34 #for $row in $data 29 35 #set $i += 1 30 36 #if $i%2 31 <tr style="background-color: rgb(250, 250, 250);">37 <tr style="background-color: rgb(250, 250, 250);"> 32 38 #else 33 <tr>39 <tr> 34 40 #end if 35 41 #if $row['ContentType'] == 'x-tivo-container/folder' 36 42 <td></td> 37 <td><a href='/TiVoConnect?Command=NPL&Container=$(container)&Folder=$(row["UniqueId"]) '>$row['Title'] </a></td>43 <td><a href='/TiVoConnect?Command=NPL&Container=$(container)&Folder=$(row["UniqueId"])&TiVo=$tivoIP'>$row['Title'] </a></td> 38 44 <td NOWRAP align="center">$(row["TotalItems"]) Items</td> 39 45 <td NOWRAP align="center">$row["LastChangeDate"]</td> … … 68 74 #if $this_status['running'] and $this_status['rate'] != "" 69 75 Transfering - $this_status['rate'] KB/s<br> 70 <a href="/TiVoConnect?Command=ToGoStop&Container=$(container)&Url=$(row['Url']) ">Stop Transfer</a>76 <a href="/TiVoConnect?Command=ToGoStop&Container=$(container)&Url=$(row['Url'])&TiVo=$tivoIP">Stop Transfer</a> 71 77 #elif $this_status['running'] and $this_status['rate'] == "" 72 78 Initiating Transfer.<br> … … 74 80 #elif $this_status['error'] 75 81 Error - $this_status['error']<br> 76 <a href="/TiVoConnect?Command=ToGo&Container=$(container)&Url=$(row['Url']) ">Try Transfer Again.</a>82 <a href="/TiVoConnect?Command=ToGo&Container=$(container)&Url=$(row['Url'])&TiVo=$tivoIP">Try Transfer Again.</a> 77 83 #elif $this_status['finished'] 78 84 Transfer Complete! 79 85 #else 80 86 Transfer Stopped<br> 81 <a href="/TiVoConnect?Command=ToGo&Container=$(container)&Url=$(row['Url']) ">Try Transfer Again.</a>87 <a href="/TiVoConnect?Command=ToGo&Container=$(container)&Url=$(row['Url'])&TiVo=$tivoIP">Try Transfer Again.</a> 82 88 #endif 83 89 #else 84 <a href="/TiVoConnect?Command=ToGo&Container=$(container)&Url=$(row['Url']) ">Transfer This.</a>90 <a href="/TiVoConnect?Command=ToGo&Container=$(container)&Url=$(row['Url'])&TiVo=$tivoIP">Transfer This.</a> 85 91 #end if 86 92 </td>
