mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-31 14:58:05 +00:00
SetToken function added
This commit is contained in:
@@ -3,10 +3,12 @@ import fs from 'fs';
|
||||
let youtubeData: youtubeDataOptions;
|
||||
if (fs.existsSync('.data/youtube.data')) {
|
||||
youtubeData = JSON.parse(fs.readFileSync('.data/youtube.data').toString());
|
||||
youtubeData.file = true
|
||||
}
|
||||
|
||||
interface youtubeDataOptions {
|
||||
cookie?: Object;
|
||||
file? : boolean;
|
||||
}
|
||||
|
||||
export function getCookies(): undefined | string {
|
||||
@@ -27,5 +29,19 @@ export function setCookie(key: string, value: string): boolean {
|
||||
}
|
||||
|
||||
export function uploadCookie() {
|
||||
if (youtubeData) fs.writeFileSync('.data/youtube.data', JSON.stringify(youtubeData, undefined, 4));
|
||||
if (youtubeData.cookie && youtubeData.file) fs.writeFileSync('.data/youtube.data', JSON.stringify(youtubeData, undefined, 4));
|
||||
}
|
||||
|
||||
export function setCookieToken(options : { cookie : string }){
|
||||
let cook = options.cookie
|
||||
let cookie: Object = {};
|
||||
cook.split(';').forEach((x) => {
|
||||
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 });
|
||||
});
|
||||
youtubeData = { cookie }
|
||||
youtubeData.file = false
|
||||
}
|
||||
Reference in New Issue
Block a user