commit
1c78dcf164
@ -157,6 +157,7 @@ export class Stream {
|
||||
this.loop();
|
||||
}, 265);
|
||||
this.stream.on('close', () => {
|
||||
this.timer.destroy()
|
||||
this.cleanup();
|
||||
});
|
||||
this.loop();
|
||||
@ -177,6 +178,7 @@ export class Stream {
|
||||
|
||||
private async loop() {
|
||||
if (this.stream.destroyed) {
|
||||
this.timer.destroy()
|
||||
this.cleanup();
|
||||
return;
|
||||
}
|
||||
@ -196,6 +198,7 @@ export class Stream {
|
||||
if (Number(stream.statusCode) >= 400) {
|
||||
this.cleanup();
|
||||
await this.retry();
|
||||
this.timer.reuse()
|
||||
this.loop();
|
||||
return;
|
||||
}
|
||||
@ -205,6 +208,7 @@ export class Stream {
|
||||
stream.once('error', async (err) => {
|
||||
this.cleanup();
|
||||
await this.retry();
|
||||
this.timer.reuse()
|
||||
this.loop();
|
||||
});
|
||||
|
||||
@ -215,6 +219,7 @@ export class Stream {
|
||||
stream.on('end', () => {
|
||||
if (end >= this.content_length) {
|
||||
this.timer.destroy();
|
||||
this.cleanup()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -71,9 +71,10 @@ export async function stream(url: string, options: StreamOptions = {}): Promise<
|
||||
if (typeof options.quality !== 'number') options.quality = audioFormat.length - 1;
|
||||
else if (options.quality <= 0) options.quality = 0;
|
||||
else if (options.quality >= audioFormat.length) options.quality = audioFormat.length - 1;
|
||||
final.push(audioFormat[options.quality]);
|
||||
if(audioFormat.length !== 0) final.push(audioFormat[options.quality]);
|
||||
else final.push(info.format[info.format.length - 1])
|
||||
let type: StreamType =
|
||||
audioFormat[options.quality].codec === 'opus' && audioFormat[options.quality].container === 'webm'
|
||||
final[0].codec === 'opus' && final[0].container === 'webm'
|
||||
? StreamType.WebmOpus
|
||||
: StreamType.Arbitrary;
|
||||
return new Stream(
|
||||
@ -109,9 +110,10 @@ export async function stream_from_info(info: InfoData, options: StreamOptions =
|
||||
if (typeof options.quality !== 'number') options.quality = audioFormat.length - 1;
|
||||
else if (options.quality <= 0) options.quality = 0;
|
||||
else if (options.quality >= audioFormat.length) options.quality = audioFormat.length - 1;
|
||||
final.push(audioFormat[options.quality]);
|
||||
if(audioFormat.length !== 0) final.push(audioFormat[options.quality]);
|
||||
else final.push(info.format[info.format.length - 1])
|
||||
let type: StreamType =
|
||||
audioFormat[options.quality].codec === 'opus' && audioFormat[options.quality].container === 'webm'
|
||||
final[0].codec === 'opus' && final[0].container === 'webm'
|
||||
? StreamType.WebmOpus
|
||||
: StreamType.Arbitrary;
|
||||
return new Stream(
|
||||
|
||||
@ -171,8 +171,10 @@ export async function request(url: string, options: RequestOpts = {}): Promise<s
|
||||
if(res.headers && res.headers['set-cookie'] && cookies_added){
|
||||
res.headers['set-cookie'].forEach((x) => {
|
||||
x.split(';').forEach((x) => {
|
||||
const [key, value] = x.split('=');
|
||||
if (!value) return;
|
||||
const arr = x.split('=')
|
||||
if(arr.length <= 1 ) return;
|
||||
const key = arr.shift()?.trim() as string
|
||||
const value = arr.join('=').trim()
|
||||
setCookie(key, value);
|
||||
});
|
||||
})
|
||||
@ -204,9 +206,10 @@ export async function request(url: string, options: RequestOpts = {}): Promise<s
|
||||
let cookies = res.head.filter((x) => x.toLocaleLowerCase().startsWith('set-cookie: '));
|
||||
cookies.forEach((x) => {
|
||||
x.toLocaleLowerCase().split('set-cookie: ')[1].split(';').forEach((y) => {
|
||||
let [key, value] = y.split('=');
|
||||
if (!value)
|
||||
return;
|
||||
const arr = y.split('=')
|
||||
if(arr.length <= 1 ) return;
|
||||
const key = arr.shift()?.trim() as string
|
||||
const value = arr.join('=').trim()
|
||||
setCookie(key, value);
|
||||
});
|
||||
});
|
||||
|
||||
@ -183,10 +183,10 @@ export function authorization(): void {
|
||||
console.log('Cookies has been added successfully.');
|
||||
let cookie: Object = {};
|
||||
cook.split(';').forEach((x) => {
|
||||
let [ key, value ] = x.split('=')
|
||||
if(!value) return;
|
||||
key = key.trim()
|
||||
value = value.trim()
|
||||
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 })
|
||||
})
|
||||
fs.writeFileSync('.data/youtube.data', JSON.stringify({ cookie }, undefined, 4));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user