Fixes bug where playlists could not have download progress tracked

- downloads are now treated as playlists for cleaner logic
This commit is contained in:
Isaac Abadi
2020-09-20 23:01:43 -04:00
parent 8fdc231f08
commit daca715d1b
2 changed files with 30 additions and 16 deletions

View File

@@ -1159,7 +1159,10 @@ async function downloadFileByURL_exec(url, type, options, sessionID = null) {
return;
} else {
// store info in download for future use
download['_filename'] = info['_filename'];
if (Array.isArray(info)) {
download['fileNames'] = [];
for (let info_obj of info) download['fileNames'].push(info_obj['_filename']);
}
download['filesize'] = utils.getExpectedFileSize(info);
}
@@ -1613,12 +1616,15 @@ function checkDownloadPercent(download) {
Any file that starts with <video title> will be counted as part of the "bytes downloaded", which will
be divided by the "total expected bytes."
*/
const file_id = download['file_id'];
const filename = path.format(path.parse(download['_filename'].substring(0, download['_filename'].length-4)));
// assume it's a playlist for logic reasons
const fileNames = Array.isArray(download['fileNames']) ? download['fileNames']
: [path.format(path.parse(download['_filename'].substring(0, download['_filename'].length-4)))];
const resulting_file_size = download['filesize'];
glob(`${filename}*`, (err, files) => {
let sum_size = 0;
let sum_size = 0;
let glob_str = '';
glob(`{${fileNames.join(',')}, }*`, (err, files) => {
files.forEach(file => {
try {
const file_stats = fs.statSync(file);