From 3229c732d4ae75b5a5ddc5a5897f660bab5c2c71 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 21 Mar 2015 12:59:21 +0530 Subject: [PATCH] dont download same video/resolution again --- static/js/fs.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/static/js/fs.js b/static/js/fs.js index 1c2c7d34..f3b015bb 100644 --- a/static/js/fs.js +++ b/static/js/fs.js @@ -30,21 +30,26 @@ pandora.fs = (function() { } that.cacheVideo = function(id, callback) { - that.downloads = that.downloads || {}; - that.downloads[id] = { - added: new Date(), - cancel: function() { - }, - id: id + '::' + pandora.user.ui.videoResolution, - item: id, - progress: 0, - resolution: pandora.user.ui.videoResolution, - size: 0 - }; + if (that.getVideoURL(id, pandora.user.ui.videoResolution, 1) || that.downloads[id]) { + callback({progress: 1}); + return; + } else { + that.downloads = that.downloads || {}; + that.downloads[id] = { + added: new Date(), + cancel: function() { + }, + id: id + '::' + pandora.user.ui.videoResolution, + item: id, + progress: 0, + resolution: pandora.user.ui.videoResolution, + size: 0 + }; - queue.length - ? queue.push([id, callback]) - : startDownload(id, callback); + queue.length + ? queue.push([id, callback]) + : startDownload(id, callback); + } function startDownload(id, callback) { pandora.api.get({id: id, keys: ['parts']}, function(result) {