From f642c010cde25db795f14f451dbe8fd0a293d8e7 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 26 Mar 2015 15:42:53 +0530 Subject: [PATCH] add option to select a local video file --- static/js/cacheDialog.js | 26 ++++++++++++++++++++++++++ static/js/fs.js | 16 ++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/static/js/cacheDialog.js b/static/js/cacheDialog.js index 2ceefe7c..60f6c6c0 100644 --- a/static/js/cacheDialog.js +++ b/static/js/cacheDialog.js @@ -123,6 +123,21 @@ pandora.ui.cacheDialog = function() { }) .appendTo($item), + $fileButton = Ox.FileButton({ + title: 'Select Video...', + width: 128, + disabled: pandora.user.ui.section != 'items' + || pandora.user.ui.item == '' + || !!pandora.fs.getVideoURL(pandora.user.ui.item, pandora.user.ui.videoResolution, 1) + }) + .css({ + margin: '8px' + }) + .bindEvent({ + click: selectVideo + }) + .appendTo($item), + $cacheListButton = Ox.Button({ title: 'Cache List...', width: 128, @@ -285,6 +300,17 @@ pandora.ui.cacheDialog = function() { }); } + function selectVideo(data) { + var blob = data.files[0], + name = pandora.fs.getVideoName(pandora.user.ui.item, pandora.user.ui.videoResolution, 1); + pandora.fs.storeBlob(blob, name, function() { + getCachedVideos(function(files) { + cachedVideos = Ox.api(files); + cachedVideos(data, callback); + }); + }); + } + function updateActiveDownloads() { pandora.fs.getVideos(function(files) { files.forEach(function(file) { diff --git a/static/js/fs.js b/static/js/fs.js index db8810e6..92ef3ad8 100644 --- a/static/js/fs.js +++ b/static/js/fs.js @@ -11,6 +11,7 @@ pandora.fs = (function() { requestedBytes = 100*1024*1024*1024; // 100GB if(window.webkitRequestFileSystem) { + that.enabled = true; window.webkitRequestFileSystem(window.PERSISTENT, requestedBytes, function(fs) { that.fs = fs; that.fs.root.createReader().readEntries(function(results) { @@ -20,16 +21,11 @@ pandora.fs = (function() { } }); }); - that.enabled = true; }, function(e) { Ox.Log('FS', 'Error:', e); }); } - function getVideoName(id, resolution, part, track) { - return pandora.getVideoURLName(id, resolution, part, track).replace('/', '::'); - } - function cacheVideo(id, callback) { active = true; pandora.api.get({id: id, keys: ['parts']}, function(result) { @@ -88,6 +84,10 @@ pandora.fs = (function() { }; + that.getVideoName = function(id, resolution, part, track) { + return pandora.getVideoURLName(id, resolution, part, track).replace('/', '::'); + }; + that.removeVideo = function(id, callback) { if (that.downloads && that.downloads[id] && that.downloads[id].cancel) { that.downloads[id].cancel(); @@ -101,7 +101,7 @@ pandora.fs = (function() { var count = result.data.parts * pandora.site.video.resolutions.length, done = 0; Ox.range(result.data.parts).forEach(function(part) { pandora.site.video.resolutions.forEach(function(resolution) { - var name = getVideoName(id, resolution, part + 1); + var name = that.getVideoName(id, resolution, part + 1); that.fs.root.getFile(name, {create: false}, function(fileEntry) { // remove existing file fileEntry.remove(function(e) { @@ -158,7 +158,7 @@ pandora.fs = (function() { that.downloadVideoURL = function(id, resolution, part, track, callback) { //fixme: would be nice to download videos from subdomains, // currently throws a cross domain error - var name = getVideoName(id, resolution, part, track), + var name = that.getVideoName(id, resolution, part, track), url = '/' + pandora.getVideoURLName(id, resolution, part, track), blobs = [], blobSize = 5*1024*1024, total; Ox.Log('FS', 'start downloading', url); @@ -253,7 +253,7 @@ pandora.fs = (function() { }; that.getVideoURL = function(id, resolution, part, track) { - var name = getVideoName(id, resolution, part, track); + var name = that.getVideoName(id, resolution, part, track); return that.local[name]; };