better zipfiles, do not fail if imdb does not return

This commit is contained in:
j 2007-03-30 20:08:19 +00:00
parent 50157e16b6
commit 19c52e22a4
2 changed files with 14 additions and 9 deletions

View file

@ -390,12 +390,14 @@ def guess(title, director=''):
if url.startswith('http://www.imdb.com/title/tt'):
return url[28:35]
try:
req = urllib2.Request(imdb_url, None, utils.DEFAULT_HEADERS)
u = urllib2.urlopen(req)
data = u.read()
return_url = u.url
u.close()
except:
return None
if return_url.startswith('http://www.imdb.com/title/tt'):
return return_url[28:35]
if data:

View file

@ -24,10 +24,13 @@ def getZipFileLink(opensubtitle_id):
return "http://www.opensubtitles.org/en/download/sub/%s" % opensubtitle_id
def downloadSubtitle(zip_link):
return extractSubtitles(read_url(zip_link))
def extractSubtitles(zip_data):
srts ={}
zip = StringIO.StringIO()
zip.write(read_url(zip_link))
zfile = zipfile.ZipFile(zip)
z = StringIO.StringIO()
z.write(zip_data)
zfile = zipfile.ZipFile(z)
files = zfile.namelist()
def is_not_nfo(file): return not file.endswith('nfo')
files = filter(is_not_nfo, files)