From a994e359642b3f794651413145c80496d81eda2d Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Sun, 26 Dec 2021 15:39:46 +0530 Subject: [PATCH 01/11] 1.6.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5dbfd6d..37ee47f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "play-dl", - "version": "1.6.4", + "version": "1.6.5", "description": "YouTube, SoundCloud, Spotify, Deezer searching and streaming for discord.js bots", "main": "dist/index.js", "typings": "dist/index.d.ts", From 3f580c395801648470f1e45d1f53965d52bb038a Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Sun, 26 Dec 2021 18:01:15 +0530 Subject: [PATCH 02/11] Fixed some issues --- play-dl/YouTube/utils/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/play-dl/YouTube/utils/parser.ts b/play-dl/YouTube/utils/parser.ts index 44503ff..4b19ce9 100644 --- a/play-dl/YouTube/utils/parser.ts +++ b/play-dl/YouTube/utils/parser.ts @@ -29,7 +29,7 @@ export function ParseSearchResult(html: string, options?: ParseSearchInterface): const data = html .split('var ytInitialData = ')?.[1] ?.split(';')[0] - .split(/;\s*"(var|const|let)"/)[0]; + .split(/;(\s*)?(var|const|let)(\s*)?/)[0]; const json_data = JSON.parse(data); const results = []; const details = From b4b791e55c977603833bef4acb90bfe7b798bbca Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Sun, 26 Dec 2021 18:03:47 +0530 Subject: [PATCH 03/11] Fixed parsing issues --- play-dl/YouTube/utils/extractor.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index cc227f5..a8c5487 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -122,12 +122,12 @@ 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)"/)[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] ?.split(';')[0] - .split(/;\s*"(var|const|let)"/)[0]; + .split(/;(\s*)?(var|const|let)(\s*)?/)[0]; if (!initial_data) throw new Error('Initial Response Data is undefined.'); const player_response = JSON.parse(player_data); const initial_response = JSON.parse(initial_data); @@ -351,7 +351,7 @@ export async function playlist_info(url: string, options: PlaylistOptions = {}): body .split('var ytInitialData = ')[1] .split(';')[0] - .split(/;\s*"(var|const|let)"/)[0] + .split(/;(\s*)?(var|const|let)(\s*)?/)[0] ); if (response.alerts) { if (response.alerts[0].alertWithButtonRenderer?.type === 'INFO') { From fc17f35f21f370e5507e7ee31cf2a0e7264c47fe Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Sun, 26 Dec 2021 18:05:15 +0530 Subject: [PATCH 04/11] Fixed parsing issues --- play-dl/YouTube/utils/extractor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index a8c5487..1af053d 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -226,7 +226,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)/)[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); if (player_response.playabilityStatus.status !== 'OK') From 15bd9dc18d3e02c0dfe253dabcc9e49b19402a42 Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Sun, 26 Dec 2021 18:07:24 +0530 Subject: [PATCH 05/11] Increased agents to 10 --- play-dl/Request/useragent.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/play-dl/Request/useragent.ts b/play-dl/Request/useragent.ts index 6080354..05ee668 100644 --- a/play-dl/Request/useragent.ts +++ b/play-dl/Request/useragent.ts @@ -1,7 +1,10 @@ const useragents: string[] = [ + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36 Edg/96.0.1054.43', 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36', + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0', 'Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36.0 (KHTML, like Gecko) Chrome/61.0.0.0 Safari/537.36.0', 'Mozilla/5.0 (Windows; U; Windows NT 6.1) AppleWebKit/531.35.5 (KHTML, like Gecko) Version/4.0.3 Safari/531.35.5', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246', From 1f3e351213aedfb54265cff3f357d2dcf6d0c401 Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Sun, 26 Dec 2021 18:07:53 +0530 Subject: [PATCH 06/11] 1.6.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 37ee47f..822026a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "play-dl", - "version": "1.6.5", + "version": "1.6.6", "description": "YouTube, SoundCloud, Spotify, Deezer searching and streaming for discord.js bots", "main": "dist/index.js", "typings": "dist/index.d.ts", From a0c3287d54d5b92dd9eb8e83a09577d2baca2247 Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Sun, 26 Dec 2021 21:13:29 +0530 Subject: [PATCH 07/11] Fixed search function issues --- play-dl/YouTube/utils/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/play-dl/YouTube/utils/parser.ts b/play-dl/YouTube/utils/parser.ts index 4b19ce9..1042d88 100644 --- a/play-dl/YouTube/utils/parser.ts +++ b/play-dl/YouTube/utils/parser.ts @@ -29,7 +29,7 @@ export function ParseSearchResult(html: string, options?: ParseSearchInterface): const data = html .split('var ytInitialData = ')?.[1] ?.split(';')[0] - .split(/;(\s*)?(var|const|let)(\s*)?/)[0]; + .split(/;\s*(var|const|let)\s/)[0]; const json_data = JSON.parse(data); const results = []; const details = From 87589279f909fe705e8c0e5eed4c519cc15b5d3b Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Sun, 26 Dec 2021 21:17:39 +0530 Subject: [PATCH 08/11] Fixed regexp issues --- play-dl/YouTube/utils/extractor.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index 1af053d..e1ed5ed 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -122,12 +122,12 @@ 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] ?.split(';')[0] - .split(/;(\s*)?(var|const|let)(\s*)?/)[0]; + .split(/;\s*(var|const|let)\s/)[0]; if (!initial_data) throw new Error('Initial Response Data is undefined.'); const player_response = JSON.parse(player_data); const initial_response = JSON.parse(initial_data); @@ -226,7 +226,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); if (player_response.playabilityStatus.status !== 'OK') @@ -351,7 +351,7 @@ export async function playlist_info(url: string, options: PlaylistOptions = {}): body .split('var ytInitialData = ')[1] .split(';')[0] - .split(/;(\s*)?(var|const|let)(\s*)?/)[0] + .split(/;\s*(var|const|let)\s/)[0] ); if (response.alerts) { if (response.alerts[0].alertWithButtonRenderer?.type === 'INFO') { From 6c607f062ff9c323309d602d4753c823b1e28864 Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Sun, 26 Dec 2021 21:18:26 +0530 Subject: [PATCH 09/11] 1.6.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 822026a..4939a64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "play-dl", - "version": "1.6.6", + "version": "1.6.7", "description": "YouTube, SoundCloud, Spotify, Deezer searching and streaming for discord.js bots", "main": "dist/index.js", "typings": "dist/index.d.ts", From 770e896cc0fb79d297694ba172f543b557b8b316 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Sun, 26 Dec 2021 16:55:10 +0100 Subject: [PATCH 10/11] Simplify regular expressions --- play-dl/Deezer/index.ts | 4 ++-- play-dl/YouTube/utils/cipher.ts | 2 +- play-dl/YouTube/utils/extractor.ts | 4 ++-- play-dl/YouTube/utils/parser.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/play-dl/Deezer/index.ts b/play-dl/Deezer/index.ts index fee02e7..745d5eb 100644 --- a/play-dl/Deezer/index.ts +++ b/play-dl/Deezer/index.ts @@ -92,7 +92,7 @@ async function internalValidate(url: string): Promise { return { type: false }; } - if ((path[1] === 'track' || path[1] === 'album' || path[1] === 'playlist') && path[2].match(/^[0-9]+$/)) { + if ((path[1] === 'track' || path[1] === 'album' || path[1] === 'playlist') && path[2].match(/^\d+$/)) { return { type: path[1], id: path[2] @@ -105,7 +105,7 @@ async function internalValidate(url: string): Promise { if ( path.length === 3 && (path[1] === 'track' || path[1] === 'album' || path[1] === 'playlist') && - path[2].match(/^[0-9]+$/) + path[2].match(/^\d+$/) ) { return { type: path[1], diff --git a/play-dl/YouTube/utils/cipher.ts b/play-dl/YouTube/utils/cipher.ts index 62d1c99..84adb4c 100644 --- a/play-dl/YouTube/utils/cipher.ts +++ b/play-dl/YouTube/utils/cipher.ts @@ -9,7 +9,7 @@ interface formatOptions { s?: string; } // RegExp for various js functions -const var_js = '[a-zA-Z_\\$][a-zA-Z_0-9]*'; +const var_js = '[a-zA-Z_\\$]\\w*'; const singlequote_js = `'[^'\\\\]*(:?\\\\[\\s\\S][^'\\\\]*)*'`; const duoblequote_js = `"[^"\\\\]*(:?\\\\[\\s\\S][^"\\\\]*)*"`; const quote_js = `(?:${singlequote_js}|${duoblequote_js})`; diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index e1ed5ed..24a5ca1 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -468,12 +468,12 @@ function getNormalPlaylist(response: any, body: any): YouTubePlayList { if (!data.title.runs || !data.title.runs.length) throw new Error('Failed to Parse Playlist info.'); const author = playlist_details[1]?.playlistSidebarSecondaryInfoRenderer.videoOwner; - const views = data.stats.length === 3 ? data.stats[1].simpleText.replace(/[^0-9]/g, '') : 0; + const views = data.stats.length === 3 ? data.stats[1].simpleText.replace(/\D/g, '') : 0; const lastUpdate = data.stats .find((x: any) => 'runs' in x && x['runs'].find((y: any) => y.text.toLowerCase().includes('last update'))) ?.runs.pop()?.text ?? null; - const videosCount = data.stats[0].runs[0].text.replace(/[^0-9]/g, '') || 0; + const videosCount = data.stats[0].runs[0].text.replace(/\D/g, '') || 0; const res = new YouTubePlayList({ continuation: { diff --git a/play-dl/YouTube/utils/parser.ts b/play-dl/YouTube/utils/parser.ts index 1042d88..647a52e 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 { artist: Boolean(badge?.includes('artist')) }, uploadedAt: data.videoRenderer.publishedTimeText?.simpleText ?? null, - views: data.videoRenderer.viewCountText?.simpleText?.replace(/[^0-9]/g, '') ?? 0, + views: data.videoRenderer.viewCountText?.simpleText?.replace(/\D/g, '') ?? 0, live: durationText ? false : true }); @@ -179,7 +179,7 @@ export function parsePlaylist(data?: any): YouTubePlayList { name: channel?.text, url: `https://www.youtube.com${channel?.navigationEndpoint.commandMetadata.webCommandMetadata.url}` }, - videos: parseInt(data.playlistRenderer.videoCount.replace(/[^0-9]/g, '')) + videos: parseInt(data.playlistRenderer.videoCount.replace(/\D/g, '')) }, true ); From e1b0d14477727a3a6010ba894bf21a7ec79b07f1 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Sun, 26 Dec 2021 17:28:37 +0100 Subject: [PATCH 11/11] Improve stream retry performance by using video_stream_info --- play-dl/YouTube/classes/LiveStream.ts | 6 +++--- play-dl/YouTube/classes/SeekStream.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/play-dl/YouTube/classes/LiveStream.ts b/play-dl/YouTube/classes/LiveStream.ts index 918ef14..988991f 100644 --- a/play-dl/YouTube/classes/LiveStream.ts +++ b/play-dl/YouTube/classes/LiveStream.ts @@ -2,7 +2,7 @@ import { Readable } from 'node:stream'; import { IncomingMessage } from 'node:http'; import { parseAudioFormats, StreamOptions, StreamType } from '../stream'; import { request, request_stream } from '../../Request'; -import { video_info } from '..'; +import { video_stream_info } from '../utils/extractor'; export interface FormatInterface { url: string; @@ -98,7 +98,7 @@ export class LiveStream { * Used by dash_timer for updating dash_url every 30 minutes. */ private async dash_updater() { - const info = await video_info(this.video_url); + const info = await video_stream_info(this.video_url); if ( info.LiveStreamData.isLive === true && info.LiveStreamData.hlsManifestUrl !== null && @@ -277,7 +277,7 @@ export class Stream { * Retry if we get 404 or 403 Errors. */ private async retry() { - const info = await video_info(this.video_url); + const info = await video_stream_info(this.video_url); const audioFormat = parseAudioFormats(info.format); this.url = audioFormat[this.quality].url; } diff --git a/play-dl/YouTube/classes/SeekStream.ts b/play-dl/YouTube/classes/SeekStream.ts index 4a37f07..c87db9f 100644 --- a/play-dl/YouTube/classes/SeekStream.ts +++ b/play-dl/YouTube/classes/SeekStream.ts @@ -1,7 +1,7 @@ import { IncomingMessage } from 'http'; import { request_stream } from '../../Request'; import { parseAudioFormats, StreamOptions, StreamType } from '../stream'; -import { video_info } from '../utils'; +import { video_stream_info } from '../utils/extractor'; import { Timer } from './LiveStream'; import { WebmSeeker, WebmSeekerState } from './WebmSeeker'; @@ -137,7 +137,7 @@ export class SeekStream { * Retry if we get 404 or 403 Errors. */ private async retry() { - const info = await video_info(this.video_url); + const info = await video_stream_info(this.video_url); const audioFormat = parseAudioFormats(info.format); this.url = audioFormat[this.quality].url; }