Changeset f975761fe7abe49e3bc883c08150fd8b60ecf011
- Timestamp:
- 03/09/08 18:35:41 (10 months ago)
- git-parent:
- Files:
-
- plugins/admin/admin.py (modified) (5 diffs)
- plugins/admin/templates/npl.tmpl (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/admin/admin.py
r5655f7f rf975761 1 1 import os, socket, re, sys, ConfigParser, config, time 2 import urllib2 2 import urllib2, cookielib, thread 3 3 from xml.dom import minidom 4 4 from ConfigParser import NoOptionError … … 19 19 p = os.path.sep.join(p) 20 20 config_file_path = os.path.join(p, 'pyTivo.conf') 21 22 status = {} 21 23 22 24 class Admin(Plugin): … … 158 160 if (len(item.getElementsByTagName("UniqueId")) >= 1): 159 161 entry['UniqueId'] = item.getElementsByTagName("UniqueId")[0].firstChild.data 160 if entry['ContentType'] != 'x-tivo-container/folder': 162 if entry['ContentType'] == 'x-tivo-container/folder': 163 entry['TotalItems'] = item.getElementsByTagName("TotalItems")[0].firstChild.data 164 entry['LastChangeDate'] = item.getElementsByTagName("LastChangeDate")[0].firstChild.data 165 entry['LastChangeDate'] = time.strftime("%b %d, %Y", time.localtime(int(entry['LastChangeDate'], 16))) 166 else: 161 167 link = item.getElementsByTagName("Links")[0] 162 168 if (len(link.getElementsByTagName("CustomIcon")) >= 1): … … 172 178 + str((int(entry['Duration'])/60*1000)%60).zfill(2) + ':' \ 173 179 + 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)))180 entry['CaptureDate'] = time.strftime("%b %d, %Y", time.localtime(int(entry['CaptureDate'], 16))) 175 181 176 182 data.append(entry) … … 181 187 handler.end_headers() 182 188 t = Template(file=os.path.join(SCRIPTDIR,'templates', 'npl.tmpl')) 189 t.subfolder = False 190 if folder != '/NowPlaying': 191 t.subfolder = True 183 192 t.container = cname 184 193 t.data = data 185 194 handler.wfile.write(t) 186 195 196 def ToGo(self, handler, query): 197 theurl = "http://192.168.1.150/download/Survivor%20Micronesia%20--%20Fans%20vs.%20Favorites.TiVo?Container=%2FNowPlaying&id=385244" 198 password = '' #TiVo MAK 199 tivoIP = '192.168.1.150' 200 outfile = "video.tivo" 201 202 status[theurl] = {'running':True, 'error':'', 'rate':''} 203 204 thread.start_new_thread(get_tivo_file, (theurl, password, tivoIP, outfile)) 205 206 207 def get_tivo_file(url, mak, tivoIP, outfile): 208 global status 209 cj = cookielib.LWPCookieJar() 210 211 r=urllib2.Request(url) 212 auth_handler = urllib2.HTTPDigestAuthHandler() 213 auth_handler.add_password('TiVo DVR', tivoIP, 'tivo', mak) 214 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj), auth_handler) 215 urllib2.install_opener(opener) 216 217 try: 218 handle = urllib2.urlopen(r) 219 except IOError, e: 220 #If we get "Too many transfers error" try a second time. For some reason 221 #urllib2 does not properly close connections when a transfer is canceled. 222 if e.code == 503: 223 try: 224 handle = urllib2.urlopen(r) 225 except IOError, e: 226 status[url]['running'] = False 227 status[url]['error'] = e.code 228 return 229 else: 230 status[url]['running'] = False 231 status[url]['error'] = e.code 232 return 233 234 f = open(outfile, 'wb') 235 kilobytes = 0 236 start_time = time.time() 237 output = handle.read(1024) 238 while status[url]['running'] and output != '': 239 kilobytes += 1 240 f.write(output) 241 if ((time.time() - start_time) >= 5): 242 status[url]['rate'] = int(kilobytes/(time.time() - start_time)) 243 kilobytes = 0 244 start_time = time.time() 245 output = handle.read(1024) 246 status[url]['running'] = False 247 handle.close() 248 f.close() 249 return 250 plugins/admin/templates/npl.tmpl
r33aa537 rf975761 5 5 <title>pyTivo - TiVo ToGo</title> 6 6 </head> 7 <body> 8 <table align=center style="text-align: left;" border="1" cellpadding="2" cellspacing="2"> 7 <body style="background-color: rgb(250, 250, 250);"> 8 9 <p align="center"><font size="6">pyTivo TiVo ToGo</font></p> 10 <table style="border: 1px solid rgb(220, 220, 220);background-color: rgb(255, 255, 255);text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="0" cellspacing="4"> 9 11 <tbody> 10 12 <tr> … … 18 20 <tr> 19 21 <td> 22 <div style="visibility: visible; width: 800px; overflow: scroll; height: 450px; position: relative;"> 20 23 <table> 24 #if $subfolder == True 25 <tr><td colspan=5><a href="/TiVoConnect?Command=NPL&Container=$container">Back to Now Playing List</a></td></tr> 26 #end if 21 27 #set $i = 0 22 28 #for $row in $data … … 28 34 #end if 29 35 #if $row['ContentType'] == 'x-tivo-container/folder' 30 <td width=8></td>36 <td></td> 31 37 <td><a href='/TiVoConnect?Command=NPL&Container=$(container)&Folder=$(row["UniqueId"])'>$row['Title'] </a></td> 32 <td></td><td></td> 38 <td>$(row["TotalItems"]) Items</td> 39 <td>$row["LastChangeDate"]</td> 40 <td></td> 33 41 #else 34 42 #if 'Icon' in $row 35 43 #if $row['Icon'] == 'urn:tivo:image:expires-soon-recording' 36 <td width=8 bgcolor='yellow'></td>44 <td><table><tr><td height=18 width=8 bgcolor='yellow'> </td></tr></table></td> 37 45 #else if $row['Icon'] == 'urn:tivo:image:expired-recording' 38 <td width=8 bgcolor='yellow'><b> ! </b></td>46 <td><table><tr><td height=18 width=8 bgcolor='yellow'><b> ! </b></td></tr></table></td> 39 47 #else if $row['Icon'] == 'urn:tivo:image:save-until-i-delete-recording' 40 <td width=8 bgcolor='green'></td>48 <td><table><tr><td height=18 width=8 bgcolor='green'></td></tr></table></td> 41 49 #else 42 50 <td width=8></td> … … 53 61 $row['Duration'] 54 62 </td> 55 <td>$row['CaptureDate']</td> 63 <td>$row['CaptureDate']</td><td><a href="#">Transfer This.</a></td> 56 64 #end if 57 65 </tr> 58 66 #end for 59 67 </table> 68 </div> 60 69 </td> 61 70 </tr>
