forked from 0x2620/pandora
fix download queue
This commit is contained in:
parent
3229c732d4
commit
d3ce9198ce
1 changed files with 37 additions and 33 deletions
|
@ -6,6 +6,7 @@ pandora.fs = (function() {
|
|||
downloads: {},
|
||||
enabled: false,
|
||||
},
|
||||
active,
|
||||
queue = [],
|
||||
requestedBytes = 100*1024*1024*1024; // 100GB
|
||||
|
||||
|
@ -29,29 +30,8 @@ pandora.fs = (function() {
|
|||
return pandora.getVideoURLName(id, resolution, part, track).replace('/', '::');
|
||||
}
|
||||
|
||||
that.cacheVideo = function(id, callback) {
|
||||
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);
|
||||
}
|
||||
|
||||
function startDownload(id, callback) {
|
||||
function cacheVideo(id, callback) {
|
||||
active = true;
|
||||
pandora.api.get({id: id, keys: ['parts']}, function(result) {
|
||||
var parts = result.data.parts, sizes = [];
|
||||
downloadPart(0);
|
||||
|
@ -70,8 +50,9 @@ pandora.fs = (function() {
|
|||
if (result.url) {
|
||||
if (part + 1 == parts) {
|
||||
delete that.downloads[id];
|
||||
active = false;
|
||||
if (queue.length) {
|
||||
startDownload.apply(null, queue.shift());
|
||||
cacheVideo.apply(null, queue.shift());
|
||||
}
|
||||
} else {
|
||||
downloadPart(part + 1);
|
||||
|
@ -82,6 +63,29 @@ pandora.fs = (function() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
that.cacheVideo = function(id, callback) {
|
||||
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
|
||||
};
|
||||
|
||||
(active || queue.length)
|
||||
? queue.push([id, callback])
|
||||
: cacheVideo(id, callback);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
that.removeVideo = function(id, callback) {
|
||||
|
|
Loading…
Reference in a new issue