forked from 0x2620/pandora
queue multiple cache requests
This commit is contained in:
parent
c0615911d2
commit
71b77f6359
1 changed files with 35 additions and 24 deletions
|
@ -6,6 +6,7 @@ pandora.fs = (function() {
|
||||||
downloads: {},
|
downloads: {},
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
|
queue = [],
|
||||||
requestedBytes = 100*1024*1024*1024; // 100GB
|
requestedBytes = 100*1024*1024*1024; // 100GB
|
||||||
|
|
||||||
if(window.webkitRequestFileSystem) {
|
if(window.webkitRequestFileSystem) {
|
||||||
|
@ -40,32 +41,42 @@ pandora.fs = (function() {
|
||||||
resolution: pandora.user.ui.videoResolution,
|
resolution: pandora.user.ui.videoResolution,
|
||||||
size: 0
|
size: 0
|
||||||
};
|
};
|
||||||
pandora.api.get({id: id, keys: ['parts']}, function(result) {
|
|
||||||
var parts = result.data.parts, sizes = [];
|
|
||||||
downloadPart(0);
|
|
||||||
|
|
||||||
function downloadPart(part) {
|
queue.length
|
||||||
that.downloadVideoURL(id, pandora.user.ui.videoResolution, part + 1, false, function(result) {
|
? queue.push([id, callback])
|
||||||
result.progress = 1/parts * (part + result.progress);
|
: startDownload(id, callback);
|
||||||
that.downloads[id].progress = result.progress;
|
|
||||||
if (result.cancel) {
|
function startDownload(id, callback) {
|
||||||
that.downloads[id].cancel = result.cancel;
|
pandora.api.get({id: id, keys: ['parts']}, function(result) {
|
||||||
}
|
var parts = result.data.parts, sizes = [];
|
||||||
if (result.total) {
|
downloadPart(0);
|
||||||
sizes[part] = result.total;
|
|
||||||
that.downloads[id].size = Ox.sum(sizes);
|
function downloadPart(part) {
|
||||||
}
|
that.downloadVideoURL(id, pandora.user.ui.videoResolution, part + 1, false, function(result) {
|
||||||
if (result.url) {
|
result.progress = 1/parts * (part + result.progress);
|
||||||
if (part + 1 == parts) {
|
that.downloads[id].progress = result.progress;
|
||||||
delete that.downloads[id];
|
if (result.cancel) {
|
||||||
} else {
|
that.downloads[id].cancel = result.cancel;
|
||||||
downloadPart(part + 1);
|
|
||||||
}
|
}
|
||||||
}
|
if (result.total) {
|
||||||
callback && callback(result);
|
sizes[part] = result.total;
|
||||||
});
|
that.downloads[id].size = Ox.sum(sizes);
|
||||||
}
|
}
|
||||||
});
|
if (result.url) {
|
||||||
|
if (part + 1 == parts) {
|
||||||
|
delete that.downloads[id];
|
||||||
|
if (queue.length) {
|
||||||
|
startDownload.apply(null, queue.shift());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
downloadPart(part + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback && callback(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
that.removeVideo = function(id, callback) {
|
that.removeVideo = function(id, callback) {
|
||||||
|
|
Loading…
Reference in a new issue