better zipfiles, do not fail if imdb does not return
This commit is contained in:
parent
50157e16b6
commit
19c52e22a4
2 changed files with 14 additions and 9 deletions
|
@ -390,12 +390,14 @@ def guess(title, director=''):
|
||||||
if url.startswith('http://www.imdb.com/title/tt'):
|
if url.startswith('http://www.imdb.com/title/tt'):
|
||||||
return url[28:35]
|
return url[28:35]
|
||||||
|
|
||||||
req = urllib2.Request(imdb_url, None, utils.DEFAULT_HEADERS)
|
try:
|
||||||
u = urllib2.urlopen(req)
|
req = urllib2.Request(imdb_url, None, utils.DEFAULT_HEADERS)
|
||||||
data = u.read()
|
u = urllib2.urlopen(req)
|
||||||
return_url = u.url
|
data = u.read()
|
||||||
u.close()
|
return_url = u.url
|
||||||
|
u.close()
|
||||||
|
except:
|
||||||
|
return None
|
||||||
if return_url.startswith('http://www.imdb.com/title/tt'):
|
if return_url.startswith('http://www.imdb.com/title/tt'):
|
||||||
return return_url[28:35]
|
return return_url[28:35]
|
||||||
if data:
|
if data:
|
||||||
|
|
|
@ -24,10 +24,13 @@ def getZipFileLink(opensubtitle_id):
|
||||||
return "http://www.opensubtitles.org/en/download/sub/%s" % opensubtitle_id
|
return "http://www.opensubtitles.org/en/download/sub/%s" % opensubtitle_id
|
||||||
|
|
||||||
def downloadSubtitle(zip_link):
|
def downloadSubtitle(zip_link):
|
||||||
|
return extractSubtitles(read_url(zip_link))
|
||||||
|
|
||||||
|
def extractSubtitles(zip_data):
|
||||||
srts ={}
|
srts ={}
|
||||||
zip = StringIO.StringIO()
|
z = StringIO.StringIO()
|
||||||
zip.write(read_url(zip_link))
|
z.write(zip_data)
|
||||||
zfile = zipfile.ZipFile(zip)
|
zfile = zipfile.ZipFile(z)
|
||||||
files = zfile.namelist()
|
files = zfile.namelist()
|
||||||
def is_not_nfo(file): return not file.endswith('nfo')
|
def is_not_nfo(file): return not file.endswith('nfo')
|
||||||
files = filter(is_not_nfo, files)
|
files = filter(is_not_nfo, files)
|
||||||
|
|
Loading…
Reference in a new issue