Files
play-dl-test/play-dl/token.ts

63 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-12-07 10:43:23 +05:30
import { setUserAgent } from './Request/useragent';
2021-10-12 14:09:14 +05:30
import { setSoundCloudToken } from './SoundCloud';
import { setSpotifyToken } from './Spotify';
import { setCookieToken } from './YouTube/utils/cookie';
2021-10-12 13:56:33 +05:30
interface tokenOptions {
2021-10-12 14:09:14 +05:30
spotify?: {
client_id: string;
client_secret: string;
refresh_token: string;
market: string;
};
soundcloud?: {
client_id: string;
};
youtube?: {
cookie: string;
};
2021-12-07 10:43:23 +05:30
useragent?: string[];
2021-10-12 13:56:33 +05:30
}
/**
2021-11-23 09:56:08 +05:30
* Sets
*
* i> YouTube :- cookies.
2021-11-23 09:56:08 +05:30
*
* ii> SoundCloud :- client ID.
2021-11-23 09:56:08 +05:30
*
* iii> Spotify :- client ID, client secret, refresh token, market.
2021-11-23 09:56:08 +05:30
*
2021-12-07 10:43:23 +05:30
* iv> Useragents :- array of string.
*
* locally in memory.
2021-12-08 09:47:26 +05:30
*
* Example :
2021-12-07 12:15:56 +05:30
* ```ts
* play.setToken({
* youtube : {
* cookie : "Your Cookies"
* }
* }) // YouTube Cookies
2021-12-08 09:47:26 +05:30
*
2022-01-04 15:20:38 +05:30
* await play.setToken({
* spotify : {
* client_id: 'ID',
client_secret: 'secret',
refresh_token: 'token',
market: 'US'
* }
* }) // Await this only when setting data for spotify
*
2021-12-07 12:15:56 +05:30
* play.setToken({
* useragent: ['Your User-agent']
* }) // Use this to avoid 429 errors.
* ```
* @param options {@link tokenOptions}
*/
2022-01-04 15:20:38 +05:30
export async function setToken(options: tokenOptions) {
if (options.spotify) await setSpotifyToken(options.spotify);
2021-10-12 14:09:14 +05:30
if (options.soundcloud) setSoundCloudToken(options.soundcloud);
if (options.youtube) setCookieToken(options.youtube);
2021-12-07 10:43:23 +05:30
if (options.useragent) setUserAgent(options.useragent);
2021-10-12 14:09:14 +05:30
}