Suggested patch:
Code:
diff -up ./cacheurl.py.orig ./cacheurl.py
--- ./cacheurl.py.orig 2010-12-30 17:28:54.955339079 +0100
+++ ./cacheurl.py 2010-12-30 17:34:13.015595168 +0100
@@ -86,6 +86,16 @@ def set_status_symbol( status_symbol ):
status_symbol_index = 0
return [ "-", "\\", "|", "/" ][ status_symbol_index ]
+# This class is only needed in order to make a HEAD request
+class HeadRequest(urllib2.Request):
+ def get_method(self):
+ return "HEAD"
+
+# And this is to prevent following redirects
+class HTTPRedirectPreventer(urllib2.HTTPRedirectHandler):
+ def redirect_request(self, req, fp, code, msg, hdrs, newurl):
+ return None
+
class HTTP:
def __init__( self, cache = ".cache", title = "", actual_filename = False, flat_cache = False, clear_cache_folder=False ):
# set the cache directory; default to a .cache directory in BASE_DATA_PATH
@@ -260,6 +270,30 @@ class HTTP:
filepath = None
return filepath
+ def urlcheck( self, url ):
+ # get the filename
+ filepath = self.make_cache_filename( url )
+
+ # if the file is already in the cache, we're done
+ if os.path.isfile( filepath ):
+ return True
+
+ try:
+ # special handler to do HEAD as we don't want to download
+ # the file
+ request = HeadRequest( url )
+ request.add_header( "User-Agent", __useragent__ )
+ # and a special opener to avoid following redirects
+ opener = urllib2.build_opener(HTTPRedirectPreventer)
+ response = opener.open( request )
+ except urllib2.HTTPError, e:
+ return False
+ except:
+ LOG( LOG_ERROR, self.__class__.__name__, "%s.%s [%s]", __module_name__, __module_version__, sys.exc_info()[ 1 ] )
+ return False
+
+ return True
+
def on_data( self, url, filepath, filesize, size_read_so_far ):
return True
diff -up ./gui.py.orig ./gui.py
--- ./gui.py.orig 2010-12-30 17:08:02.616221721 +0100
+++ ./gui.py 2010-12-31 00:22:18.998089032 +0100
@@ -509,9 +509,19 @@ class GUI( xbmcgui.WindowXML ):
#self.core = xbmc.PLAYER_CORE_DVDPLAYER
#else:
# self.core = xbmc.PLAYER_CORE_MPLAYER
+
+ # The URIs we find in the XML data don't seem
+ # to be properly distributed in the CDN so we
+ # need to change them to what you can find on
+ # the "normal" trailers page.
+ alt_url = url.replace("/405/us/media/trailers/", "/movies/")
+ tester = cacheurl.HTTP( clear_cache_folder=not self.flat_cache )
+ if ( tester.urlcheck( alt_url ) ):
+ url = alt_url
+
self.url = url
if ( self.settings[ "mode" ] == 0 ):
- filename = url + "?|User-Agent=%s" % ( urllib.quote_plus( cacheurl.__useragent__ ), )
+ filename = url + "|User-Agent=%s" % ( urllib.quote_plus( cacheurl.__useragent__ ), )
else:
if ( self.settings[ "mode" ] == 1 ):
if ( not self.check_cache( self.trailers.movies[ self.trailer ].title ) ):
The basic principle is testing the modified URI by doing a HEAD request first, and using the original one if that request fails. Should allow us to use this hack safely.
Old trailers still have problems, but they're probably just poorly cached in the CDN. I tried "A Scanner Darkly" and got 3 Mbps. That's more than the 1 Mbps I get with the unmodified URIs, but insufficient for smooth playback.