refactor(streamsb): improve quality sorting

This commit is contained in:
Jordaar 2023-06-16 16:14:05 +05:30
parent 7e948c60c1
commit a0bb03790a

View File

@ -100,7 +100,7 @@ registerEmbedScraper({
"[onclick^=download_video]" "[onclick^=download_video]"
); );
const dlDetails = []; let dlDetails = [];
for (const func of downloadVideoFunctions) { for (const func of downloadVideoFunctions) {
const funcContents = func.getAttribute("onclick"); const funcContents = func.getAttribute("onclick");
const regExpFunc = /download_video\('(.+?)','(.+?)','(.+?)'\)/; const regExpFunc = /download_video\('(.+?)','(.+?)','(.+?)'\)/;
@ -121,6 +121,12 @@ registerEmbedScraper({
} }
} }
dlDetails = dlDetails.sort((a, b) => {
const aQuality = qualityOrder.indexOf(a.quality.label as MWStreamQuality);
const bQuality = qualityOrder.indexOf(b.quality.label as MWStreamQuality);
return aQuality - bQuality;
});
progress(40); progress(40);
let dls = await Promise.all( let dls = await Promise.all(
@ -187,11 +193,6 @@ registerEmbedScraper({
}) })
); );
dls = dls.filter((d) => !!d.url); dls = dls.filter((d) => !!d.url);
dls = dls.sort((a, b) => {
const aQuality = qualityOrder.indexOf(a.quality);
const bQuality = qualityOrder.indexOf(b.quality);
return aQuality - bQuality;
});
progress(60); progress(60);