From 92a023e6d9919879228d114a73fb9c0759ee4f8e Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Thu, 27 Jan 2022 13:22:26 +0530 Subject: [PATCH] Added deciphering of audio only formats in decipher info. --- play-dl/YouTube/stream.ts | 2 +- play-dl/YouTube/utils/extractor.ts | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/play-dl/YouTube/stream.ts b/play-dl/YouTube/stream.ts index d0b4e51..f87efd5 100644 --- a/play-dl/YouTube/stream.ts +++ b/play-dl/YouTube/stream.ts @@ -63,7 +63,7 @@ export async function stream_from_info( info: InfoData | StreamInfoData, options: StreamOptions = {} ): Promise { - if (!info.format || info.format.length === 0) + if (info.format.length === 0) throw new Error('Upcoming and premiere videos that are not currently live cannot be streamed.'); const final: any[] = []; diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index 8e5bf9d..157aff4 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -4,6 +4,7 @@ import { YouTubeVideo } from '../classes/Video'; import { YouTubePlayList } from '../classes/Playlist'; import { InfoData, StreamInfoData } from './constants'; import { URL, URLSearchParams } from 'node:url'; +import { parseAudioFormats } from '../stream'; interface InfoOptions { htmldata?: boolean; @@ -378,12 +379,15 @@ export async function video_stream_info(url: string, options: InfoOptions = {}): dashManifestUrl: player_response.streamingData?.dashManifestUrl ?? null, hlsManifestUrl: player_response.streamingData?.hlsManifestUrl ?? null }; - return await decipher_info({ - LiveStreamData, - html5player, - format, - video_details - }); + return await decipher_info( + { + LiveStreamData, + html5player, + format, + video_details + }, + true + ); } /** * Function to convert seconds to [hour : minutes : seconds] format @@ -427,9 +431,13 @@ export async function video_info(url: string, options: InfoOptions = {}): Promis /** * Function uses data from video_basic_info and deciphers it if it contains signatures. * @param data Data - {@link InfoData} + * @param audio_only `boolean` - To decipher only audio formats only. * @returns Deciphered Video Info {@link InfoData} */ -export async function decipher_info(data: T): Promise { +export async function decipher_info( + data: T, + audio_only: boolean = false +): Promise { if ( data.LiveStreamData.isLive === true && data.LiveStreamData.dashManifestUrl !== null && @@ -437,11 +445,10 @@ export async function decipher_info(data: T ) { return data; } else if (data.format.length > 0 && (data.format[0].signatureCipher || data.format[0].cipher)) { + if (audio_only) data.format = parseAudioFormats(data.format); data.format = await format_decipher(data.format, data.html5player); return data; - } else { - return data; - } + } else return data; } /** * Gets YouTube playlist info from a playlist url.