Changeset 33aa5370e3dac26c1c656f7cff1ed3e589e34f2d

Show
Ignore:
Timestamp:
03/06/08 01:54:28 (9 months ago)
Author:
KRKeegan <-NOSPAM-kevin@krkeegan.com>
git-committer:
KRKeegan <-NOSPAM-kevin@krkeegan.com> 1204790068 -0800
git-parent:

[ae4dbbea29a9d3ceb84ace30d35d0d18f829df32]

git-author:
KRKeegan <-NOSPAM-kevin@krkeegan.com> 1204790068 -0800
Message:

Initial design TiVo ToGo? functionality

Files:

Legend:

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

    rfeebef9 r33aa537  
    1 import os, socket, re, sys, ConfigParser, config 
     1import os, socket, re, sys, ConfigParser, config, time 
     2import urllib2 
     3from xml.dom import minidom 
    24from ConfigParser import NoOptionError 
    35from Cheetah.Template import Template 
     
    122124        t.text = '<h3>Your Settings have been saved.</h3>  <br>You settings have been saved to the pyTivo.conf file.  However you will need to do a <b>Soft Reset</b> before these changes will take effect.' 
    123125        handler.wfile.write(t) 
     126         
     127    def NPL(self, handler, query): 
     128        folder = '/NowPlaying' 
     129        if 'Folder' in query: 
     130            folder += '/' + str(query['Folder'][0]) 
     131        theurl = 'https://192.168.1.150/TiVoConnect?Command=QueryContainer&Container=' + folder 
    124132 
     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) 
    125186