Cookies Header function added

This commit is contained in:
killer069 2021-11-01 15:32:51 +05:30
parent 5214250eac
commit 703e36c78d
7 changed files with 24 additions and 13 deletions

View File

@ -178,3 +178,13 @@ let resource = createAudioResource(source.stream, {
inputType : source.type
}) // This creates resource for playing
```
#### cookieHeaders(headersCookie : `string[]`)
_This is function to update youtube cookies when using external https module._
```js
const res = ... // You need to get response.
play.cookieHeaders(res.headers['set-cookie']) // Updates YouTube Cookies if cookies exists.
```

View File

@ -63,7 +63,7 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET'
return;
}
if (res.headers && res.headers['set-cookie'] && cookies_added) {
cookieHeaders(res.headers['set-cookie'])
cookieHeaders(res.headers['set-cookie']);
}
if (Number(res.statusCode) >= 300 && Number(res.statusCode) < 400) {
res = await https_getter(res.headers.location as string, options);
@ -89,7 +89,7 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET'
return;
}
if (res.headers && (res.headers as any)['set-cookie'] && cookies_added) {
cookieHeaders((res.headers as any)['set-cookie'])
cookieHeaders((res.headers as any)['set-cookie']);
}
if (res.statusCode >= 300 && res.statusCode < 400) {
res = await proxy_getter((res.headers as any)['location'], options.proxies, options.headers);

View File

@ -1,4 +1,4 @@
export { stream, stream_from_info, YouTubeStream } from './stream';
export * from './utils';
export { YouTube } from './search';
export { cookieHeaders } from './utils/cookie'
export { cookieHeaders } from './utils/cookie';

View File

@ -13,7 +13,7 @@ export enum StreamType {
export interface StreamOptions {
quality?: number;
proxy?: Proxy[];
htmldata? : boolean
htmldata?: boolean;
}
export interface InfoData {

View File

@ -48,6 +48,7 @@ export function setCookieToken(options: { cookie: string }) {
}
export function cookieHeaders(headCookie: string[]) {
if (!youtubeData?.cookie) return;
headCookie.forEach((x: string) => {
x.split(';').forEach((x) => {
const arr = x.split('=');

View File

@ -6,7 +6,7 @@ import { InfoData } from '../stream';
interface InfoOptions {
proxy?: Proxy[];
htmldata? : boolean
htmldata?: boolean;
}
interface PlaylistOptions {
@ -83,8 +83,7 @@ export async function video_basic_info(url: string, options: InfoOptions = {}) {
let body: string;
if (options.htmldata) {
body = url;
}
else {
} else {
if (yt_validate(url) !== 'video') throw new Error('This is not a YouTube Watch URL');
const video_id: string = extractID(url);
const new_url = `https://www.youtube.com/watch?v=${video_id}&has_verified=1`;

View File

@ -6,7 +6,8 @@ export {
yt_validate,
extractID,
YouTube,
YouTubeStream
YouTubeStream,
cookieHeaders
} from './YouTube';
export { spotify, sp_validate, refreshToken, is_expired, Spotify } from './Spotify';
export { soundcloud, so_validate, SoundCloud, SoundCloudStream, getFreeClientID } from './SoundCloud';