Changeset 5d5b39ad7a7b0586f6da77ad6db7351b81f185a2

Show
Ignore:
Timestamp:
03/11/08 00:55:11 (8 months ago)
Author:
KRKeegan <-NOSPAM-kevin@krkeegan.com>
git-committer:
KRKeegan <-NOSPAM-kevin@krkeegan.com> 1205214911 -0700
git-parent:

[e08b04950ca91bfe9b5725c7c58862b6d37d7188]

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

Allow selection of TiVo

Files:

Legend:

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

    r6e208fc r5d5b39a  
    149149        if 'Folder' in query: 
    150150            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 
    164175                try: 
    165176                    handle = urllib2.urlopen(r) 
     
    168179                    handler.send_response(404) 
    169180                    handler.end_headers() 
    170                     return  
     181                    return 
     182                tivo_cache[theurl] = {} 
    171183                tivo_cache[theurl]['thepage'] = handle.read() 
    172184                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) 
    222226        subcname = query['Container'][0] 
    223227        cname = subcname.split('/')[0] 
     
    229233            t.subfolder = True 
    230234        t.status = status 
     235        print handler.tivos 
     236        t.tivos = handler.tivos 
     237        t.tivoIP = tivoIP 
    231238        t.container = cname 
    232239        t.data = data 
    233240        t.unquote = unquote 
     241        t.len = len 
    234242        handler.wfile.write(t) 
    235243 
     
    294302            parse_url = urlparse(str(query['Url'][0])) 
    295303            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] 
    299306            name = unquote(parse_url[2])[10:300].split('.') 
    300307            name.insert(-1," - " + unquote(parse_url[4]).split("id=")[1] + ".") 
     
    310317            t.container = cname 
    311318            t.time = '3' 
    312             t.url = '/TiVoConnect?Command=NPL&Container=' + cname 
     319            t.url = '/TiVoConnect?Command=NPL&Container=' + cname + '&TiVo=' + query['TiVo'][0] 
    313320            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.' 
    315322            handler.wfile.write(t) 
    316323        else: 
     
    320327            t.container = cname 
    321328            t.time = '10' 
    322             t.url = '/TiVoConnect?Command=NPL&Container=' + cname 
     329            t.url = '/TiVoConnect?Command=NPL&Container=' + cname + '&TiVo=' + query['TiVo'][0] 
    323330            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.' 
    325332            handler.wfile.write(t) 
    326333 
     
    338345        t.container = cname 
    339346        t.time = '3' 
    340         t.url = '/TiVoConnect?Command=NPL&Container=' + cname 
     347        t.url = '/TiVoConnect?Command=NPL&Container=' + cname + '&TiVo=' + query['TiVo'][0] 
    341348        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  
    1212    <tr> 
    1313      <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 
    1721      </select> 
    18           &nbsp;<input value="View Now Playing List" name="NPL" type="button"> &nbsp;</td> 
     22          &nbsp;<input value="View Now Playing List" type="submit"> 
     23          </form> 
     24          </td> 
    1925    </tr> 
    2026    <tr> 
     
    2329      <table> 
    2430      #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> 
    2632      #end if 
    2733      #set $i = 0 
    28       #for $row in $data 
     34         #for $row in $data 
    2935                  #set $i += 1 
    3036                  #if $i%2 
    31                       <tr style="background-color: rgb(250, 250, 250);"> 
     37                      <tr style="background-color: rgb(250, 250, 250);"> 
    3238                  #else 
    33                       <tr> 
     39                      <tr> 
    3440                  #end if 
    3541                  #if $row['ContentType'] == 'x-tivo-container/folder' 
    3642                        <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> 
    3844                        <td NOWRAP align="center">$(row["TotalItems"]) Items</td> 
    3945                        <td NOWRAP align="center">$row["LastChangeDate"]</td> 
     
    6874                                        #if $this_status['running'] and $this_status['rate'] != "" 
    6975                                                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> 
    7177                                        #elif $this_status['running'] and $this_status['rate'] == "" 
    7278                                                Initiating Transfer.<br> 
     
    7480                                        #elif $this_status['error'] 
    7581                                                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> 
    7783                                        #elif $this_status['finished'] 
    7884                                                Transfer Complete! 
    7985                                        #else 
    8086                                                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> 
    8288                                        #endif 
    8389                                #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> 
    8591                                #end if 
    8692                                </td>