diff --git a/lookup/cache.py b/lookup/cache.py index dd809ea..2fbdfa3 100644 --- a/lookup/cache.py +++ b/lookup/cache.py @@ -22,6 +22,7 @@ def addPoster(m, url, site, site_id): def getIds(): for id in oxweb.impawards.getIds(): if models.MovieId.objects.all().filter(impawards_id=id).count() == 0: + print 'impawards', id data = oxweb.impawards.getData(id) if data: m = models.getMovieIdByImdbId(data['imdbId']) @@ -33,6 +34,7 @@ def getIds(): for criterionId in oxweb.criterion.getIds(): if models.MovieId.objects.all().filter(criterion_id=id).count() == 0: + print 'criterion', id data = oxweb.criterion.getData(criterionId) if data: m = models.getMovieIdByImdbId(data['imdbId']) @@ -45,6 +47,7 @@ def getIds(): lastId = models.Karagarga.maxId() for karagargaId in oxweb.karagarga.getIds(lastId): if models.Karagarga.objects.filter(karagarga_id=karagargaId).count() == 0: + print 'kg', id data = oxweb.karagarga.getData(karagargaId) if data: if 'imdbId' in data: diff --git a/poster/models.py b/poster/models.py index 71bdb46..42ea29b 100644 --- a/poster/models.py +++ b/poster/models.py @@ -33,8 +33,8 @@ def getPosters(movie_id): del posters[p] return posters -def poster_path(instance, filename): - url_hash = hashlib.sha1(instance.url).hexdigest() +def poster_path(url, filename): + url_hash = hashlib.sha1(url).hexdigest() ext = 'jpg' if filename.endswith('.png'): ext = 'png' @@ -49,7 +49,7 @@ class PosterCache(models.Model): url = models.CharField(max_length=1024) site = models.CharField(max_length=255) site_id = models.CharField(max_length=42) - image = models.ImageField(max_length=255, upload_to=poster_path) + image = models.ImageField(max_length=255, upload_to=lambda i, f: poster_path(i.url, f)) failed = models.BooleanField(default=False) def get(self): @@ -64,13 +64,6 @@ class PosterCache(models.Model): self.save() return self.image -def manual_poster_path(instance, filename): - url_hash = hashlib.sha1('%s' % instance.id).hexdigest() - ext = 'jpg' - if filename.endswith('.png'): - ext = 'png' - name = "%s.%s" % (url_hash, ext) - return os.path.join('posters', url_hash[:2], url_hash[2:4], url_hash[4:6], name) class Poster(models.Model): created = models.DateTimeField(auto_now_add=True) @@ -78,8 +71,9 @@ class Poster(models.Model): movie_id = models.ForeignKey(MovieId, related_name='poster') poster = models.ForeignKey(PosterCache, default=None, blank=True) - image = models.ImageField(max_length=255, upload_to=manual_poster_path) - + upload = models.ImageField(max_length=255, upload_to=lambda i, f: poster_path('upload/%s' % i.id, f)) + oxdb = models.ImageField(max_length=255, upload_to=lambda i, f: poster_path('oxdb/%s' % i.id, f)) + def get(self): if self.image: return self.image @@ -98,6 +92,9 @@ def getPosterUrls(m): if poster: if PosterCache.objects.all().filter(url=poster).count() == 0: addPoster(poster, 'imdb.com', m.imdb_id) + for poster in oxweb.movieposterdb.getData(m.imdb_id)['posters']: + if PosterCache.objects.all().filter(url=poster).count() == 0: + addPoster(poster, 'movieposterdb.com', m.imdb_id) if m.criterion_id: for poster in oxweb.criterion.getData(m.criterion_id)['posters']: if PosterCache.objects.all().filter(url=poster).count() == 0: diff --git a/templates/poster.html b/templates/poster.html index a4cf5d0..279be87 100644 --- a/templates/poster.html +++ b/templates/poster.html @@ -14,13 +14,13 @@ $(function(){ $.each(posters, function(key, urls) { var id = 'row' + key.replace('.', '_'); var row = '