use new media urls

This commit is contained in:
rlx 2011-08-06 18:00:15 +00:00
parent 80d02eb712
commit 60539576ed
10 changed files with 84 additions and 67 deletions

View file

@ -343,7 +343,7 @@ class Item(models.Model):
poster = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster)) poster = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster))
if os.path.exists(poster): if os.path.exists(poster):
posters.append({ posters.append({
'url': '/%s/poster.pandora.jpg' % self.itemId, 'url': '/%s/poster.jpg' % self.itemId,
'width': 640, 'width': 640,
'height': 1024, 'height': 1024,
'source': settings.URL, 'source': settings.URL,
@ -379,7 +379,7 @@ class Item(models.Model):
'index': p, 'index': p,
'position': f['position'], 'position': f['position'],
'selected': p == pos, 'selected': p == pos,
'url': '/%s/frame/poster/%d.jpg' %(self.itemId, p), 'url': '/%s/frameposter%d.jpg' %(self.itemId, p),
'height': f['height'], 'height': f['height'],
'width': f['width'] 'width': f['width']
}) })

View file

@ -5,17 +5,26 @@ from django.conf.urls.defaults import *
urlpatterns = patterns("item.views", urlpatterns = patterns("item.views",
(r'^(?P<id>[A-Z0-9].*)/frame/(?P<size>\d+)/(?P<position>[0-9\.,]+).jpg$', 'frame'), #frames
(r'^(?P<id>[A-Z0-9].*)/frame/poster/(?P<position>\d+).jpg$', 'poster_frame'), (r'^(?P<id>[A-Z0-9].+)/frame(?P<size>\d+)p(?P<position>[\d\.]+)\.jpg$', 'frame'),
(r'^(?P<id>[A-Z0-9].*)/(?P<oshash>[a-f0-9]+)/(?P<profile>.*\.(?P<format>webm|ogv|mp4))$', 'video'),
(r'^(?P<id>[A-Z0-9][A-Za-z0-9]+)/torrent/(?P<filename>.*?)$', 'torrent'), #timelines
(r'^(?P<id>[A-Z0-9].*)/(?P<profile>.*\.(?P<format>webm|ogv|mp4))$', 'video'), (r'^(?P<id>[A-Z0-9].+)/timeline(?P<size>\d+)p(?P<position>\d+)\.png$', 'timeline'),
(r'^(?P<id>[A-Z0-9].*)/poster\.(?P<size>\d+)\.jpg$', 'poster'), (r'^(?P<id>[A-Z0-9].+)/timeline(?P<size>\d+)p\.png$', 'timeline_overview'),
(r'^(?P<id>[A-Z0-9].*)/poster\.(?P<size>large)\.jpg$', 'poster'),
(r'^(?P<id>[A-Z0-9].*)/poster\.pandora\.jpg$', 'poster_local'), #video
(r'^(?P<id>[A-Z0-9].*)/poster\.jpg$', 'poster'), (r'^(?P<id>[A-Z0-9].+)/(?P<profile>\d+p)(?P<index>\d*)\.(?P<format>webm|ogv|mp4)$', 'video'),
(r'^(?P<id>[A-Z0-9].*)/icon\.(?P<size>\d+)\.jpg$', 'icon'),
(r'^(?P<id>[A-Z0-9].*)/icon\.jpg$', 'icon'), #torrent
(r'^(?P<id>[A-Z0-9].*)/timelines/(?P<timeline>.+)\.(?P<size>\d+)\.(?P<position>\d+)\.png$', 'timeline'), (r'^(?P<id>[A-Z0-9][A-Za-z0-9]+)/torrent/(?P<filename>.+?)$', 'torrent'),
(r'^(?P<id>[A-Z0-9].*)/timeline\.(?P<size>\d+)\.png$', 'timeline_overview'),
#icon
(r'^(?P<id>[A-Z0-9].+)/icon(?P<size>\d*)\.jpg$', 'icon'),
#poster
(r'^(?P<id>[A-Z0-9].+)/poster(?P<size>\d+)\.jpg$', 'poster'),
(r'^(?P<id>[A-Z0-9].+)/poster\.jpg$', 'poster_local'),
(r'^(?P<id>[A-Z0-9].+)/frameposter(?P<position>\d+).jpg$', 'poster_frame'),
) )

View file

@ -573,7 +573,8 @@ def image_to_response(item, image, size=None):
if not os.path.exists(path): if not os.path.exists(path):
image_size = max(image.width, image.height) image_size = max(image.width, image.height)
if size > image_size: if size > image_size:
return redirect('/%s/icon.jpg' % item.itemId) path = image.path
else:
extract.resize_image(image.path, path, size=size) extract.resize_image(image.path, path, size=size)
else: else:
path = image.path path = image.path
@ -587,13 +588,9 @@ def poster_local(request, id):
def poster(request, id, size=None): def poster(request, id, size=None):
item = get_object_or_404(models.Item, itemId=id) item = get_object_or_404(models.Item, itemId=id)
if size == 'large':
size = None
if item.poster: if item.poster:
return image_to_response(item, item.poster, size) return image_to_response(item, item.poster, size)
else: else:
if not size:
size='large'
poster_path = os.path.join(settings.STATIC_ROOT, 'png/posterDark.48.png') poster_path = os.path.join(settings.STATIC_ROOT, 'png/posterDark.48.png')
response = HttpFileResponse(poster_path, content_type='image/jpeg') response = HttpFileResponse(poster_path, content_type='image/jpeg')
response['Cache-Control'] = 'no-cache' response['Cache-Control'] = 'no-cache'
@ -608,11 +605,8 @@ def icon(request, id, size=None):
raise Http404 raise Http404
def timeline(request, id, timeline, size, position): def timeline(request, id, size, position):
item = get_object_or_404(models.Item, itemId=id) item = get_object_or_404(models.Item, itemId=id)
if timeline == 'strip':
timeline = '%s.%s.%04d.png' %(item.timeline_prefix[:-8] + 'strip', size, int(position))
else:
timeline = '%s.%s.%04d.png' %(item.timeline_prefix, size, int(position)) timeline = '%s.%s.%04d.png' %(item.timeline_prefix, size, int(position))
return HttpFileResponse(timeline, content_type='image/png') return HttpFileResponse(timeline, content_type='image/png')
@ -639,13 +633,14 @@ def torrent(request, id, filename=None):
filename = os.path.abspath(os.path.join(settings.MEDIA_ROOT, filename)) filename = os.path.abspath(os.path.join(settings.MEDIA_ROOT, filename))
return HttpFileResponse(filename) return HttpFileResponse(filename)
def video(request, id, profile, oshash=None, format=None): def video(request, id, profile, index=None, format=None):
print id, profile, index, format
item = get_object_or_404(models.Item, itemId=id) item = get_object_or_404(models.Item, itemId=id)
if oshash: if index:
stream = get_object_or_404(item.files, oshash=oshash) stream = item.streams.filter(profile=profile)[index]
path = stream.video.path path = stream.video.path
else: else:
stream = get_object_or_404(item.streams, profile=profile) stream = get_object_or_404(item.streams, profile="%s.%s" % (profile, format))
path = stream.video.path path = stream.video.path
#server side cutting #server side cutting
t = request.GET.get('t') t = request.GET.get('t')

View file

@ -48,7 +48,7 @@ pandora.ui.browser = function() {
id: data['id'], id: data['id'],
info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key], info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key],
title: data.title + (data.director ? ' (' + data.director + ')' : ''), title: data.title + (data.director ? ' (' + data.director + ')' : ''),
url: data.poster.url.replace(/jpg/, size + '.jpg'), url: '/' + data['id'] + '/poster' + size + '.jpg',
width: ratio >= 1 ? size : size * ratio width: ratio >= 1 ? size : size * ratio
}; };
}, },

View file

@ -9,7 +9,7 @@ pandora.ui.flipbook = function(item) {
var duration = result.data.duration, var duration = result.data.duration,
posterFrame = result.data.posterFrame || parseInt(duration/2), posterFrame = result.data.posterFrame || parseInt(duration/2),
steps = 24, steps = 24,
framePrefix = '/' + item + '/frame/' + that.width() + '/', framePrefix = '/' + item + '/frame' + that.height() + 'p',
frames = {}; frames = {};
Ox.range(0, duration, duration/steps).forEach(function(position) { Ox.range(0, duration, duration/steps).forEach(function(position) {
position = parseInt(position); position = parseInt(position);

View file

@ -26,7 +26,10 @@ pandora.ui.info = function() {
} }
}); });
if (pandora.user.ui.item) { if (pandora.user.ui.item) {
pandora.api.getItem(pandora.user.ui.item, function(result) { pandora.api.get({
id: pandora.user.ui.item,
keys: ['stream']
}, function(result) {
pandora.user.infoRatio = result.data.stream.aspectRatio; pandora.user.infoRatio = result.data.stream.aspectRatio;
var width = that.width() || 256, var width = that.width() || 256,
height = width / pandora.user.infoRatio + 16; height = width / pandora.user.infoRatio + 16;
@ -43,7 +46,9 @@ pandora.ui.info = function() {
!pandora.user.ui.showInfo && pandora.$ui.leftPanel.css({bottom: -height}); !pandora.user.ui.showInfo && pandora.$ui.leftPanel.css({bottom: -height});
pandora.$ui.leftPanel.size(2, height); pandora.$ui.leftPanel.size(2, height);
}); });
pandora.$ui.infoTimeline.attr('src', '/'+pandora.user.ui.item+'/timeline.16.png'); pandora.$ui.infoTimeline.attr({
src: '/' + pandora.user.ui.item + '/timeline16p.png'
});
} }
return that; return that;
}; };

View file

@ -36,7 +36,7 @@ pandora.ui.infoView = function(data) {
.appendTo($info), .appendTo($info),
$poster = Ox.Element('<img>') $poster = Ox.Element('<img>')
.attr({ .attr({
src: '/' + data.id + '/poster.jpg?' + uid src: '/' + data.id + '/poster512.jpg?' + uid
}) })
.css({ .css({
position: 'absolute', position: 'absolute',
@ -63,7 +63,7 @@ pandora.ui.infoView = function(data) {
.appendTo($data.$element), .appendTo($data.$element),
$reflectionPoster = $('<img>') $reflectionPoster = $('<img>')
.attr({ .attr({
src: '/' + data.id + '/poster.jpg?' + uid src: '/' + data.id + '/poster512.jpg?' + uid
}) })
.css({ .css({
position: 'absolute', position: 'absolute',
@ -407,7 +407,7 @@ pandora.ui.infoView = function(data) {
position: selectedImage.index // fixme: api slightly inconsistent position: selectedImage.index // fixme: api slightly inconsistent
}), function() { }), function() {
$browserImages.each(function() { $browserImages.each(function() {
$(this).attr({src: '/' + data.id + '/poster.64.jpg?' + Ox.uid()}); $(this).attr({src: '/' + data.id + '/poster64.jpg?' + Ox.uid()});
}); });
}); });
} }
@ -457,7 +457,7 @@ pandora.ui.infoView = function(data) {
$text.animate({ $text.animate({
left: margin + (posterSize == 256 ? 256 : posterWidth) + margin + 'px', left: margin + (posterSize == 256 ? 256 : posterWidth) + margin + 'px',
}, 250); }, 250);
pandora.api.setUI({infoIconSize: pandora.user.ui.infoIconSize = posterSize}); pandora.UI.set({infoIconSize: posterSize});
} }
that.resize = function() { that.resize = function() {

View file

@ -24,9 +24,9 @@ pandora.ui.item = function() {
item: function(data, sort, size) { item: function(data, sort, size) {
size = size || 128; size = size || 128;
var ratio = result.data.stream.aspectRatio, var ratio = result.data.stream.aspectRatio,
width = ratio>1?size:size*ratio, width = ratio > 1 ? size : Math.round(size * ratio),
height = ratio>1?size/ratio:size, height = ratio > 1 ? Math.round(size / ratio) : size,
url = '/' + pandora.user.ui.item + '/frame/' + size + '/' + data['in'] + '.jpg'; url = '/' + pandora.user.ui.item + '/frame' + size + 'p' + data['in'] + '.jpg';
return { return {
height: height, height: height,
id: data['id'], id: data['id'],
@ -227,9 +227,7 @@ pandora.ui.item = function() {
position: pandora.user.ui.videoPosition[pandora.user.ui.item] || 0, position: pandora.user.ui.videoPosition[pandora.user.ui.item] || 0,
showAnnotations: pandora.user.ui.showAnnotations, showAnnotations: pandora.user.ui.showAnnotations,
showControls: pandora.user.ui.showControls, showControls: pandora.user.ui.showControls,
subtitles: result.data.layers.subtitles.map(function(subtitle) { subtitles: result.data.layers.subtitles,
return {'in': subtitle['in'], out: subtitle.out, text: subtitle.value};
}),
videoHeight: video.height, videoHeight: video.height,
videoId: pandora.user.ui.item, videoId: pandora.user.ui.item,
videoWidth: video.width, videoWidth: video.width,
@ -280,13 +278,13 @@ pandora.ui.item = function() {
duration: video.duration, duration: video.duration,
find: '', find: '',
getFrameURL: function(position) { getFrameURL: function(position) {
return '/' + pandora.user.ui.item + '/frame/' + video.width.toString() + '/' + position.toString() + '.jpg'; return '/' + pandora.user.ui.item + '/frame' + video.height.toString() + 'p' + position.toString() + '.jpg';
}, },
getLargeTimelineImageURL: function(i) { getLargeTimelineImageURL: function(i) {
return '/' + pandora.user.ui.item + '/timelines/timeline.64.' + i + '.png'; return '/' + pandora.user.ui.item + '/timeline64p' + i + '.png';
}, },
getSmallTimelineImageURL: function(i) { getSmallTimelineImageURL: function(i) {
return '/' + pandora.user.ui.item + '/timelines/timeline.16.' + i + '.png'; return '/' + pandora.user.ui.item + '/timeline16p' + i + '.png';
}, },
height: pandora.$ui.contentPanel.size(1), height: pandora.$ui.contentPanel.size(1),
id: 'editor', id: 'editor',

View file

@ -75,14 +75,17 @@ pandora.ui.list = function(view) { // fixme: remove view argument
defaultRatio: 5/8, defaultRatio: 5/8,
id: 'list', id: 'list',
item: function(data, sort, size) { item: function(data, sort, size) {
var ratio = data.poster.width / data.poster.height; var icons = pandora.user.ui.icons,
ratio = icons == 'posters' ? data.poster.width / data.poster.height : 1;
size = size || 128; size = size || 128;
return { return {
height: ratio <= 1 ? size : size / ratio, height: ratio <= 1 ? size : size / ratio,
id: data['id'], id: data.id,
info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key], info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key],
title: data.title + (data.director.length ? ' (' + data.director.join(', ') + ')' : ''), title: data.title + (data.director.length ? ' (' + data.director.join(', ') + ')' : ''),
url: data.poster.url.replace(/jpg/, size + '.jpg'), url: icons == 'posters'
? '/' + data.id + '/poster' + size + '.jpg'
: '/' + data.id + '/icon' + size + '.jpg',
width: ratio >= 1 ? size : size * ratio width: ratio >= 1 ? size : size * ratio
}; };
}, },
@ -113,9 +116,9 @@ pandora.ui.list = function(view) { // fixme: remove view argument
item: function(data, sort, size) { item: function(data, sort, size) {
size = size || 128; size = size || 128;
var ratio = data.aspectRatio, var ratio = data.aspectRatio,
width = size, width = ratio > 1 ? size : Math.round(size * ratio),
height = size/ratio, height = ratio > 1 ? Math.round(size / ratio) : size,
url = '/' + data.item + '/frame/' + size + '/'+data['in'] + '.jpg'; url = '/' + data.item + '/frame' + height + 'p' + data['in'] + '.jpg';
return { return {
height: height, height: height,
id: data['id'], id: data['id'],
@ -463,7 +466,7 @@ pandora.ui.list = function(view) { // fixme: remove view argument
pandora.resizeFolders(); pandora.resizeFolders();
}); });
}); });
pandora.$ui.infoTimeline.attr('src', '/'+data.ids[0]+'/timeline.16.png') pandora.$ui.infoTimeline.attr('src', '/' + data.ids[0] + '/timeline16p.png')
} }
pandora.api.find({ pandora.api.find({
query: { query: {

View file

@ -71,16 +71,16 @@ pandora.ui.mainMenu = function() {
] }, ] },
{ id: 'viewMenu', title: 'View', items: [ { id: 'viewMenu', title: 'View', items: [
{ id: 'movies', title: 'View ' + pandora.site.itemName.plural, items: [ { id: 'movies', title: 'View ' + pandora.site.itemName.plural, items: [
{ group: 'viewmovies', min: 0, max: 1, items: $.map(pandora.site.listViews, function(view, i) { { group: 'viewmovies', min: 1, max: 1, items: $.map(pandora.site.listViews, function(view, i) {
return $.extend({ return $.extend({
checked: pandora.user.ui.lists[pandora.user.ui.list].listView == view.id, checked: pandora.user.ui.lists[pandora.user.ui.list].listView == view.id,
}, view); }, view);
}) }, }) },
]}, ]},
{ id: 'icons', title: 'Icons', items: [ { id: 'icons', title: 'Icons', items: [
{ id: 'poster', title: 'Poster' }, { group: 'viewicons', min: 1, max: 1, items: ['posters', 'frames'].map(function(icons) {
{ id: 'still', title: 'Still' }, return {id: icons, title: Ox.toTitleCase(icons), checked: pandora.user.ui.icons == icons};
{ id: 'timeline', title: 'Timeline' } }) }
] }, ] },
{ id: 'info', title: 'Info', items: [ { id: 'info', title: 'Info', items: [
{ id: 'poster', title: 'Poster' }, { id: 'poster', title: 'Poster' },
@ -88,7 +88,7 @@ pandora.ui.mainMenu = function() {
] }, ] },
{}, {},
{ id: 'openmovie', title: ['Open ' + pandora.site.itemName.singular, 'Open ' + pandora.site.itemName.plural], disabled: true, items: [ { id: 'openmovie', title: ['Open ' + pandora.site.itemName.singular, 'Open ' + pandora.site.itemName.plural], disabled: true, items: [
{ group: 'movieview', min: 0, max: 1, items: $.map(pandora.site.itemViews, function(view, i) { { group: 'movieview', min: 1, max: 1, items: $.map(pandora.site.itemViews, function(view, i) {
return $.extend({ return $.extend({
checked: pandora.user.ui.itemView == view.id, checked: pandora.user.ui.itemView == view.id,
}, view); }, view);
@ -168,6 +168,13 @@ pandora.ui.mainMenu = function() {
if (data.id == 'find') { if (data.id == 'find') {
var id = data.checked[0].id; var id = data.checked[0].id;
pandora.$ui.findSelect.selectItem(id); pandora.$ui.findSelect.selectItem(id);
} else if (data.id == 'icons') {
var $list = !pandora.user.ui.item ? pandora.$ui.list : pandora.$ui.browser;
/*
list.options({
item:
});
*/
} else if (data.id == 'movieview') { } else if (data.id == 'movieview') {
var view = data.checked[0].id; var view = data.checked[0].id;
var id = document.location.pathname.split('/')[1]; var id = document.location.pathname.split('/')[1];