Merge pull request #168 from absidue/deduplicate-yt-functions

Remove some duplicate code in the YouTube functions
This commit is contained in:
Killer069 2021-11-27 14:42:47 +05:30 committed by GitHub
commit 8017dd32f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 37 deletions

View File

@ -46,35 +46,7 @@ export type YouTubeStream = Stream | LiveStream;
*/
export async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream> {
const info = await video_info(url, { proxy: options.proxy, htmldata: options.htmldata });
const final: any[] = [];
if (
info.LiveStreamData.isLive === true &&
info.LiveStreamData.dashManifestUrl !== null &&
info.video_details.durationInSec === 0
) {
return new LiveStream(
info.LiveStreamData.dashManifestUrl,
info.format[info.format.length - 1].targetDurationSec as number,
info.video_details.url
);
}
const audioFormat = parseAudioFormats(info.format);
if (typeof options.quality !== 'number') options.quality = audioFormat.length - 1;
else if (options.quality <= 0) options.quality = 0;
else if (options.quality >= audioFormat.length) options.quality = audioFormat.length - 1;
if (audioFormat.length !== 0) final.push(audioFormat[options.quality]);
else final.push(info.format[info.format.length - 1]);
let type: StreamType =
final[0].codec === 'opus' && final[0].container === 'webm' ? StreamType.WebmOpus : StreamType.Arbitrary;
return new Stream(
final[0].url,
type,
info.video_details.durationInSec,
Number(final[0].contentLength),
info.video_details.url,
options
);
return await stream_from_info(info, options);
}
/**
* Stream command for YouTube using info from video_info or decipher_info function.

View File

@ -250,14 +250,7 @@ function parseSeconds(seconds: number): string {
*/
export async function video_info(url: string, options: InfoOptions = {}): Promise<InfoData> {
const data = await video_basic_info(url, options);
if (data.LiveStreamData.isLive === true && data.LiveStreamData.dashManifestUrl !== null) {
return data;
} else if (data.format[0].signatureCipher || data.format[0].cipher) {
data.format = await format_decipher(data.format, data.html5player);
return data;
} else {
return data;
}
return await decipher_info(data);
}
/**
* Function uses data from video_basic_info and deciphers it if it contains signatures.