diff --git a/package-lock.json b/package-lock.json index e50cfeb..b2f357c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "typedoc": "^0.22.11", "typedoc-plugin-extras": "^2.2.1", "typedoc-plugin-missing-exports": "^0.22.4", - "typescript": "^4.5.5" + "typescript": "^4.7.2" }, "engines": { "node": ">=16.0.0" @@ -1460,9 +1460,9 @@ } }, "node_modules/typescript": { - "version": "4.6.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz", - "integrity": "sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==", + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.2.tgz", + "integrity": "sha512-Mamb1iX2FDUpcTRzltPxgWMKy3fhg0TN378ylbktPGPK/99KbDtMQ4W1hwgsbPAsG3a0xKa1vmw4VKZQbkvz5A==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -2454,9 +2454,9 @@ "requires": {} }, "typescript": { - "version": "4.6.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz", - "integrity": "sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==", + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.2.tgz", + "integrity": "sha512-Mamb1iX2FDUpcTRzltPxgWMKy3fhg0TN378ylbktPGPK/99KbDtMQ4W1hwgsbPAsG3a0xKa1vmw4VKZQbkvz5A==", "dev": true }, "vscode-oniguruma": { diff --git a/package.json b/package.json index 6f9fd26..9caec9e 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "typedoc": "^0.22.11", "typedoc-plugin-extras": "^2.2.1", "typedoc-plugin-missing-exports": "^0.22.4", - "typescript": "^4.5.5" + "typescript": "^4.7.2" }, "dependencies": { "play-audio": "^0.5.2" diff --git a/play-dl/YouTube/classes/SeekStream.ts b/play-dl/YouTube/classes/SeekStream.ts index 8e86be1..58df9fd 100644 --- a/play-dl/YouTube/classes/SeekStream.ts +++ b/play-dl/YouTube/classes/SeekStream.ts @@ -71,6 +71,7 @@ export class SeekStream { duration: number, headerLength: number, contentLength: number, + bitrate: number, video_url: string, options: StreamOptions ) { @@ -83,7 +84,7 @@ export class SeekStream { this.type = StreamType.Opus; this.bytes_count = 0; this.video_url = video_url; - this.per_sec_bytes = Math.ceil(contentLength / duration); + this.per_sec_bytes = bitrate ? Math.ceil(bitrate / 8) : Math.ceil(contentLength / duration); this.header_length = headerLength; this.content_length = contentLength; this.request = null; diff --git a/play-dl/YouTube/stream.ts b/play-dl/YouTube/stream.ts index b9fdfd0..46d6b42 100644 --- a/play-dl/YouTube/stream.ts +++ b/play-dl/YouTube/stream.ts @@ -65,6 +65,8 @@ export async function stream_from_info( ): Promise { if (info.format.length === 0) throw new Error('Upcoming and premiere videos that are not currently live cannot be streamed.'); + if (options.quality && !Number.isInteger(options.quality)) + throw new Error("Quality must be set to an integer.") const final: any[] = []; if ( @@ -99,6 +101,7 @@ export async function stream_from_info( info.video_details.durationInSec, final[0].indexRange.end, Number(final[0].contentLength), + Number(final[0].bitrate), info.video_details.url, options ); diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index 5512301..a11216e 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -151,7 +151,7 @@ export async function video_basic_info(url: string, options: InfoOptions = {}): const player_data = body .split('var ytInitialPlayerResponse = ')?.[1] ?.split(';')[0] - .split(/;\s*(var|const|let)\s/)[0]; + .split(/(?<=}}});\s*(var|const|let)\s/)[0]; if (!player_data) throw new Error('Initial Player Response Data is undefined.'); const initial_data = body .split('var ytInitialData = ')?.[1] @@ -349,7 +349,7 @@ export async function video_stream_info(url: string, options: InfoOptions = {}): const player_data = body .split('var ytInitialPlayerResponse = ')?.[1] ?.split(';')[0] - .split(/;\s*(var|const|let)\s/)[0]; + .split(/(?<=}}});\s*(var|const|let)\s/)[0]; if (!player_data) throw new Error('Initial Player Response Data is undefined.'); const player_response = JSON.parse(player_data); let upcoming = false; diff --git a/play-dl/YouTube/utils/parser.ts b/play-dl/YouTube/utils/parser.ts index 8515b4f..0f1a922 100644 --- a/play-dl/YouTube/utils/parser.ts +++ b/play-dl/YouTube/utils/parser.ts @@ -146,7 +146,7 @@ export function parseVideo(data?: any): YouTubeVideo { id: data.videoRenderer.videoId, url: `https://www.youtube.com/watch?v=${data.videoRenderer.videoId}`, title: data.videoRenderer.title.runs[0].text, - description: data.videoRenderer.detailedMetadataSnippets?.[0].snippetText.runs.length + description: data.videoRenderer.detailedMetadataSnippets?.[0].snippetText.runs?.length ? data.videoRenderer.detailedMetadataSnippets[0].snippetText.runs.map((run: any) => run.text).join('') : '', duration: durationText ? parseDuration(durationText.simpleText) : 0,