add poster/movieId.size.jpg

This commit is contained in:
j 2010-09-07 16:05:38 +02:00
parent 7a01749b66
commit 744dfb101e
8 changed files with 49 additions and 18 deletions

View file

@ -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

View file

@ -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

View file

@ -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'):

View file

@ -7,6 +7,8 @@ from django.conf.urls.defaults import *
urlpatterns = patterns("backend.views",
(r'^frame/(?P<id>.*)/(?P<position>.*)\.(?P<size>\d+).jpg$', 'frame'),
(r'^stream/(?P<id>.*).(?P<quality>.*).ogv$', 'video'),
(r'^$', 'api'),
(r'^poster/(?P<id>.*)\.(?P<size>\d+)\.jpg$', 'poster'),
(r'^poster/(?P<id>.*)\.jpg$', 'poster'),
(r'^api/$', 'api'),
)

View file

@ -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:

View file

@ -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
};
},

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

View file

@ -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<key>.*)$', '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: