add movieposterdb
This commit is contained in:
parent
0243766f8f
commit
c267b258be
3 changed files with 17 additions and 17 deletions
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -14,13 +14,13 @@ $(function(){
|
|||
$.each(posters, function(key, urls) {
|
||||
var id = 'row' + key.replace('.', '_');
|
||||
var row = '<tr id="'+id+'">';
|
||||
row += '<td id="'+id+'_title">' + key + '</td>';
|
||||
$.each(urls, function(i, poster) {
|
||||
row += '<td id="'+id+'_title" valign="top">' + key + '</td>';
|
||||
row += '<td>';
|
||||
row += '<img src="'+poster.url+'" height="256">';
|
||||
row += '<div>' + poster.width + 'x'+ poster.height + '</div>';
|
||||
row += '</td>';
|
||||
$.each(urls, function(i, poster) {
|
||||
row += '<div style="float: left; height: 280px;padding-right: 4px;"><img src="'+poster.url+'" height="256">';
|
||||
row += '<div>' + poster.width + 'x'+ poster.height + '</div></div>';
|
||||
});
|
||||
row += '</td>';
|
||||
row += '</tr>';
|
||||
$("#posters").append(row);
|
||||
$('#'+id+'_title').click(function() {
|
||||
|
|
Loading…
Reference in a new issue