From fe45b30345bb67c48355e6bf50924bff8775c821 Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 6 Aug 2011 18:00:15 +0000 Subject: [PATCH] use new media urls --- pandora/item/models.py | 4 ++-- pandora/item/urls.py | 35 ++++++++++++++++++++------------ pandora/item/views.py | 31 ++++++++++++---------------- static/js/pandora/ui/browser.js | 2 +- static/js/pandora/ui/flipbook.js | 2 +- static/js/pandora/ui/info.js | 13 ++++++++---- static/js/pandora/ui/infoView.js | 8 ++++---- static/js/pandora/ui/item.js | 18 ++++++++-------- static/js/pandora/ui/list.js | 21 +++++++++++-------- static/js/pandora/ui/menu.js | 17 +++++++++++----- 10 files changed, 84 insertions(+), 67 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index fd7d243e0..88f241c5c 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -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'] }) diff --git a/pandora/item/urls.py b/pandora/item/urls.py index 7f25e5a3b..d24f1453b 100644 --- a/pandora/item/urls.py +++ b/pandora/item/urls.py @@ -5,17 +5,26 @@ from django.conf.urls.defaults import * urlpatterns = patterns("item.views", - (r'^(?P[A-Z0-9].*)/frame/(?P\d+)/(?P[0-9\.,]+).jpg$', 'frame'), - (r'^(?P[A-Z0-9].*)/frame/poster/(?P\d+).jpg$', 'poster_frame'), - (r'^(?P[A-Z0-9].*)/(?P[a-f0-9]+)/(?P.*\.(?Pwebm|ogv|mp4))$', 'video'), - (r'^(?P[A-Z0-9][A-Za-z0-9]+)/torrent/(?P.*?)$', 'torrent'), - (r'^(?P[A-Z0-9].*)/(?P.*\.(?Pwebm|ogv|mp4))$', 'video'), - (r'^(?P[A-Z0-9].*)/poster\.(?P\d+)\.jpg$', 'poster'), - (r'^(?P[A-Z0-9].*)/poster\.(?Plarge)\.jpg$', 'poster'), - (r'^(?P[A-Z0-9].*)/poster\.pandora\.jpg$', 'poster_local'), - (r'^(?P[A-Z0-9].*)/poster\.jpg$', 'poster'), - (r'^(?P[A-Z0-9].*)/icon\.(?P\d+)\.jpg$', 'icon'), - (r'^(?P[A-Z0-9].*)/icon\.jpg$', 'icon'), - (r'^(?P[A-Z0-9].*)/timelines/(?P.+)\.(?P\d+)\.(?P\d+)\.png$', 'timeline'), - (r'^(?P[A-Z0-9].*)/timeline\.(?P\d+)\.png$', 'timeline_overview'), + #frames + (r'^(?P[A-Z0-9].+)/frame(?P\d+)p(?P[\d\.]+)\.jpg$', 'frame'), + + #timelines + (r'^(?P[A-Z0-9].+)/timeline(?P\d+)p(?P\d+)\.png$', 'timeline'), + (r'^(?P[A-Z0-9].+)/timeline(?P\d+)p\.png$', 'timeline_overview'), + + #video + (r'^(?P[A-Z0-9].+)/(?P\d+p)(?P\d*)\.(?Pwebm|ogv|mp4)$', 'video'), + + #torrent + (r'^(?P[A-Z0-9][A-Za-z0-9]+)/torrent/(?P.+?)$', 'torrent'), + + #icon + (r'^(?P[A-Z0-9].+)/icon(?P\d*)\.jpg$', 'icon'), + + #poster + (r'^(?P[A-Z0-9].+)/poster(?P\d+)\.jpg$', 'poster'), + (r'^(?P[A-Z0-9].+)/poster\.jpg$', 'poster_local'), + (r'^(?P[A-Z0-9].+)/frameposter(?P\d+).jpg$', 'poster_frame'), + + ) diff --git a/pandora/item/views.py b/pandora/item/views.py index bbe25343c..d94e0c3c1 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -573,8 +573,9 @@ 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) - extract.resize_image(image.path, path, size=size) + path = image.path + else: + extract.resize_image(image.path, path, size=size) else: path = image.path return HttpFileResponse(path, content_type='image/jpeg') @@ -587,17 +588,13 @@ 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' - return response + response = HttpFileResponse(poster_path, content_type='image/jpeg') + response['Cache-Control'] = 'no-cache' + return response def icon(request, id, size=None): @@ -608,12 +605,9 @@ 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)) + 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') diff --git a/static/js/pandora/ui/browser.js b/static/js/pandora/ui/browser.js index 083c0aa33..8573316d6 100644 --- a/static/js/pandora/ui/browser.js +++ b/static/js/pandora/ui/browser.js @@ -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 }; }, diff --git a/static/js/pandora/ui/flipbook.js b/static/js/pandora/ui/flipbook.js index 509ea77c7..b69954780 100644 --- a/static/js/pandora/ui/flipbook.js +++ b/static/js/pandora/ui/flipbook.js @@ -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); diff --git a/static/js/pandora/ui/info.js b/static/js/pandora/ui/info.js index e1e7c3fdc..ee71f3c9a 100644 --- a/static/js/pandora/ui/info.js +++ b/static/js/pandora/ui/info.js @@ -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; }; diff --git a/static/js/pandora/ui/infoView.js b/static/js/pandora/ui/infoView.js index 332f9dec8..3f35c3f2f 100644 --- a/static/js/pandora/ui/infoView.js +++ b/static/js/pandora/ui/infoView.js @@ -36,7 +36,7 @@ pandora.ui.infoView = function(data) { .appendTo($info), $poster = Ox.Element('') .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 = $('') .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() { diff --git a/static/js/pandora/ui/item.js b/static/js/pandora/ui/item.js index 0932b6100..c9c668e39 100644 --- a/static/js/pandora/ui/item.js +++ b/static/js/pandora/ui/item.js @@ -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', diff --git a/static/js/pandora/ui/list.js b/static/js/pandora/ui/list.js index 34428884e..6a3a60b6d 100644 --- a/static/js/pandora/ui/list.js +++ b/static/js/pandora/ui/list.js @@ -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: { diff --git a/static/js/pandora/ui/menu.js b/static/js/pandora/ui/menu.js index 927acea1b..53e37310e 100644 --- a/static/js/pandora/ui/menu.js +++ b/static/js/pandora/ui/menu.js @@ -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];