add movieposterdb

This commit is contained in:
j 2009-07-15 20:19:56 +02:00
parent 0243766f8f
commit c267b258be
3 changed files with 17 additions and 17 deletions

View file

@ -22,6 +22,7 @@ def addPoster(m, url, site, site_id):
def getIds(): def getIds():
for id in oxweb.impawards.getIds(): for id in oxweb.impawards.getIds():
if models.MovieId.objects.all().filter(impawards_id=id).count() == 0: if models.MovieId.objects.all().filter(impawards_id=id).count() == 0:
print 'impawards', id
data = oxweb.impawards.getData(id) data = oxweb.impawards.getData(id)
if data: if data:
m = models.getMovieIdByImdbId(data['imdbId']) m = models.getMovieIdByImdbId(data['imdbId'])
@ -33,6 +34,7 @@ def getIds():
for criterionId in oxweb.criterion.getIds(): for criterionId in oxweb.criterion.getIds():
if models.MovieId.objects.all().filter(criterion_id=id).count() == 0: if models.MovieId.objects.all().filter(criterion_id=id).count() == 0:
print 'criterion', id
data = oxweb.criterion.getData(criterionId) data = oxweb.criterion.getData(criterionId)
if data: if data:
m = models.getMovieIdByImdbId(data['imdbId']) m = models.getMovieIdByImdbId(data['imdbId'])
@ -45,6 +47,7 @@ def getIds():
lastId = models.Karagarga.maxId() lastId = models.Karagarga.maxId()
for karagargaId in oxweb.karagarga.getIds(lastId): for karagargaId in oxweb.karagarga.getIds(lastId):
if models.Karagarga.objects.filter(karagarga_id=karagargaId).count() == 0: if models.Karagarga.objects.filter(karagarga_id=karagargaId).count() == 0:
print 'kg', id
data = oxweb.karagarga.getData(karagargaId) data = oxweb.karagarga.getData(karagargaId)
if data: if data:
if 'imdbId' in data: if 'imdbId' in data:

View file

@ -33,8 +33,8 @@ def getPosters(movie_id):
del posters[p] del posters[p]
return posters return posters
def poster_path(instance, filename): def poster_path(url, filename):
url_hash = hashlib.sha1(instance.url).hexdigest() url_hash = hashlib.sha1(url).hexdigest()
ext = 'jpg' ext = 'jpg'
if filename.endswith('.png'): if filename.endswith('.png'):
ext = 'png' ext = 'png'
@ -49,7 +49,7 @@ class PosterCache(models.Model):
url = models.CharField(max_length=1024) url = models.CharField(max_length=1024)
site = models.CharField(max_length=255) site = models.CharField(max_length=255)
site_id = models.CharField(max_length=42) 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) failed = models.BooleanField(default=False)
def get(self): def get(self):
@ -64,13 +64,6 @@ class PosterCache(models.Model):
self.save() self.save()
return self.image 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): class Poster(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
@ -78,8 +71,9 @@ class Poster(models.Model):
movie_id = models.ForeignKey(MovieId, related_name='poster') movie_id = models.ForeignKey(MovieId, related_name='poster')
poster = models.ForeignKey(PosterCache, default=None, blank=True) 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): def get(self):
if self.image: if self.image:
return self.image return self.image
@ -98,6 +92,9 @@ def getPosterUrls(m):
if poster: if poster:
if PosterCache.objects.all().filter(url=poster).count() == 0: if PosterCache.objects.all().filter(url=poster).count() == 0:
addPoster(poster, 'imdb.com', m.imdb_id) 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: if m.criterion_id:
for poster in oxweb.criterion.getData(m.criterion_id)['posters']: for poster in oxweb.criterion.getData(m.criterion_id)['posters']:
if PosterCache.objects.all().filter(url=poster).count() == 0: if PosterCache.objects.all().filter(url=poster).count() == 0:

View file

@ -14,13 +14,13 @@ $(function(){
$.each(posters, function(key, urls) { $.each(posters, function(key, urls) {
var id = 'row' + key.replace('.', '_'); var id = 'row' + key.replace('.', '_');
var row = '<tr id="'+id+'">'; var row = '<tr id="'+id+'">';
row += '<td id="'+id+'_title">' + key + '</td>'; row += '<td id="'+id+'_title" valign="top">' + key + '</td>';
$.each(urls, function(i, poster) {
row += '<td>'; row += '<td>';
row += '<img src="'+poster.url+'" height="256">'; $.each(urls, function(i, poster) {
row += '<div>' + poster.width + 'x'+ poster.height + '</div>'; row += '<div style="float: left; height: 280px;padding-right: 4px;"><img src="'+poster.url+'" height="256">';
row += '</td>'; row += '<div>' + poster.width + 'x'+ poster.height + '</div></div>';
}); });
row += '</td>';
row += '</tr>'; row += '</tr>';
$("#posters").append(row); $("#posters").append(row);
$('#'+id+'_title').click(function() { $('#'+id+'_title').click(function() {