Fixed bug where playlist downloads would fail and progress would not show (for playlist downloads)

This commit is contained in:
Isaac Abadi
2021-01-09 14:06:19 -05:00
parent 6ef0082563
commit db78e4ad5e
2 changed files with 28 additions and 15 deletions

View File

@@ -1144,7 +1144,12 @@ async function downloadFileByURL_exec(url, type, options, sessionID = null) {
} }
// store info in download for future use // 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']);
} else {
download['_filename'] = info['_filename'];
}
download['filesize'] = utils.getExpectedFileSize(info); download['filesize'] = utils.getExpectedFileSize(info);
download_checker = setInterval(() => checkDownloadPercent(download), 1000); download_checker = setInterval(() => checkDownloadPercent(download), 1000);
} }
@@ -1621,13 +1626,15 @@ function checkDownloadPercent(download) {
be divided by the "total expected bytes." be divided by the "total expected bytes."
*/ */
const file_id = download['file_id']; 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(utils.removeFileExtension(download['_filename'])))];
const resulting_file_size = download['filesize']; const resulting_file_size = download['filesize'];
if (!resulting_file_size) return; if (!resulting_file_size) return;
glob(`${filename}*`, (err, files) => { let sum_size = 0;
let sum_size = 0; glob(`{${fileNames.join(',')}, }*`, (err, files) => {
files.forEach(file => { files.forEach(file => {
try { try {
const file_stats = fs.statSync(file); const file_stats = fs.statSync(file);

View File

@@ -105,20 +105,26 @@ function getDownloadedThumbnail(name, type, customPath = null) {
return null; return null;
} }
function getExpectedFileSize(info_json) { function getExpectedFileSize(input_info_jsons) {
if (info_json['filesize']) { // treat single videos as arrays to have the file sizes checked/added to. makes the code cleaner
return info_json['filesize']; const info_jsons = Array.isArray(input_info_jsons) ? input_info_jsons : [input_info_jsons];
}
const formats = info_json['format_id'].split('+');
let expected_filesize = 0; let expected_filesize = 0;
formats.forEach(format_id => { info_jsons.forEach(info_json => {
if (!info_json.formats) return expected_filesize; if (info_json['filesize']) {
info_json.formats.forEach(available_format => { expected_filesize += info_json['filesize'];
if (available_format.format_id === format_id && available_format.filesize) { return;
expected_filesize += available_format.filesize; }
} const formats = info_json['format_id'].split('+');
let individual_expected_filesize = 0;
formats.forEach(format_id => {
info_json.formats.forEach(available_format => {
if (available_format.format_id === format_id && available_format.filesize) {
individual_expected_filesize += available_format.filesize;
}
});
}); });
expected_filesize += individual_expected_filesize;
}); });
return expected_filesize; return expected_filesize;