From ad38fa019e06cc42a850a72e0eb9537f70ebb79a Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 19 Aug 2011 14:43:05 +0000 Subject: [PATCH] switch to new get api results --- pandora/0xdb.json | 6 ++- pandora/annotation/models.py | 6 ++- pandora/app/models.py | 3 -- pandora/padma.json | 6 ++- static/js/pandora.js | 3 +- static/js/pandora/ui/info.js | 9 ++--- static/js/pandora/ui/infoView.js | 4 +- static/js/pandora/ui/item.js | 60 ++++++++++------------------ static/js/pandora/ui/list.js | 17 ++++---- static/js/pandora/ui/videoPreview.js | 8 ++-- 10 files changed, 55 insertions(+), 67 deletions(-) diff --git a/pandora/0xdb.json b/pandora/0xdb.json index d51edcc2..fd8eaf82 100644 --- a/pandora/0xdb.json +++ b/pandora/0xdb.json @@ -549,5 +549,9 @@ }, "username": "" }, - "userLevels": ["guest", "member", "staff", "admin"] + "userLevels": ["guest", "member", "staff", "admin"], + "video": { + "formats": ["webm", "h264"], + "resolutions": [96] + } } diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 544b16ea..5bc06919 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -121,8 +121,10 @@ class Annotation(models.Model): if key in j: _j[key] = j[key] j = _j - if 'aspectRatio' in keys: - j['aspectRatio'] = self.item.stream_aspect + if 'videoRatio' in keys: + streams = self.item.streams() + if streams: + j['videoRatio'] = streams[0].aspect_ratio if 'item' in keys: j['item'] = self.item.itemId return j diff --git a/pandora/app/models.py b/pandora/app/models.py index 2d480804..8cfe9794 100644 --- a/pandora/app/models.py +++ b/pandora/app/models.py @@ -34,9 +34,6 @@ def site_config(): site_config['site']['sectionName'] = settings.SITENAME site_config['site']['url'] = settings.URL - site_config['formats'] = settings.VIDEO_FORMATS - site_config['resolutions'] = settings.VIDEO_RESOLUTIONS - site_config['keys'] = {} for key in site_config['itemKeys']: site_config['keys'][key['id']] = key diff --git a/pandora/padma.json b/pandora/padma.json index 7f2d1288..c98932e6 100644 --- a/pandora/padma.json +++ b/pandora/padma.json @@ -444,5 +444,9 @@ }, "username": "" }, - "userLevels": ["guest", "member", "staff", "admin"] + "userLevels": ["guest", "member", "staff", "admin"], + "video": { + "formats": ["webm", "h264"], + "resolutions": [480, 240, 96] + } } diff --git a/static/js/pandora.js b/static/js/pandora.js index 6b8ad218..7b653b0b 100644 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -81,7 +81,8 @@ Ox.load('Geo', function() { $.extend(pandora.user, { infoRatio: 16 / 9, sectionElement: 'buttons', - selectedMovies: [] + selectedMovies: [], + videoFormat: Ox.UI.getVideoFormat(pandora.site.video.formats) }); // fixme: this should not happen if (!pandora.user.ui.lists[pandora.user.ui.list]) { diff --git a/static/js/pandora/ui/info.js b/static/js/pandora/ui/info.js index 7796d012..0becca14 100644 --- a/static/js/pandora/ui/info.js +++ b/static/js/pandora/ui/info.js @@ -1,7 +1,6 @@ // vim: et:ts=4:sw=4:sts=4:ft=javascript pandora.ui.info = function(id) { id = id || pandora.user.ui.item; - Ox.print('ID', id) var that = Ox.Element() .bindEvent({ toggle: function(data) { @@ -32,13 +31,13 @@ pandora.ui.info = function(id) { }); } else { // Video Preview - pandora.api.get({id: id, keys: ['stream']}, function(result) { - var video = result.data.stream; - height = Math.round(pandora.user.ui.sidebarSize / video.aspectRatio) + 16; + pandora.api.get({id: id, keys: ['duration', 'videoRatio']}, function(result) { + var height = Math.round(pandora.user.ui.sidebarSize / result.data.videoRatio) + 16; pandora.$ui.videoPreview && pandora.$ui.videoPreview.removeElement(); pandora.$ui.videoPreview = pandora.ui.videoPreview({ id: id, - video: video + duration: result.data.duration, + ratio: result.data.videoRatio }).appendTo(pandora.$ui.info); pandora.user.infoRatio = pandora.user.ui.sidebarSize / height; resize(height); diff --git a/static/js/pandora/ui/infoView.js b/static/js/pandora/ui/infoView.js index 91fe025f..27a1fad8 100644 --- a/static/js/pandora/ui/infoView.js +++ b/static/js/pandora/ui/infoView.js @@ -501,7 +501,7 @@ pandora.ui.infoView = function(data) { $reflectionIcon.attr({src: src}); iconSize = iconSize == 256 ? 512 : 256; iconRatio = pandora.user.ui.icons == 'posters' - ? data.posterRatio : 1; + ? data.poster.width / data.poster.height : 1; toggleIconSize(); pandora.user.level == 'admin' && $list.replaceWith($list = renderList()); }; @@ -514,4 +514,4 @@ pandora.ui.infoView = function(data) { return that; -} +} \ No newline at end of file diff --git a/static/js/pandora/ui/item.js b/static/js/pandora/ui/item.js index c3d6a6e4..8d2cfe84 100644 --- a/static/js/pandora/ui/item.js +++ b/static/js/pandora/ui/item.js @@ -116,18 +116,6 @@ pandora.ui.item = function() { } }) ); - /* - $.get('/static/html/itemInfo.html', {}, function(template) { - //Ox.print(template); - var posterRatio = result.data.posterRatio; - result.data.posterWidth = posterRatio > 1 ? 256 : Math.round(256 * posterRatio); - result.data.posterHeight = posterRatio < 1 ? 256 : Math.round(256 / posterRatio); - result.data.posterLeft = Math.floor((256 - result.data.posterWidth) / 2); - pandora.$ui.contentPanel.replaceElement(1, - pandora.$ui.item = Ox.Element().append($.tmpl(template, result.data)) - ); - }); - */ } } else if (pandora.user.ui.itemView == 'map') { @@ -221,21 +209,20 @@ pandora.ui.item = function() { } else if (pandora.user.ui.itemView == 'player') { // fixme: duplicated var layers = [], - video = result.data.stream, - cuts = result.data.cuts || [], - format = $.support.video.supportedFormat(pandora.site.formats), - streams = {}; - video.height = pandora.site.resolutions[0]; - video.width = parseInt(video.height * video.aspectRatio / 2) * 2; - pandora.site.resolutions.forEach(function(resolution) { - streams[resolution] = video.baseUrl + '/' + resolution + 'p.' + format; - }); + video = {}; $.each(pandora.site.layers, function(i, layer) { layers[i] = $.extend({}, layer, {items: result.data.layers[layer.id]}); }); + pandora.site.video.resolutions.forEach(function(resolution) { + video[resolution] = Ox.range(result.data.parts).map(function(i) { + return '/' + pandora.user.ui.item + '/' + + resolution + 'p' + (i + 1) + '.' + pandora.user.videoFormat; + }); + }); // pandora.$ui.contentPanel.replaceElement(1, pandora.$ui.player = Ox.VideoPanelPlayer({ annotationsSize: pandora.user.ui.annotationsSize, + cuts: result.data.cuts || [], duration: video.duration, getTimelineImageURL: function(i) { return '/' + pandora.user.ui.item + '/timeline64p' + i + '.png'; @@ -250,10 +237,7 @@ pandora.ui.item = function() { return {'in': subtitle['in'], out: subtitle.out, text: subtitle.value}; }) : [], timeline: '/' + pandora.user.ui.item + '/timeline16p.png', - video: streams, - videoHeight: video.height, - //videoId: pandora.user.ui.item, - videoWidth: video.width, + video: video, volume: pandora.user.ui.videoVolume, width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1 }).bindEvent({ @@ -287,25 +271,23 @@ pandora.ui.item = function() { } else if (pandora.user.ui.itemView == 'timeline') { var layers = [], - video = result.data.stream, - cuts = result.data.cuts || [], - format = $.support.video.supportedFormat(pandora.site.formats), - streams = {}; - video.height = pandora.site.resolutions[0]; - video.width = parseInt(video.height * video.aspectRatio / 2) * 2; - pandora.site.resolutions.forEach(function(resolution) { - streams[resolution] = video.baseUrl + '/' + resolution + 'p.' + format; - }); + video = result.data.stream; $.each(pandora.site.layers, function(i, layer) { layers[i] = $.extend({}, layer, {items: result.data.layers[layer.id]}); }); + pandora.site.video.resolutions.forEach(function(resolution) { + video[resolution] = Ox.range(result.data.parts).map(function(i) { + return '/' + pandora.user.ui.item + '/' + + resolution + 'p' + (i + 1) + '.' + pandora.user.videoFormat; + }); + }); pandora.$ui.contentPanel.replaceElement(1, pandora.$ui.editor = Ox.VideoEditor({ annotationsSize: pandora.user.ui.annotationsSize, - cuts: cuts, + cuts: result.data.cuts || [], duration: video.duration, find: '', getFrameURL: function(position) { - return '/' + pandora.user.ui.item + '/' + video.height.toString() + 'p' + position.toString() + '.jpg'; + return '/' + pandora.user.ui.item + '/' + Ox.last(pandora.site.video.resolutions) + 'p' + position + '.jpg'; }, getLargeTimelineImageURL: function(i) { return '/' + pandora.user.ui.item + '/timeline64p' + i + '.png'; @@ -326,10 +308,8 @@ pandora.ui.item = function() { subtitles: result.data.layers.subtitles ? result.data.layers.subtitles.map(function(subtitle) { return {'in': subtitle['in'], out: subtitle.out, text: subtitle.value}; }) : [], - video: streams, - videoHeight: video.height, - //videoId: pandora.user.ui.item, - videoWidth: video.width, + video: video, + videoRatio: result.data.videoRatio, videoSize: pandora.user.ui.videoSize, width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1 }).bindEvent({ diff --git a/static/js/pandora/ui/list.js b/static/js/pandora/ui/list.js index 1704959f..990c38e2 100644 --- a/static/js/pandora/ui/list.js +++ b/static/js/pandora/ui/list.js @@ -168,8 +168,9 @@ pandora.ui.list = function() { // fixme: remove view argument that = Ox.IconList({ fixedRatio: fixedRatio, item: function(data, sort, size) { + Ox.print('DATA', data) size = size || 128; - var ratio = data.aspectRatio, + var ratio = data.videoRatio, width = ratio > fixedRatio ? size : Math.round(size * ratio / fixedRatio), height = Math.round(width / ratio), url = '/' + data.item + '/' + height + 'p' + data['in'] + '.jpg'; @@ -196,7 +197,7 @@ pandora.ui.list = function() { // fixme: remove view argument itemQuery: itemQuery }), callback); }, - keys: ['id', 'value', 'in', 'out', 'aspectRatio', 'item'], + keys: ['id', 'value', 'in', 'out', 'video', 'videoRatio', 'item'], max: 1, size: 128, sort: pandora.user.ui.lists[pandora.user.ui.list].sort, @@ -310,10 +311,10 @@ pandora.ui.list = function() { // fixme: remove view argument element: pandora.$ui.clips = Ox.IconList({ fixedRatio: fixedRatio, item: function(data, sort, size) { - Ox.print('RATIO', data.aspectRatio); + Ox.print('RATIO', data.videoRatio); size = size || 128; - var width = data.aspectRatio < fixedRatio ? size : size * data.aspectRatio / fixedRatio, - height = width / data.aspectRatio, + var width = data.videoRatio < fixedRatio ? size : size * data.videoRatio / fixedRatio, + height = width / data.videoRatio, url = '/' + data.item + '/' + height + 'p' + data['in'] + '.jpg'; return { height: height, @@ -326,7 +327,7 @@ pandora.ui.list = function() { // fixme: remove view argument }; }, items: [], - keys: ['id', 'value', 'in', 'out', 'aspectRatio', 'item'], + keys: ['id', 'value', 'in', 'out', 'videoRatio', 'item'], size: 128, sort: pandora.user.ui.lists[pandora.user.ui.list].sort, unique: 'id' @@ -454,8 +455,8 @@ pandora.ui.list = function() { // fixme: remove view argument } }, function(result) { var item = result.data.items[0], - title = item.title + ' (' + item.director + ')', - ratio = item.posterRatio, + title = item.title + ' (' + item.director + ')' + ratio = item.poster.width / item.poster.height, windowWidth = window.innerWidth * 0.8, windowHeight = window.innerHeight * 0.8, windowRatio = windowWidth / windowHeight, diff --git a/static/js/pandora/ui/videoPreview.js b/static/js/pandora/ui/videoPreview.js index a00e5ec4..254ad3e4 100644 --- a/static/js/pandora/ui/videoPreview.js +++ b/static/js/pandora/ui/videoPreview.js @@ -2,14 +2,14 @@ pandora.ui.videoPreview = function(data) { var frameWidth = pandora.user.ui.sidebarSize, - frameHeight = Math.round(frameWidth / data.video.aspectRatio), + frameHeight = Math.round(frameWidth / data.ratio), that = Ox.VideoPreview({ - duration: data.video.duration, + duration: data.duration, getFrame: function(position) { var width = pandora.user.ui.sidebarSize, height = Math.round(width / pandora.user.infoRatio), - resolution = Ox.filter(pandora.site.resolutions, function(resolution, i) { - return resolution >= height || i == pandora.site.resolutions.length - 1; + resolution = Ox.filter(pandora.site.video.resolutions, function(resolution, i) { + return resolution >= height || i == pandora.site.video.resolutions.length - 1; })[0]; return '/' + data.id + '/' + resolution + 'p' + ( Ox.isUndefined(position) ? '' : position