From 3d6d1be2e69f20902f45539108429071e8392db4 Mon Sep 17 00:00:00 2001 From: j Date: Sat, 13 Aug 2016 15:35:20 +0200 Subject: [PATCH] include oshash in video url to avoid cache issues --- pandora/clip/models.py | 8 ++++++-- pandora/clip/views.py | 2 +- pandora/item/views.py | 2 ++ static/js/item.js | 2 +- static/js/itemClips.js | 5 +++-- static/js/utils.js | 14 +++++++------- static/js/videoView.js | 2 +- 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/pandora/clip/models.py b/pandora/clip/models.py index 51499d13e..73e9a9a89 100644 --- a/pandora/clip/models.py +++ b/pandora/clip/models.py @@ -126,10 +126,13 @@ class MetaClip(object): j['cuts'] = tuple([c for c in self.item.get('cuts', []) if c > self.start and c < self.end]) for key in keys: if key not in self.clip_keys and key not in j: - value = self.item.get(key) or self.item.json.get(key) + if key == 'streams': + value = [s.file.oshash for s in self.item.streams()] + else: + value = self.item.get(key) or self.item.json.get(key) if not value and hasattr(self.item.sort, key): value = getattr(self.item.sort, key) - if value != None: + if value is not None: j[key] = value return j @@ -152,6 +155,7 @@ class MetaClip(object): data['duration'] = data['out'] - data['in'] data['cuts'] = tuple([c for c in self.item.get('cuts', []) if c > self.start and c < self.end]) data['layers'] = self.get_layers(user) + data['streams'] = [s.file.oshash for s in self.item.streams()] return data def get_layers(self, user=None): diff --git a/pandora/clip/views.py b/pandora/clip/views.py index 6bddfd374..bd8b5665d 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -149,7 +149,7 @@ def findClips(request, data): if 'annotations' in keys: aqs = Annotation.objects.filter(layer__in=settings.CONFIG['clipLayers'], clip__in=clips) - add_annotations('annotations', aqs , True) + add_annotations('annotations', aqs, True) for layer in filter(lambda l: l in keys, layer_ids): aqs = Annotation.objects.filter(layer=layer, clip__in=clips) diff --git a/pandora/item/views.py b/pandora/item/views.py index 970c0452b..0bed6260f 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -472,6 +472,8 @@ def get(request, data): info = item.get_json(data['keys']) if not data['keys'] or 'stream' in data['keys']: info['stream'] = item.get_stream() + if not data['keys'] or 'streams' in data['keys']: + info['streams'] = [s.file.oshash for s in item.streams()] if data['keys'] and 'layers' in data['keys']: info['layers'] = item.get_layers(request.user) if data['keys'] and 'documents' in data['keys']: diff --git a/static/js/item.js b/static/js/item.js index 458acafcb..5dad4abfd 100644 --- a/static/js/item.js +++ b/static/js/item.js @@ -16,7 +16,7 @@ pandora.ui.item = function() { 'audioTracks', 'cuts', 'duration', 'durations', 'editable', 'layers', 'modified', 'parts', 'posterFrame', 'rendered', 'rightslevel', - 'size', 'videoRatio', + 'streams', 'size', 'videoRatio', ].concat(pandora.site.itemTitleKeys) : [] }, pandora.user.ui.itemView == 'info' && pandora.site.capabilities.canEditMetadata[pandora.user.level] ? 0 : -1, function(result) { diff --git a/static/js/itemClips.js b/static/js/itemClips.js index 26df7a777..071e033e1 100644 --- a/static/js/itemClips.js +++ b/static/js/itemClips.js @@ -95,7 +95,7 @@ pandora.ui.itemClips = function(options) { $img = $item.find('.OxIcon > img'); points = [$item.data('in'), $item.data('out')]; if ($img.length) { - pandora.api.get({id: self.options.id, keys: ['durations', 'rightslevel']}, function(result) { + pandora.api.get({id: self.options.id, keys: ['durations', 'rightslevel', 'streams']}, function(result) { var partsAndPoints = pandora.getVideoPartsAndPoints( result.data.durations, points ), @@ -113,7 +113,8 @@ pandora.ui.itemClips = function(options) { ), rewind: true, video: partsAndPoints.parts.map(function(i) { - return pandora.getVideoURL(self.options.id, Ox.min(pandora.site.video.resolutions), i + 1); + return pandora.getVideoURL(self.options.id, Ox.min(pandora.site.video.resolutions), i + 1, + null, result.data.streams[i]); }), width: self.width }) diff --git a/static/js/utils.js b/static/js/utils.js index 8675753bf..d02d94462 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1021,7 +1021,7 @@ pandora.getClipVideos = function(clip, resolution) { resolution = resolution || pandora.user.ui.videoResolution; return Ox.flatten(Ox.range(clip.parts).map(function(i) { var item = { - src: pandora.getVideoURL(clip.item, resolution, i + 1), + src: pandora.getVideoURL(clip.item, resolution, i + 1, null, clip.streams[i]), resolution: resolution }; if (currentTime + clip.durations[i] <= start || currentTime > end) { @@ -1937,12 +1937,12 @@ pandora.getMediaURL = function(url) { return pandora.site.site.mediaprefix + url; }; -pandora.getVideoURLName = function(id, resolution, part, track) { +pandora.getVideoURLName = function(id, resolution, part, track, streamId) { return id + '/' + resolution + 'p' + part + (track ? '.' + track : '') - + '.' + pandora.user.videoFormat; + + '.' + pandora.user.videoFormat + (streamId ? '?' + streamId : ''); }; -pandora.getVideoURL = function(id, resolution, part, track) { +pandora.getVideoURL = function(id, resolution, part, track, streamId) { var uid = Ox.uid(), prefix = pandora.site.site.videoprefix .replace('{id}', id) @@ -1952,7 +1952,7 @@ pandora.getVideoURL = function(id, resolution, part, track) { .replace('{uid42}', uid % 42), local = pandora.fs && pandora.fs.getVideoURL(id, resolution, part, track); return local || prefix + '/' - + pandora.getVideoURLName(id, resolution, part, track); + + pandora.getVideoURLName(id, resolution, part, track, streamId); }; pandora.getCensoredClips = function(data) { @@ -2026,7 +2026,7 @@ pandora.getVideoOptions = function(data) { track: Ox.getLanguageNameByCode(track), resolution: resolution, src: pandora.getVideoURL( - data.item || pandora.user.ui.item, resolution, i + 1, track + data.item || pandora.user.ui.item, resolution, i + 1, track, data.streams[i] ) }); }); @@ -2038,7 +2038,7 @@ pandora.getVideoOptions = function(data) { index: i, resolution: resolution, src: pandora.getVideoURL( - data.item || pandora.user.ui.item, resolution, i + 1 + data.item || pandora.user.ui.item, resolution, i + 1, null, data.streams[i] ) }); }); diff --git a/static/js/videoView.js b/static/js/videoView.js index 8d2a5c3e5..3165fadb6 100644 --- a/static/js/videoView.js +++ b/static/js/videoView.js @@ -52,7 +52,7 @@ pandora.ui.videoView = function(isEmbed) { pandora.api.findClips({ query: query, itemsQuery: itemsQuery, - keys: ['id', 'in', 'out', 'durations', 'parts'], + keys: ['id', 'in', 'out', 'durations', 'parts', 'streams'], range: range, sort: pandora.user.ui.listSort }, function(result) {