From 727ea66f350775bc33d4059d4360c12396d47f19 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 18 Oct 2011 16:02:14 +0200 Subject: [PATCH] fix --- oxdata/lookup/models.py | 49 ++++++++++++++++++----------------------- oxdata/movie/models.py | 21 ++++++------------ oxdata/settings.py | 7 +++--- 3 files changed, 33 insertions(+), 44 deletions(-) diff --git a/oxdata/lookup/models.py b/oxdata/lookup/models.py index 1553b05..0c4ab21 100644 --- a/oxdata/lookup/models.py +++ b/oxdata/lookup/models.py @@ -20,18 +20,10 @@ def getMovieIdByImdbId(imdb_id): '0377059': '0343663', '0426560': '0088000', }.get(imdb_id, imdb_id) - try: - 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() - else: - print imdb_id, "is not a valid id, failed loading movie" - return None + m, created = MovieId.objects.get_or_create(imdb_id=imdb_id) + if created: + m = MovieId.objects.get(imdb_id=imdb_id) + m.updateFromImdb() return m class MovieId(models.Model): @@ -79,11 +71,14 @@ class MovieId(models.Model): def updateFromImdb(self): if 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]: - 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) if not self.wikipedia_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 elif MovieId.objects.filter(wikipedia_id=self.wikipedia_id).count() >= 1: self.wikipedia_id=None - if not self.oxdb_id: - self.gen_oxdb_id() - self.save() + #if not self.oxdb_id: + # self.gen_oxdb_id() + self.save() def gen_oxdb_id(self): - oxid_value = u"\n".join([self.title, self.director, str(self.year)]) - oxid = hashlib.sha1(oxid_value.encode('utf-8')).hexdigest() - if self.episode > -1: - oxid_value = u"\n".join([self.series_title, "%02d" % self.season]) - oxid = hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20] - oxid_value = u"\n".join(["%02d" % self.episode, self.episode_title, self.director, str(self.year)]) - oxid += hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20] - self.oxdb_id = u"0x" + oxid - self.save() + self.oxdb_id = ox.get_oxid( + self.title, + self.director, + self.year or '', + self.season or '', + self.episode or '', + self.episode_title or '', + self.episode_director or [], + self.episode_yeaer or '') def suggested_name(self): return normalizePath(self.title) diff --git a/oxdata/movie/models.py b/oxdata/movie/models.py index 6f848d3..31c2e03 100644 --- a/oxdata/movie/models.py +++ b/oxdata/movie/models.py @@ -58,20 +58,13 @@ class Imdb(models.Model): info = ox.web.imdb.ImdbCombined(self.imdb) if info: for key in self.keys: - ikey = { - 'director': 'directors', - 'episodeTitle': 'episode_title', - 'episodeYear': 'episode_year', - '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): - value = '\n'.join(value) + '\n' - setattr(self, key, value) + if key in info: + value = info[key] + if key == 'title' and 'seriesTitle' in info: + value = info['seriesTitle'] + if isinstance(value, list): + value = '\n'.join(value) + '\n' + setattr(self, key, value) if self.season < 0: self.season = None if self.episode < 0: diff --git a/oxdata/settings.py b/oxdata/settings.py index e394824..3379fe4 100644 --- a/oxdata/settings.py +++ b/oxdata/settings.py @@ -72,11 +72,12 @@ ADMIN_MEDIA_PREFIX = '/admin/media/' # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.load_template_source', - 'django.template.loaders.app_directories.load_template_source', - 'django.template.loaders.eggs.load_template_source', + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + 'django.template.loaders.eggs.Loader', ) + MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',