From 524b1345511bdcb8e88de58ea8555a9d833b70a3 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 16 Jan 2011 18:58:57 +0530 Subject: [PATCH] use imdb/icon/expose timeline --- pandora/item/models.py | 88 +++++++++++++++++++++----------------- pandora/item/tasks.py | 4 +- pandora/item/urls.py | 1 + pandora/item/utils.py | 2 +- pandora/item/views.py | 6 +++ pandora/itemlist/models.py | 3 +- pandora/settings.py | 2 + 7 files changed, 63 insertions(+), 43 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 6863eed..b2415f3 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -33,46 +33,54 @@ def get_item(info): info dict with: imdbId, title, director, episode_title, season, series ''' - if 'imdbId' in info and info['imdbId']: - try: - item = Item.objects.get(itemId=info['imdbId']) - except Item.DoesNotExist: - item = Item(itemId=info['imdbId']) - if 'title' in info and 'director' in info: - item.external_data = { - 'title': info['title'], - 'director': info['director'], - 'year': info.get('year', '') - } - #FIXME: this should be done async - item.save() - tasks.update_imdb.delay(item.itemId) - #item.update_imdb() - else: - q = Item.objects.filter(find__key='title', find__value=info['title']) - if q.count() > 1: - print "FIXME: check more than title here!!?" - item = q[0] - else: + if settings.USE_IMDB: + if 'imdbId' in info and info['imdbId']: try: - item = Item.objects.get(itemId=info['oxdbId']) + item = Item.objects.get(itemId=info['imdbId']) except Item.DoesNotExist: - item = Item() - item.data = { - 'title': info['title'], - 'director': info['director'], - 'year': info.get('year', '') - } - item.itemId = info['oxdbId'] - - for key in ('episode_title', 'series_title', 'season', 'episode'): - if key in info and info[key]: - item.data[key] = info[key] + item = Item(itemId=info['imdbId']) + if 'title' in info and 'director' in info: + item.external_data = { + 'title': info['title'], + 'director': info['director'], + 'year': info.get('year', '') + } + #FIXME: this should be done async + item.save() + tasks.update_external.delay(item.itemId) + #item.update_external() + else: + q = Item.objects.filter(find__key='title', find__value=info['title']) + if q.count() > 1: + print "FIXME: check more than title here!!?" + item = q[0] + else: try: - existing_item = Item.objects.get(oxdbId=item.oxdb_id()) - item = existing_item + item = Item.objects.get(itemId=info['oxdbId']) except Item.DoesNotExist: - item.save() + item = Item() + item.data = { + 'title': info['title'], + 'director': info['director'], + 'year': info.get('year', '') + } + item.itemId = info['oxdbId'] + + for key in ('episode_title', 'series_title', 'season', 'episode'): + if key in info and info[key]: + item.data[key] = info[key] + try: + existing_item = Item.objects.get(oxdbId=item.oxdb_id()) + item = existing_item + except Item.DoesNotExist: + item.save() + else: + try: + item = Item.objects.get(itemId=info['itemId']) + except Item.DoesNotExist: + item = Item(itemId=info['itemId']) + item.save() + return item @@ -130,7 +138,7 @@ class Item(models.Model): _reviews[settings.REVIEW_WHITELIST[url]] = r[0] return _reviews - def update_imdb(self): + def update_external(self): if len(self.itemId) == 7: data = ox.web.imdb.Imdb(self.itemId) #FIXME: all this should be in ox.web.imdb.Imdb @@ -343,7 +351,9 @@ class Item(models.Model): def save(key, value): f, created = ItemFind.objects.get_or_create(item=self, key=key) if value not in ('', '||'): - f.value = value.strip() + if isinstance(value, basestring): + value = value.strip() + f.value = value f.save() else: f.delete() @@ -730,7 +740,7 @@ class Item(models.Model): '-l', timeline, '-p', poster ] - if len(self.itemId) == 7: + if settings.USE_IMDB and len(self.itemId) == 7: cmd += ['-i', self.itemId] cmd += ['-o', self.oxdbId] p = subprocess.Popen(cmd) diff --git a/pandora/item/tasks.py b/pandora/item/tasks.py index f1d1209..e94254a 100644 --- a/pandora/item/tasks.py +++ b/pandora/item/tasks.py @@ -19,9 +19,9 @@ def update_poster(itemId): @task(ignore_resulsts=True, queue='default') -def update_imdb(itemId): +def update_external(itemId): item = models.Item.objects.get(itemId=itemId) - item.update_imdb() + item.update_external() @task(queue="encoding") diff --git a/pandora/item/urls.py b/pandora/item/urls.py index bd82768..583011d 100644 --- a/pandora/item/urls.py +++ b/pandora/item/urls.py @@ -14,4 +14,5 @@ urlpatterns = patterns("item.views", (r'^(?P[A-Z0-9].*)/icon\.(?P\d+)\.jpg$', 'icon'), (r'^(?P[A-Z0-9].*)/icon\.jpg$', 'icon'), (r'^(?P[A-Z0-9].*)/timelines/(?P.+)\.(?P\d+)\.(?P\d+)\.png$', 'timeline'), + (r'^(?P[A-Z0-9].*)/timeline\.(?P\d+)\.png$', 'timeline_overview'), ) diff --git a/pandora/item/utils.py b/pandora/item/utils.py index 90ffda7..c6cf902 100644 --- a/pandora/item/utils.py +++ b/pandora/item/utils.py @@ -184,7 +184,7 @@ def parse_path(path): r['oxdbId'] = oxdb_id(r['title'], r['directors'], r.get('year', ''), r.get('season', ''), r.get('episode', ''), episode_title=r['episode_title'], - episode_directors=[], + episode_director=[], episode_year='') return r diff --git a/pandora/item/views.py b/pandora/item/views.py index ed1728f..710a25e 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -491,6 +491,12 @@ def timeline(request, id, timeline, size, position): return HttpFileResponse(timeline, content_type='image/png') +def timeline_overview(request, id, size): + item = get_object_or_404(models.Item, itemId=id) + timeline = '%s.%s.png' %(item.timeline_prefix, size) + return HttpFileResponse(timeline, content_type='image/png') + + def video(request, id, profile): item = get_object_or_404(models.Item, itemId=id) stream = get_object_or_404(item.streams, profile=profile) diff --git a/pandora/itemlist/models.py b/pandora/itemlist/models.py index d51a8d8..885d3b5 100644 --- a/pandora/itemlist/models.py +++ b/pandora/itemlist/models.py @@ -24,7 +24,8 @@ class List(models.Model): _status = ['private', 'public', 'featured'] query = DictField(default={"static": True}) type= models.CharField(max_length=255, default='static') - + description = models.TextField(default='') + icon = models.ImageField(default=None, blank=True, upload_to=lambda i, x: i.path("icon.jpg")) #is through table still required? diff --git a/pandora/settings.py b/pandora/settings.py index 0a67a71..bbe4d73 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -190,6 +190,8 @@ DEFAULT_LISTS = [ } ] #0xdb.org +USE_IMDB = True + #POSTER_SERVICES=['http://data.0xdb.org/poster/'] #copy scripts and adjust to customize