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]
|
||||||
|
|
||||||
|
try:
|
||||||
req = urllib2.Request(imdb_url, None, utils.DEFAULT_HEADERS)
|
req = urllib2.Request(imdb_url, None, utils.DEFAULT_HEADERS)
|
||||||
u = urllib2.urlopen(req)
|
u = urllib2.urlopen(req)
|
||||||
data = u.read()
|
data = u.read()
|
||||||
return_url = u.url
|
return_url = u.url
|
||||||
u.close()
|
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