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

View file

@ -5,17 +5,26 @@ from django.conf.urls.defaults import *
urlpatterns = patterns("item.views",
(r'^(?P<id>[A-Z0-9].*)/frame/(?P<size>\d+)/(?P<position>[0-9\.,]+).jpg$', 'frame'),
(r'^(?P<id>[A-Z0-9].*)/frame/poster/(?P<position>\d+).jpg$', 'poster_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'),
(r'^(?P<id>[A-Z0-9].*)/(?P<profile>.*\.(?P<format>webm|ogv|mp4))$', 'video'),
(r'^(?P<id>[A-Z0-9].*)/poster\.(?P<size>\d+)\.jpg$', 'poster'),
(r'^(?P<id>[A-Z0-9].*)/poster\.(?P<size>large)\.jpg$', 'poster'),
(r'^(?P<id>[A-Z0-9].*)/poster\.pandora\.jpg$', 'poster_local'),
(r'^(?P<id>[A-Z0-9].*)/poster\.jpg$', 'poster'),
(r'^(?P<id>[A-Z0-9].*)/icon\.(?P<size>\d+)\.jpg$', 'icon'),
(r'^(?P<id>[A-Z0-9].*)/icon\.jpg$', 'icon'),
(r'^(?P<id>[A-Z0-9].*)/timelines/(?P<timeline>.+)\.(?P<size>\d+)\.(?P<position>\d+)\.png$', 'timeline'),
(r'^(?P<id>[A-Z0-9].*)/timeline\.(?P<size>\d+)\.png$', 'timeline_overview'),
#frames
(r'^(?P<id>[A-Z0-9].+)/frame(?P<size>\d+)p(?P<position>[\d\.]+)\.jpg$', 'frame'),
#timelines
(r'^(?P<id>[A-Z0-9].+)/timeline(?P<size>\d+)p(?P<position>\d+)\.png$', 'timeline'),
(r'^(?P<id>[A-Z0-9].+)/timeline(?P<size>\d+)p\.png$', 'timeline_overview'),
#video
(r'^(?P<id>[A-Z0-9].+)/(?P<profile>\d+p)(?P<index>\d*)\.(?P<format>webm|ogv|mp4)$', 'video'),
#torrent
(r'^(?P<id>[A-Z0-9][A-Za-z0-9]+)/torrent/(?P<filename>.+?)$', 'torrent'),
#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):
image_size = max(image.width, image.height)
if size > image_size:
return redirect('/%s/icon.jpg' % item.itemId)
path = image.path
else:
extract.resize_image(image.path, path, size=size)
else:
path = image.path
@ -587,13 +588,9 @@ def poster_local(request, id):
def poster(request, id, size=None):
item = get_object_or_404(models.Item, itemId=id)
if size == 'large':
size = None
if item.poster:
return image_to_response(item, item.poster, size)
else:
if not size:
size='large'
poster_path = os.path.join(settings.STATIC_ROOT, 'png/posterDark.48.png')
response = HttpFileResponse(poster_path, content_type='image/jpeg')
response['Cache-Control'] = 'no-cache'
@ -608,11 +605,8 @@ def icon(request, id, size=None):
raise Http404
def timeline(request, id, timeline, size, position):
def timeline(request, id, size, position):
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))
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))
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)
if oshash:
stream = get_object_or_404(item.files, oshash=oshash)
if index:
stream = item.streams.filter(profile=profile)[index]
path = stream.video.path
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
#server side cutting
t = request.GET.get('t')

View file

@ -48,7 +48,7 @@ pandora.ui.browser = function() {
id: data['id'],
info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key],
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
};
},

View file

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

View file

@ -25,8 +25,11 @@ pandora.ui.info = function() {
pandora.resizeFolders();
}
});
if(pandora.user.ui.item) {
pandora.api.getItem(pandora.user.ui.item, function(result) {
if (pandora.user.ui.item) {
pandora.api.get({
id: pandora.user.ui.item,
keys: ['stream']
}, function(result) {
pandora.user.infoRatio = result.data.stream.aspectRatio;
var width = that.width() || 256,
height = width / pandora.user.infoRatio + 16;
@ -41,9 +44,11 @@ pandora.ui.info = function() {
});
pandora.resizeFolders();
!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 + '/timeline16p.png'
});
pandora.$ui.infoTimeline.attr('src', '/'+pandora.user.ui.item+'/timeline.16.png');
}
return that;
};

View file

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

View file

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

View file

@ -75,14 +75,17 @@ pandora.ui.list = function(view) { // fixme: remove view argument
defaultRatio: 5/8,
id: 'list',
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;
return {
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],
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
};
},
@ -113,13 +116,13 @@ pandora.ui.list = function(view) { // fixme: remove view argument
item: function(data, sort, size) {
size = size || 128;
var ratio = data.aspectRatio,
width = size,
height = size/ratio,
url = '/' + data.item + '/frame/' + size + '/'+data['in'] + '.jpg';
width = ratio > 1 ? size : Math.round(size * ratio),
height = ratio > 1 ? Math.round(size / ratio) : size,
url = '/' + data.item + '/frame' + height + 'p' + data['in'] + '.jpg';
return {
height: height,
id: data['id'],
info: Ox.formatDuration(data['in'], 'short') +' - '+ Ox.formatDuration(data['out'], 'short'),
info: Ox.formatDuration(data['in'], 'short') + ' - ' + Ox.formatDuration(data['out'], 'short'),
title: data.value,
url: url,
width: width
@ -130,7 +133,7 @@ pandora.ui.list = function(view) { // fixme: remove view argument
query = {conditions:[]};
//fixme: can this be in pandora.Query? dont just check for subtitles
itemQuery.conditions.forEach(function(q) {
if(q.key == 'subtitles') {
if (q.key == 'subtitles') {
query.conditions.push({key: 'value', value: q.value, operator: q.operator});
}
});
@ -463,7 +466,7 @@ pandora.ui.list = function(view) { // fixme: remove view argument
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({
query: {

View file

@ -71,16 +71,16 @@ pandora.ui.mainMenu = function() {
] },
{ id: 'viewMenu', title: 'View', 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({
checked: pandora.user.ui.lists[pandora.user.ui.list].listView == view.id,
}, view);
}) },
]},
{ id: 'icons', title: 'Icons', items: [
{ id: 'poster', title: 'Poster' },
{ id: 'still', title: 'Still' },
{ id: 'timeline', title: 'Timeline' }
{ group: 'viewicons', min: 1, max: 1, items: ['posters', 'frames'].map(function(icons) {
return {id: icons, title: Ox.toTitleCase(icons), checked: pandora.user.ui.icons == icons};
}) }
] },
{ id: 'info', title: 'Info', items: [
{ 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: [
{ 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({
checked: pandora.user.ui.itemView == view.id,
}, view);
@ -168,6 +168,13 @@ pandora.ui.mainMenu = function() {
if (data.id == 'find') {
var id = data.checked[0].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') {
var view = data.checked[0].id;
var id = document.location.pathname.split('/')[1];