Changeset 6e208fcad11df64fb8cc031e4c2ba5ed6fe84f84

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

[9d2b62c372c3bb7efda006cd3e2564910e56d4c5]

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

Cache TiVo NPL for 60 seconds, Fix redirect page

Files:

Legend:

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

    r9d2b62c r6e208fc  
    2121config_file_path = os.path.join(p, 'pyTivo.conf') 
    2222 
    23 status = {} 
     23status = {} #Global variable to control download threads 
     24tivo_cache = {} #Cache of TiVo NPL 
    2425 
    2526class Admin(Plugin): 
     
    3637        t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl')) 
    3738        t.container = cname 
    38         t.text = '<h3>The pyTivo Server has been soft reset.</h3>  <br>pyTivo has reloaded the pyTivo.conf file and all changed should now be in effect.' 
     39        t.time = '3' 
     40        t.url = '/TiVoConnect?Command=Admin&Container=' + cname 
     41        t.text = '<h3>The pyTivo Server has been soft reset.</h3>  <br>pyTivo has reloaded the pyTivo.conf'+\ 
     42                 'file and all changed should now be in effect. <br> The'+ \ 
     43                 '<a href="/TiVoConnect?Command=Admin&Container='+ cname +'"> Admin</a> page will reload in 3 seconds.' 
    3944        handler.wfile.write(t) 
    4045     
     
    125130        t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl')) 
    126131        t.container = cname 
    127         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.' 
     132        t.time = '10' 
     133        t.url = '/TiVoConnect?Command=Admin&Container=' + cname 
     134        t.text = '<h3>Your Settings have been saved.</h3>  <br>You settings have been saved to the pyTivo.conf file.'+\ 
     135                 'However you will need to do a <b>Soft Reset</b> before these changes will take effect.'+\ 
     136                 '<br> The <a href="/TiVoConnect?Command=Admin&Container='+ cname +'"> Admin</a> page will reload in 10 seconds.' 
    128137        handler.wfile.write(t) 
    129138         
     
    151160        urllib2.install_opener(opener) 
    152161 
    153         try: 
    154             handle = urllib2.urlopen(r) 
    155         except IOError, e: 
    156             print "Possibly wrong Media Access Key, or IP address for your TiVo." 
    157             handler.send_response(404) 
    158             handler.end_headers() 
    159             return  
    160         thepage = handle.read() 
    161  
    162         xmldoc = minidom.parseString(thepage) 
     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 
     164                try: 
     165                    handle = urllib2.urlopen(r) 
     166                except IOError, e: 
     167                    print "Possibly wrong Media Access Key, or IP address for your TiVo." 
     168                    handler.send_response(404) 
     169                    handler.end_headers() 
     170                    return  
     171                tivo_cache[theurl]['thepage'] = handle.read() 
     172                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']) 
    163186        items = xmldoc.getElementsByTagName('Item') 
    164187 
     
    286309            t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl')) 
    287310            t.container = cname 
    288             t.text = '<h3>Transfer Initiated.</h3>  <br>You selected transfer has been initiated.' 
     311            t.time = '3' 
     312            t.url = '/TiVoConnect?Command=NPL&Container=' + cname 
     313            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.' 
    289315            handler.wfile.write(t) 
    290316        else: 
     
    293319            t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl')) 
    294320            t.container = cname 
    295             t.text = '<h3>Missing Data.</h3>  <br>You must set both "tivo_mak" and "togo_path" before using this function.' 
     321            t.time = '10' 
     322            t.url = '/TiVoConnect?Command=NPL&Container=' + cname 
     323            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.' 
    296325            handler.wfile.write(t) 
    297326 
     
    308337        t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl')) 
    309338        t.container = cname 
    310         t.text = '<h3>Transfer Stopped.</h3>  <br>Your transfer has been stopped.' 
    311         handler.wfile.write(t) 
     339        t.time = '3' 
     340        t.url = '/TiVoConnect?Command=NPL&Container=' + cname 
     341        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) 
  • plugins/admin/templates/redirect.tmpl

    rf86a04e r6e208fc  
    11<html> 
    22<head> 
    3 <meta http-equiv="Refresh" content="10; url=/TiVoConnect?Command=Admin&Container=$container"> 
     3<meta http-equiv="Refresh" content="$time; url=$url"> 
    44</head> 
    55<body bgcolor="#FFFFFF"> 
    66$text 
    7 <br> 
    8 The <a href="/TiVoConnect?Command=Admin&Container=$container"> Admin</a> page will reload in 10 seconds. 
    97</body> 
    108</html>