fix old ass bug
This commit is contained in:
		
							parent
							
								
									b853814917
								
							
						
					
					
						commit
						60a6adfd63
					
				| 
						 | 
					@ -46,13 +46,14 @@ 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;
 | 
				
			||||||
 | 
					        return currDiff < prevDiff ? curr : prev;
 | 
				
			||||||
      }, null);
 | 
					      }, null);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue