mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-31 14:58:05 +00:00
Cookies update
This commit is contained in:
31
play-dl/YouTube/utils/cookie.ts
Normal file
31
play-dl/YouTube/utils/cookie.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import fs from 'fs';
|
||||
|
||||
let youtubeData: youtubeDataOptions;
|
||||
if (fs.existsSync('.data/youtube.data')) {
|
||||
youtubeData = JSON.parse(fs.readFileSync('.data/youtube.data').toString());
|
||||
}
|
||||
|
||||
interface youtubeDataOptions {
|
||||
cookie?: Object;
|
||||
}
|
||||
|
||||
export function getCookies(): undefined | string {
|
||||
let result = ''
|
||||
if(!youtubeData?.cookie) return undefined
|
||||
for (const [ key, value ] of Object.entries(youtubeData.cookie)){
|
||||
result+= `${key}=${value};`
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function setCookie(key: string, value: string): boolean {
|
||||
if (!youtubeData?.cookie) return false;
|
||||
key = key.trim()
|
||||
value = value.trim()
|
||||
Object.assign(youtubeData.cookie, { [key] : value })
|
||||
return true
|
||||
}
|
||||
|
||||
export function uploadCookie() {
|
||||
if(youtubeData) fs.writeFileSync('.data/youtube.data', JSON.stringify(youtubeData, undefined, 4));
|
||||
}
|
||||
Reference in New Issue
Block a user