From ae476300650d42d31ad5b3f87aace299704dde7e Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Fri, 8 Oct 2021 18:33:46 +0530 Subject: [PATCH 1/4] Stream Loop issues fixed --- play-dl/YouTube/classes/LiveStream.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/play-dl/YouTube/classes/LiveStream.ts b/play-dl/YouTube/classes/LiveStream.ts index 5f31d89..0a2510d 100644 --- a/play-dl/YouTube/classes/LiveStream.ts +++ b/play-dl/YouTube/classes/LiveStream.ts @@ -177,6 +177,7 @@ export class Stream { private async loop() { if (this.stream.destroyed) { + this.timer.destroy() this.cleanup(); return; } From 0ef36affa22ef1879639f3d100d7d6b1c54de81a Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Sat, 9 Oct 2021 11:51:37 +0530 Subject: [PATCH 2/4] Memory Leak fixed --- play-dl/YouTube/classes/LiveStream.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/play-dl/YouTube/classes/LiveStream.ts b/play-dl/YouTube/classes/LiveStream.ts index 0a2510d..7fee2ae 100644 --- a/play-dl/YouTube/classes/LiveStream.ts +++ b/play-dl/YouTube/classes/LiveStream.ts @@ -157,6 +157,7 @@ export class Stream { this.loop(); }, 265); this.stream.on('close', () => { + this.timer.destroy() this.cleanup(); }); this.loop(); @@ -197,6 +198,7 @@ export class Stream { if (Number(stream.statusCode) >= 400) { this.cleanup(); await this.retry(); + this.timer.reuse() this.loop(); return; } @@ -206,6 +208,7 @@ export class Stream { stream.once('error', async (err) => { this.cleanup(); await this.retry(); + this.timer.reuse() this.loop(); }); @@ -216,6 +219,7 @@ export class Stream { stream.on('end', () => { if (end >= this.content_length) { this.timer.destroy(); + this.cleanup() } }); } From 568624efe077654f8a66abc6361229b4a8c2b08c Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Sat, 9 Oct 2021 12:05:30 +0530 Subject: [PATCH 3/4] Format issue fixed --- play-dl/YouTube/stream.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/play-dl/YouTube/stream.ts b/play-dl/YouTube/stream.ts index 674bc9c..dc551be 100644 --- a/play-dl/YouTube/stream.ts +++ b/play-dl/YouTube/stream.ts @@ -71,9 +71,10 @@ export async function stream(url: string, options: StreamOptions = {}): Promise< 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; - final.push(audioFormat[options.quality]); + if(audioFormat.length !== 0) final.push(audioFormat[options.quality]); + else final.push(info.format[info.format.length - 1]) let type: StreamType = - audioFormat[options.quality].codec === 'opus' && audioFormat[options.quality].container === 'webm' + final[0].codec === 'opus' && final[0].container === 'webm' ? StreamType.WebmOpus : StreamType.Arbitrary; return new Stream( @@ -109,9 +110,10 @@ export async function stream_from_info(info: InfoData, options: StreamOptions = 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; - final.push(audioFormat[options.quality]); + if(audioFormat.length !== 0) final.push(audioFormat[options.quality]); + else final.push(info.format[info.format.length - 1]) let type: StreamType = - audioFormat[options.quality].codec === 'opus' && audioFormat[options.quality].container === 'webm' + final[0].codec === 'opus' && final[0].container === 'webm' ? StreamType.WebmOpus : StreamType.Arbitrary; return new Stream( From e4bce76c4a33249ecd112e83863acbe6d3221d6c Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Sat, 9 Oct 2021 13:55:33 +0530 Subject: [PATCH 4/4] Cookies fixes --- play-dl/YouTube/utils/request.ts | 13 ++++++++----- play-dl/index.ts | 8 ++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/play-dl/YouTube/utils/request.ts b/play-dl/YouTube/utils/request.ts index dad639e..fb840b9 100644 --- a/play-dl/YouTube/utils/request.ts +++ b/play-dl/YouTube/utils/request.ts @@ -171,8 +171,10 @@ export async function request(url: string, options: RequestOpts = {}): Promise { x.split(';').forEach((x) => { - const [key, value] = x.split('='); - if (!value) return; + const arr = x.split('=') + if(arr.length <= 1 ) return; + const key = arr.shift()?.trim() as string + const value = arr.join('=').trim() setCookie(key, value); }); }) @@ -204,9 +206,10 @@ export async function request(url: string, options: RequestOpts = {}): Promise x.toLocaleLowerCase().startsWith('set-cookie: ')); cookies.forEach((x) => { x.toLocaleLowerCase().split('set-cookie: ')[1].split(';').forEach((y) => { - let [key, value] = y.split('='); - if (!value) - return; + const arr = y.split('=') + if(arr.length <= 1 ) return; + const key = arr.shift()?.trim() as string + const value = arr.join('=').trim() setCookie(key, value); }); }); diff --git a/play-dl/index.ts b/play-dl/index.ts index a9abe5e..49a6d2f 100644 --- a/play-dl/index.ts +++ b/play-dl/index.ts @@ -183,10 +183,10 @@ export function authorization(): void { console.log('Cookies has been added successfully.'); let cookie: Object = {}; cook.split(';').forEach((x) => { - let [ key, value ] = x.split('=') - if(!value) return; - key = key.trim() - value = value.trim() + const arr = x.split('=') + if(arr.length <= 1 ) return; + const key = arr.shift()?.trim() as string + const value = arr.join('=').trim() Object.assign(cookie, { [key] : value }) }) fs.writeFileSync('.data/youtube.data', JSON.stringify({ cookie }, undefined, 4));