Changeset 6e208fcad11df64fb8cc031e4c2ba5ed6fe84f84
- 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
| r9d2b62c |
r6e208fc |
|
| 21 | 21 | config_file_path = os.path.join(p, 'pyTivo.conf') |
|---|
| 22 | 22 | |
|---|
| 23 | | status = {} |
|---|
| | 23 | status = {} #Global variable to control download threads |
|---|
| | 24 | tivo_cache = {} #Cache of TiVo NPL |
|---|
| 24 | 25 | |
|---|
| 25 | 26 | class Admin(Plugin): |
|---|
| … | … | |
| 36 | 37 | t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl')) |
|---|
| 37 | 38 | 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.' |
|---|
| 39 | 44 | handler.wfile.write(t) |
|---|
| 40 | 45 | |
|---|
| … | … | |
| 125 | 130 | t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl')) |
|---|
| 126 | 131 | 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.' |
|---|
| 128 | 137 | handler.wfile.write(t) |
|---|
| 129 | 138 | |
|---|
| … | … | |
| 151 | 160 | urllib2.install_opener(opener) |
|---|
| 152 | 161 | |
|---|
| 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']) |
|---|
| 163 | 186 | items = xmldoc.getElementsByTagName('Item') |
|---|
| 164 | 187 | |
|---|
| … | … | |
| 286 | 309 | t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl')) |
|---|
| 287 | 310 | 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.' |
|---|
| 289 | 315 | handler.wfile.write(t) |
|---|
| 290 | 316 | else: |
|---|
| … | … | |
| 293 | 319 | t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl')) |
|---|
| 294 | 320 | 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.' |
|---|
| 296 | 325 | handler.wfile.write(t) |
|---|
| 297 | 326 | |
|---|
| … | … | |
| 308 | 337 | t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl')) |
|---|
| 309 | 338 | 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) |
|---|
| rf86a04e |
r6e208fc |
|
| 1 | 1 | <html> |
|---|
| 2 | 2 | <head> |
|---|
| 3 | | <meta http-equiv="Refresh" content="10; url=/TiVoConnect?Command=Admin&Container=$container"> |
|---|
| | 3 | <meta http-equiv="Refresh" content="$time; url=$url"> |
|---|
| 4 | 4 | </head> |
|---|
| 5 | 5 | <body bgcolor="#FFFFFF"> |
|---|
| 6 | 6 | $text |
|---|
| 7 | | <br> |
|---|
| 8 | | The <a href="/TiVoConnect?Command=Admin&Container=$container"> Admin</a> page will reload in 10 seconds. |
|---|
| 9 | 7 | </body> |
|---|
| 10 | 8 | </html> |
|---|