fix old ass bug

This commit is contained in:
localhost 2025-08-01 21:21:52 +03:00
parent b853814917
commit 60a6adfd63
1 changed files with 9 additions and 8 deletions

View File

@ -46,14 +46,15 @@ async function getVideoQuality(json: any, quality: string) {
const adaptiveFormats = json['streaming_data']['adaptive_formats']; const adaptiveFormats = json['streaming_data']['adaptive_formats'];
let video = adaptiveFormats.find((f: any) => f.quality_label === quality && !f.has_audio); let video = adaptiveFormats.find((f: any) => f.quality_label === quality && !f.has_audio);
// If the specified quality isn't available, find the lowest quality video if (!video) {
if (!video) { // @ts-ignore const target = parseInt(quality);
video = adaptiveFormats.filter((f: any) => !f.has_audio).reduce((prev, current) => { video = adaptiveFormats // find the quality thats closest to the one we wanted
if (!prev || parseInt(current.quality_label) < parseInt(prev.quality_label)) { .filter((f: any) => !f.has_audio && f.quality_label)
return current; .reduce((prev: any, curr: any) => {
} const currDiff = Math.abs(parseInt(curr.quality_label) - target);
return prev; const prevDiff = prev ? Math.abs(parseInt(prev.quality_label) - target) : Infinity;
}, null); return currDiff < prevDiff ? curr : prev;
}, null);
} }
return video ? video.quality_label : null; return video ? video.quality_label : null;