Cookies Header function added
This commit is contained in:
parent
5214250eac
commit
703e36c78d
@ -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.
|
||||
```
|
||||
@ -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);
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -13,7 +13,7 @@ export enum StreamType {
|
||||
export interface StreamOptions {
|
||||
quality?: number;
|
||||
proxy?: Proxy[];
|
||||
htmldata? : boolean
|
||||
htmldata?: boolean;
|
||||
}
|
||||
|
||||
export interface InfoData {
|
||||
|
||||
@ -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('=');
|
||||
|
||||
@ -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`;
|
||||
|
||||
@ -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';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user