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] 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));