This commit is contained in:
j 2011-10-18 16:02:14 +02:00
parent 8812c99155
commit 727ea66f35
3 changed files with 33 additions and 44 deletions

View file

@ -20,18 +20,10 @@ def getMovieIdByImdbId(imdb_id):
'0377059': '0343663', '0377059': '0343663',
'0426560': '0088000', '0426560': '0088000',
}.get(imdb_id, imdb_id) }.get(imdb_id, imdb_id)
try: m, created = MovieId.objects.get_or_create(imdb_id=imdb_id)
if created:
m = MovieId.objects.get(imdb_id=imdb_id) m = MovieId.objects.get(imdb_id=imdb_id)
except MovieId.DoesNotExist:
#check if imdb_id actually exists on imdb
if ox.cache.exists('http://www.imdb.com/title/tt%s/combined'%imdb_id):
m = MovieId()
m.imdb_id = imdb_id
m.save()
m.updateFromImdb() m.updateFromImdb()
else:
print imdb_id, "is not a valid id, failed loading movie"
return None
return m return m
class MovieId(models.Model): class MovieId(models.Model):
@ -79,11 +71,14 @@ class MovieId(models.Model):
def updateFromImdb(self): def updateFromImdb(self):
if self.imdb_id: if self.imdb_id:
data = ox.web.imdb.ImdbCombined(self.imdb_id) data = ox.web.imdb.ImdbCombined(self.imdb_id)
for key in ('title', 'year', 'series_title', 'episode_title', 'season', 'episode'): for key in ('title', 'year', 'seriesTitle', 'episodeTitle', 'season', 'episode'):
if key in data and data[key]: if key in data and data[key]:
setattr(self, key, data.get(key, '')) setattr(self, {
'seriesTitle': 'series_title',
'episodeTitle': 'episode_title',
}.get(key, key), data.get(key, ''))
directors = data.get('directors', []) directors = data.get('director', [])
self.director = u', '.join(directors) self.director = u', '.join(directors)
if not self.wikipedia_id: if not self.wikipedia_id:
self.wikipedia_id = ox.web.wikipedia.getId(ox.web.wikipedia.getUrlByImdb(self.imdb_id)) self.wikipedia_id = ox.web.wikipedia.getId(ox.web.wikipedia.getUrlByImdb(self.imdb_id))
@ -93,20 +88,20 @@ class MovieId(models.Model):
#its most likely wrong for both in that case #its most likely wrong for both in that case
elif MovieId.objects.filter(wikipedia_id=self.wikipedia_id).count() >= 1: elif MovieId.objects.filter(wikipedia_id=self.wikipedia_id).count() >= 1:
self.wikipedia_id=None self.wikipedia_id=None
if not self.oxdb_id: #if not self.oxdb_id:
self.gen_oxdb_id() # self.gen_oxdb_id()
self.save() self.save()
def gen_oxdb_id(self): def gen_oxdb_id(self):
oxid_value = u"\n".join([self.title, self.director, str(self.year)]) self.oxdb_id = ox.get_oxid(
oxid = hashlib.sha1(oxid_value.encode('utf-8')).hexdigest() self.title,
if self.episode > -1: self.director,
oxid_value = u"\n".join([self.series_title, "%02d" % self.season]) self.year or '',
oxid = hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20] self.season or '',
oxid_value = u"\n".join(["%02d" % self.episode, self.episode_title, self.director, str(self.year)]) self.episode or '',
oxid += hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20] self.episode_title or '',
self.oxdb_id = u"0x" + oxid self.episode_director or [],
self.save() self.episode_yeaer or '')
def suggested_name(self): def suggested_name(self):
return normalizePath(self.title) return normalizePath(self.title)

View file

@ -58,17 +58,10 @@ class Imdb(models.Model):
info = ox.web.imdb.ImdbCombined(self.imdb) info = ox.web.imdb.ImdbCombined(self.imdb)
if info: if info:
for key in self.keys: for key in self.keys:
ikey = { if key in info:
'director': 'directors', value = info[key]
'episodeTitle': 'episode_title', if key == 'title' and 'seriesTitle' in info:
'episodeYear': 'episode_year', value = info['seriesTitle']
'episodeDirector': 'episode_directors',
}.get(key, key)
if ikey in info:
if ikey in info:
value = info[ikey]
if ikey == 'title' and 'series_title' in info:
value = info['series_title']
if isinstance(value, list): if isinstance(value, list):
value = '\n'.join(value) + '\n' value = '\n'.join(value) + '\n'
setattr(self, key, value) setattr(self, key, value)

View file

@ -72,11 +72,12 @@ ADMIN_MEDIA_PREFIX = '/admin/media/'
# List of callables that know how to import templates from various sources. # List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = ( TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.load_template_source', 'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.load_template_source', 'django.template.loaders.eggs.Loader',
) )
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',