Changeset f975761fe7abe49e3bc883c08150fd8b60ecf011

Show
Ignore:
Timestamp:
03/09/08 18:35:41 (10 months ago)
Author:
KRKeegan <-NOSPAM-kevin@krkeegan.com>
git-committer:
KRKeegan <-NOSPAM-kevin@krkeegan.com> 1205105741 -0700
git-parent:

[5655f7fb1cf628281f5404cde09171e68e9a7c02]

git-author:
KRKeegan <-NOSPAM-kevin@krkeegan.com> 1205105741 -0700
Message:

Thread function to download from TiVo

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/admin/admin.py

    r5655f7f rf975761  
    11import os, socket, re, sys, ConfigParser, config, time 
    2 import urllib2 
     2import urllib2, cookielib, thread 
    33from xml.dom import minidom 
    44from ConfigParser import NoOptionError 
     
    1919p = os.path.sep.join(p) 
    2020config_file_path = os.path.join(p, 'pyTivo.conf') 
     21 
     22status = {} 
    2123 
    2224class Admin(Plugin): 
     
    158160            if (len(item.getElementsByTagName("UniqueId")) >= 1): 
    159161                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: 
    161167                link = item.getElementsByTagName("Links")[0] 
    162168                if (len(link.getElementsByTagName("CustomIcon")) >= 1): 
     
    172178                                    + str((int(entry['Duration'])/60*1000)%60).zfill(2) + ':' \ 
    173179                                    + 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))) 
    175181                         
    176182            data.append(entry) 
     
    181187        handler.end_headers() 
    182188        t = Template(file=os.path.join(SCRIPTDIR,'templates', 'npl.tmpl')) 
     189        t.subfolder = False 
     190        if folder != '/NowPlaying': 
     191            t.subfolder = True 
    183192        t.container = cname 
    184193        t.data = data 
    185194        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  
    55  <title>pyTivo - TiVo ToGo</title> 
    66</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"> 
    911  <tbody> 
    1012    <tr> 
     
    1820    <tr> 
    1921      <td> 
     22      <div style="visibility: visible; width: 800px; overflow: scroll; height: 450px; position: relative;"> 
    2023      <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 
    2127      #set $i = 0 
    2228      #for $row in $data 
     
    2834                  #end if 
    2935                  #if $row['ContentType'] == 'x-tivo-container/folder' 
    30                         <td width=8></td> 
     36                        <td></td> 
    3137                        <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> 
    3341                  #else 
    3442                        #if 'Icon' in $row 
    3543                                #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> 
    3745                                #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> 
    3947                                #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>                           
    4149                                #else 
    4250                                        <td width=8></td> 
     
    5361                        $row['Duration'] 
    5462                        </td> 
    55                         <td>$row['CaptureDate']</td> 
     63                        <td>$row['CaptureDate']</td><td><a href="#">Transfer This.</a></td> 
    5664                  #end if 
    5765                  </tr> 
    5866      #end for 
    5967      </table> 
     68      </div> 
    6069      </td> 
    6170    </tr>