fix imdb serach and mapping

This commit is contained in:
j 2009-07-10 10:47:01 +02:00
parent bb8db87d02
commit 03af5a3de0
2 changed files with 27 additions and 16 deletions

View file

@ -185,6 +185,21 @@ def getMovieInfo(imdbId):
return info return info
def getMovieRuntimeSeconds(imdbId):
info = getMovieInfo(imdbId)
value = info['runtime'][0]
parsed_value = findRe(value, '(.*?) min')
parsed_value = findRe(parsed_value, '([0-9]+)')
if not parsed_value:
parsed_value = findRe(value, '(.*?) sec')
parsed_value = findRe(parsed_value, '([0-9]+)')
if not parsed_value:
parsed_value = 0
else:
parsed_value = int(parsed_value)
else:
parsed_value = int(parsed_value) * 60
return parsed_value
def getMoviePoster(imdbId): def getMoviePoster(imdbId):
info = getMovieInfo(imdbId) info = getMovieInfo(imdbId)
@ -505,17 +520,7 @@ class IMDb:
if key in ('runtime', 'language', 'genre', 'country', 'tagline', 'plot_outline'): if key in ('runtime', 'language', 'genre', 'country', 'tagline', 'plot_outline'):
value = stripTags(value).strip() value = stripTags(value).strip()
if key == 'runtime': if key == 'runtime':
parsed_value = findRe(value, '(.*?) min') parsed_value = getMovieRuntimeSeconds(self.imdb)
parsed_value = findRe(parsed_value, '([0-9]+)')
if not parsed_value:
parsed_value = findRe(value, '(.*?) sec')
parsed_value = findRe(parsed_value, '([0-9]+)')
if not parsed_value:
parsed_value = 0
else:
parsed_value = int(parsed_value)
else:
parsed_value = int(parsed_value) * 60
elif key in ('country', 'language'): elif key in ('country', 'language'):
parsed_value = value.split(' / ') parsed_value = value.split(' / ')
if len(parsed_value) == 1: if len(parsed_value) == 1:

View file

@ -15,7 +15,7 @@ def getMovieId(title, director='', year=''):
return '' return ''
def getUrlByImdbId(imdbId): def getUrlByImdbId(imdbId):
query = '"imdb_id = %s"'% imdbId query = '"%s"'% imdbId
result = find(query) result = find(query)
if result: if result:
url = result[0][1] url = result[0][1]
@ -45,16 +45,22 @@ def getWikiData(wikipediaUrl):
def getMovieData(wikipediaUrl): def getMovieData(wikipediaUrl):
data = getWikiData(wikipediaUrl) data = getWikiData(wikipediaUrl)
filmbox_data = findRe(data, '''\{\{Infobox.Film(.*?)\}\}''') filmbox_data = findRe(data, '''\{\{Infobox.Film(.*?)\n\}\}''')
filmbox = {} filmbox = {}
for row in filmbox_data.strip().split('|'): for row in filmbox_data.strip().split('\n|'):
d = row.split('=') d = row.split('=')
if len(d) == 2: if len(d) == 2:
key = d[0].strip() key = d[0].strip()
if key[0] == '|':
key = key[1:]
value = d[1].strip() value = d[1].strip()
filmbox[key] = value filmbox[key] = value
if 'amg_id' in filmbox: if 'imdb title' in data:
filmbox['amg_id'] = filmbox['amg_id'].split('1:')[-1] filmbox['imdb_id'] = findRe(data, 'imdb title\|(\d*?)\|')
if 'Amg movie' in data:
filmbox['amg_id'] = findRe(data, 'Amg movie\|(\d*?)\|')
if 'rotten-tomatoes' in data:
filmbox['rottentomatoes_id'] = findRe(data, 'rotten-tomatoes\|id\=(.*?)\|')
return filmbox return filmbox
def getImageUrl(name): def getImageUrl(name):