diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index 10e9609..695cb40 100644 --- a/pandora/archive/extract.py +++ b/pandora/archive/extract.py @@ -223,14 +223,24 @@ def frame(videoFile, position, baseFolder, width=128, redo=False): resize_image(frame_base, frame, width) return frame -def resize_image(image_source, image_output, width): +def resize_image(image_source, image_output, width=None, size=None): if exists(image_source): source = Image.open(image_source) source_width = source.size[0] source_height = source.size[1] - - height = int(width / (float(source_width) / source_height)) - height = height - height % 2 + if size: + if source_width > source_height: + width = size + height = int(width / (float(source_width) / source_height)) + height = height - height % 2 + else: + height = size + width = int(height * (float(source_width) / source_height)) + width = width - width % 2 + + else: + height = int(width / (float(source_width) / source_height)) + height = height - height % 2 if width < source_width: resize_method = Image.ANTIALIAS diff --git a/pandora/archive/models.py b/pandora/archive/models.py index d21e313..1741f73 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -21,7 +21,6 @@ from ox.normalize import canonicalTitle, canonicalName from firefogg import Firefogg from backend import utils -from backend import extract from pandora.backend.models import Movie import extract diff --git a/pandora/backend/models.py b/pandora/backend/models.py index f124ebf..414f0c7 100644 --- a/pandora/backend/models.py +++ b/pandora/backend/models.py @@ -144,12 +144,6 @@ class Movie(models.Model): poster_frame = models.FloatField(default=-1) - def get_poster(self): - url = self.poster_url - if not url and self.poster: - url = self.poster.url - return url - #stream related fields stream_aspect = models.FloatField(default=4/3) @@ -201,14 +195,17 @@ class Movie(models.Model): 'poster_width': 'posterWidth', 'poster_height': 'posterHeight' } - def poster_json(self): + def get_poster(self): poster = {} poster['width'] = self.poster_width poster['height'] = self.poster_height + poster['url'] = '/poster/%s.jpg' % self.movieId + ''' if self.poster: poster['url'] = self.poster.url else: poster['url'] = self.poster_url + ''' return poster def get_json(self, fields=None): @@ -225,9 +222,8 @@ class Movie(models.Model): else: movie[pub_key] = value if not fields: - movie['poster'] = self.get_poster() movie['stream'] = self.get_stream() - movie['poster'] = self.poster_json() + movie['poster'] = self.get_poster() if fields: for f in fields: if f.endswith('.length') and f[:-7] in ('cast', 'genre', 'trivia'): diff --git a/pandora/backend/urls.py b/pandora/backend/urls.py index 76ddd37..ae98e8a 100644 --- a/pandora/backend/urls.py +++ b/pandora/backend/urls.py @@ -7,6 +7,8 @@ from django.conf.urls.defaults import * urlpatterns = patterns("backend.views", (r'^frame/(?P.*)/(?P.*)\.(?P\d+).jpg$', 'frame'), (r'^stream/(?P.*).(?P.*).ogv$', 'video'), - (r'^$', 'api'), + (r'^poster/(?P.*)\.(?P\d+)\.jpg$', 'poster'), + (r'^poster/(?P.*)\.jpg$', 'poster'), + (r'^api/$', 'api'), ) diff --git a/pandora/backend/views.py b/pandora/backend/views.py index 29f98f5..c2a9956 100644 --- a/pandora/backend/views.py +++ b/pandora/backend/views.py @@ -13,7 +13,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.db.models import Q, Avg, Count, Sum from django.http import HttpResponse, Http404 -from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404 +from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404, redirect from django.template import RequestContext from django.conf import settings @@ -37,6 +37,8 @@ from oxuser.views import api_login, api_logout, api_register, api_contact, api_r from archive.views import api_update, api_upload from archive.models import File +from archive import extract + def api(request): if request.META['REQUEST_METHOD'] == "OPTIONS": @@ -492,6 +494,27 @@ def api_getImdbId(request): response = json_response(status=404, text='not found') return render_to_json_response(response) +def poster(request, id, size=None): + print id, size + movie = get_object_or_404(models.Movie, movieId=id) + if movie.poster: + if size: + size = int(size) + poster_path = movie.poster.path.replace('.jpg', '.%d.jpg'%size) + if not os.path.exists(poster_path): + poster_size = max(movie.poster.width, movie.poster.height) + size = min(size, poster_size) + poster_path = movie.poster.path.replace('.jpg', '.%d.jpg'%size) + extract.resize_image(movie.poster.path, poster_path, size=size) + url = movie.poster.url.replace('.jpg', '.%d.jpg'%size) + elif movie.poster: + url = movie.poster.url + else: + url = movie.poster_url + if not url: + url = '/static/png/posterDark.48.png' + return redirect(url) + def video(request, id, quality): movie = get_object_or_404(models.Movie, movieId=id) if quality not in settings.VIDEO_ENCODING: diff --git a/pandora/static/js/pandora.js b/pandora/static/js/pandora.js index 11398f1..e882069 100755 --- a/pandora/static/js/pandora.js +++ b/pandora/static/js/pandora.js @@ -516,12 +516,13 @@ app.constructList = function(view) { $list = new Ox.IconList({ id: 'list', item: function(data, sort, size) { + size = size || 128; return { height: data.poster.height || 128, // fixme: remove later id: data['id'], info: data[info], title: data.title + (data.director ? ' (' + data.director + ')' : ''), - url: 'http://0xdb.org/' + data.id + '/poster.' + size + '.' + 'jpg', //url: data.poster.url.replace(/.jpg/, size + '.jpg'), + url: data.poster.url.replace(/jpg$/, size + '.jpg'), width: data.poster.width || 80 // fixme: remove later }; }, diff --git a/pandora/static/png/posterDark.48.png b/pandora/static/png/posterDark.48.png new file mode 100644 index 0000000..182e6c9 Binary files /dev/null and b/pandora/static/png/posterDark.48.png differ diff --git a/pandora/urls.py b/pandora/urls.py index 898e94f..e735515 100644 --- a/pandora/urls.py +++ b/pandora/urls.py @@ -10,13 +10,13 @@ admin.autodiscover() urlpatterns = patterns('', # Example: (r'^ajax_filtered_fields/', include('ajax_filtered_fields.urls')), - (r'^api/', include('backend.urls')), (r'^api/upload/$', 'archive.views.firefogg_upload'), (r'^site.js$', 'app.views.site_js'), (r'^pandora.json$', 'app.views.pandora_json'), (r'^$', 'app.views.intro'), (r'^ra$', 'app.views.index'), (r'^r/(?P.*)$', 'oxuser.views.recover'), + (r'', include('backend.urls')), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: