poster cleanup
This commit is contained in:
parent
03b484c261
commit
38fe412cb5
6 changed files with 75 additions and 29 deletions
|
@ -15,6 +15,11 @@ def ids(request):
|
|||
if 'imdb' in request.GET:
|
||||
imdb_id = request.GET['imdb']
|
||||
movie = models.getMovieIdByImdbId(imdb_id)
|
||||
elif 'oxdb' in request.GET:
|
||||
try:
|
||||
movie = models.MovieId.objects.get(oxdb_id=request.GET['oxdb'])
|
||||
except models.MovieId.DoesNotExist:
|
||||
pass
|
||||
if 'criterion' in request.GET:
|
||||
criterion_id = request.GET['criterion']
|
||||
movie = models.MovieId.objects.get(criterion_id=criterion_id)
|
||||
|
|
|
@ -18,7 +18,7 @@ from oxdata.lookup.models import MovieId
|
|||
def getPosters(movie_id):
|
||||
getPosterUrls(movie_id)
|
||||
posters = {}
|
||||
for p in PosterCache.objects.all().filter(movie_id=movie_id).order_by('id'):
|
||||
for p in PosterCache.objects.all().filter(movie_id=movie_id, failed=False).order_by('id'):
|
||||
if p.site not in posters:
|
||||
posters[p.site] = []
|
||||
poster = p.get()
|
||||
|
@ -32,8 +32,30 @@ def getPosters(movie_id):
|
|||
for p in posters.keys():
|
||||
if not posters[p]:
|
||||
del posters[p]
|
||||
poster = Poster.objects.filter(movie_id=movie_id).exclude(poster='')
|
||||
if poster.count() > 0:
|
||||
posters['local'] = [p.poster.url]
|
||||
return posters
|
||||
|
||||
def getMovieStills(movie_id):
|
||||
getPosterUrls(movie_id)
|
||||
stills = {}
|
||||
for p in PosterCache.objects.all().filter(movie_id=movie_id, failed=False).order_by('id'):
|
||||
if p.site not in stills:
|
||||
stills[p.site] = []
|
||||
still = p.get()
|
||||
if still:
|
||||
pjson = {}
|
||||
pjson['url'] = still._get_url()
|
||||
pjson['width'] = still.width
|
||||
pjson['height'] = still.height
|
||||
if still.width > still.height:
|
||||
stills[p.site].append(pjson)
|
||||
for p in stills.keys():
|
||||
if not stills[p]:
|
||||
del stills[p]
|
||||
return stills
|
||||
|
||||
def poster_path(url, filename):
|
||||
url_hash = hashlib.sha1(url).hexdigest()
|
||||
ext = 'jpg'
|
||||
|
@ -76,23 +98,12 @@ class PosterCache(models.Model):
|
|||
self.save()
|
||||
return self.image
|
||||
|
||||
|
||||
class Poster(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
movie_id = models.ForeignKey(MovieId, related_name='poster')
|
||||
poster = models.ForeignKey(PosterCache, default=None, blank=True)
|
||||
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
|
||||
if self.poster:
|
||||
return self.poster.get()
|
||||
#FIXME: select poster
|
||||
return None
|
||||
poster = models.ImageField(max_length=255, upload_to=lambda i, f: poster_path('upload/%s' % i.id, f))
|
||||
|
||||
def getPosterUrls(m):
|
||||
def addPoster(url, site, site_id):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('oxdata.poster.views',
|
||||
(r'^$', 'poster'),
|
||||
(r'^json$', 'poster_json'),
|
||||
(r'^$', 'poster_json'),
|
||||
(r'^.html$', 'poster_html'),
|
||||
)
|
||||
|
||||
|
|
|
@ -12,27 +12,22 @@ from oxdata.lookup.models import MovieId
|
|||
|
||||
import models
|
||||
|
||||
def poster(request):
|
||||
#FIXME: get MovieId from provided id and redirect to poster url
|
||||
imdbId = None
|
||||
oxdbId = None
|
||||
def get_movie_id(request):
|
||||
if 'imdb' in request.GET:
|
||||
imdbId = request.GET['imdb']
|
||||
movie_id = MovieId.objects.get(imdb_id=imdbId)
|
||||
elif 'oxdb' in request.GET:
|
||||
oxdbId = request.GET['oxdb']
|
||||
movie_id = MovieId.objects.get(oxdb_id=oxdbId)
|
||||
context = RequestContext(request, {'imdb': imdbId, 'oxdb': oxdbId})
|
||||
return render_to_response('poster.html', context)
|
||||
return movie_id
|
||||
|
||||
def poster_json(request):
|
||||
#FIXME: get MovieId from provided id and redirect to poster url
|
||||
if 'imdb' in request.GET:
|
||||
imdbId = request.GET['imdb']
|
||||
movie_id = MovieId.objects.get(imdb_id=imdbId)
|
||||
elif 'oxdb' in request.GET:
|
||||
oxdbId = request.GET['oxdb']
|
||||
movie_id = MovieId.objects.get(oxdb_id=oxdbId)
|
||||
def poster(request):
|
||||
movie_id = get_movie_id(request)
|
||||
json = models.getPosters(movie_id)
|
||||
return render_to_json_response(json)
|
||||
|
||||
def still(request):
|
||||
movie_id = get_movie_id(request)
|
||||
json = models.getMovieStills(movie_id)
|
||||
return render_to_json_response(json)
|
||||
|
||||
|
|
|
@ -1 +1,35 @@
|
|||
<pre>
|
||||
oxdata
|
||||
|
||||
public services:
|
||||
|
||||
lookup ids:
|
||||
/id/?imdb=0297884
|
||||
/id/?wikipedia=Far_from_Heaven
|
||||
|
||||
{
|
||||
"wikipedia_id": "Far_from_Heaven",
|
||||
"impawards_id": "2002/far_from_heaven",
|
||||
"title": "Far from Heaven",
|
||||
"directors": [
|
||||
"Todd Haynes"
|
||||
],
|
||||
"imdb_id": "0297884",
|
||||
"oxdb_id": "0x0db82dc4d1cd4a118e7b87b718749030a946f4be",
|
||||
"year": 2002
|
||||
}
|
||||
|
||||
get posters:
|
||||
/poster/?imdb=0297884
|
||||
/poster/?wikipedia=Far_from_Heaven
|
||||
|
||||
{
|
||||
"sitename": [
|
||||
{
|
||||
"url": "/url/to/poster",
|
||||
"width: 123,
|
||||
"height": 123
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ admin.autodiscover()
|
|||
urlpatterns = patterns('',
|
||||
(r'^$', 'oxdata.views.index'),
|
||||
(r'^poster/', include('oxdata.poster.urls')),
|
||||
(r'^still/$', 'oxdata.poster.views.still'),
|
||||
(r'^id/', include('oxdata.lookup.urls')),
|
||||
|
||||
# Uncomment the next line to enable the admin:
|
||||
|
|
Loading…
Reference in a new issue