PassThrough Changed
This commit is contained in:
parent
511c919366
commit
602927a5c7
@ -1,5 +1,5 @@
|
|||||||
import { request, request_stream } from '../YouTube/utils/request';
|
import { request, request_stream } from '../YouTube/utils/request';
|
||||||
import { PassThrough } from 'stream';
|
import { Readable } from 'stream';
|
||||||
import { IncomingMessage } from 'http';
|
import { IncomingMessage } from 'http';
|
||||||
import { StreamType } from '../YouTube/stream';
|
import { StreamType } from '../YouTube/stream';
|
||||||
import { Timer } from '../YouTube/classes/LiveStream';
|
import { Timer } from '../YouTube/classes/LiveStream';
|
||||||
@ -202,7 +202,7 @@ export class SoundCloudPlaylist {
|
|||||||
* SoundCloud Stream class
|
* SoundCloud Stream class
|
||||||
*/
|
*/
|
||||||
export class Stream {
|
export class Stream {
|
||||||
stream: PassThrough;
|
stream: Readable;
|
||||||
type: StreamType;
|
type: StreamType;
|
||||||
private url: string;
|
private url: string;
|
||||||
private downloaded_time: number;
|
private downloaded_time: number;
|
||||||
@ -212,7 +212,7 @@ export class Stream {
|
|||||||
private time: number[];
|
private time: number[];
|
||||||
private segment_urls: string[];
|
private segment_urls: string[];
|
||||||
constructor(url: string, type: StreamType = StreamType.Arbitrary) {
|
constructor(url: string, type: StreamType = StreamType.Arbitrary) {
|
||||||
this.stream = new PassThrough({ highWaterMark: 10 * 1000 * 1000 });
|
this.stream = new Readable({ highWaterMark: 10 * 1000 * 1000, read(){} });
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.downloaded_time = 0;
|
this.downloaded_time = 0;
|
||||||
@ -274,7 +274,9 @@ export class Stream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.request = stream;
|
this.request = stream;
|
||||||
stream.pipe(this.stream, { end: false });
|
stream.on('data', (c) => {
|
||||||
|
this.stream.push(c)
|
||||||
|
})
|
||||||
stream.on('end', () => {
|
stream.on('end', () => {
|
||||||
if (this.downloaded_time >= 300) return;
|
if (this.downloaded_time >= 300) return;
|
||||||
else this.loop();
|
else this.loop();
|
||||||
@ -286,7 +288,6 @@ export class Stream {
|
|||||||
|
|
||||||
private cleanup() {
|
private cleanup() {
|
||||||
this.timer.destroy();
|
this.timer.destroy();
|
||||||
this.request?.unpipe(this.stream);
|
|
||||||
this.request?.destroy();
|
this.request?.destroy();
|
||||||
this.url = '';
|
this.url = '';
|
||||||
this.downloaded_time = 0;
|
this.downloaded_time = 0;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { PassThrough } from 'stream';
|
import { Readable } from 'stream';
|
||||||
import { IncomingMessage } from 'http';
|
import { IncomingMessage } from 'http';
|
||||||
import { parseAudioFormats, StreamOptions, StreamType } from '../stream';
|
import { parseAudioFormats, StreamOptions, StreamType } from '../stream';
|
||||||
import { Proxy, request, request_stream } from '../utils/request';
|
import { Proxy, request, request_stream } from '../utils/request';
|
||||||
@ -11,7 +11,7 @@ export interface FormatInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class LiveStreaming {
|
export class LiveStreaming {
|
||||||
stream: PassThrough;
|
stream: Readable;
|
||||||
type: StreamType;
|
type: StreamType;
|
||||||
private base_url: string;
|
private base_url: string;
|
||||||
private url: string;
|
private url: string;
|
||||||
@ -23,7 +23,7 @@ export class LiveStreaming {
|
|||||||
private segments_urls: string[];
|
private segments_urls: string[];
|
||||||
private request: IncomingMessage | null;
|
private request: IncomingMessage | null;
|
||||||
constructor(dash_url: string, target_interval: number, video_url: string) {
|
constructor(dash_url: string, target_interval: number, video_url: string) {
|
||||||
this.stream = new PassThrough({ highWaterMark: 10 * 1000 * 1000 });
|
this.stream = new Readable({ highWaterMark: 10 * 1000 * 1000, read(){} });
|
||||||
this.type = StreamType.Arbitrary;
|
this.type = StreamType.Arbitrary;
|
||||||
this.url = dash_url;
|
this.url = dash_url;
|
||||||
this.base_url = '';
|
this.base_url = '';
|
||||||
@ -72,7 +72,6 @@ export class LiveStreaming {
|
|||||||
private cleanup() {
|
private cleanup() {
|
||||||
this.timer.destroy();
|
this.timer.destroy();
|
||||||
this.dash_timer.destroy();
|
this.dash_timer.destroy();
|
||||||
this.request?.unpipe(this.stream);
|
|
||||||
this.request?.destroy();
|
this.request?.destroy();
|
||||||
this.video_url = '';
|
this.video_url = '';
|
||||||
this.request = null;
|
this.request = null;
|
||||||
@ -102,7 +101,9 @@ export class LiveStreaming {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.request = stream;
|
this.request = stream;
|
||||||
stream.pipe(this.stream, { end: false });
|
stream.on('data', (c) => {
|
||||||
|
this.stream.push(c)
|
||||||
|
})
|
||||||
stream.on('end', () => {
|
stream.on('end', () => {
|
||||||
this.packet_count++;
|
this.packet_count++;
|
||||||
resolve('');
|
resolve('');
|
||||||
@ -123,7 +124,7 @@ export class LiveStreaming {
|
|||||||
* Class for YouTube Stream
|
* Class for YouTube Stream
|
||||||
*/
|
*/
|
||||||
export class Stream {
|
export class Stream {
|
||||||
stream: PassThrough;
|
stream: Readable;
|
||||||
type: StreamType;
|
type: StreamType;
|
||||||
private url: string;
|
private url: string;
|
||||||
private bytes_count: number;
|
private bytes_count: number;
|
||||||
@ -142,7 +143,7 @@ export class Stream {
|
|||||||
video_url: string,
|
video_url: string,
|
||||||
options: StreamOptions
|
options: StreamOptions
|
||||||
) {
|
) {
|
||||||
this.stream = new PassThrough({ highWaterMark: 10 * 1000 * 1000 });
|
this.stream = new Readable({ highWaterMark : 10 * 1000 * 1000, read(){} });
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.quality = options.quality as number;
|
this.quality = options.quality as number;
|
||||||
this.proxy = options.proxy || undefined;
|
this.proxy = options.proxy || undefined;
|
||||||
@ -170,7 +171,6 @@ export class Stream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private cleanup() {
|
private cleanup() {
|
||||||
this.request?.unpipe(this.stream);
|
|
||||||
this.request?.destroy();
|
this.request?.destroy();
|
||||||
this.request = null;
|
this.request = null;
|
||||||
this.url = '';
|
this.url = '';
|
||||||
@ -203,7 +203,9 @@ export class Stream {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.request = stream;
|
this.request = stream;
|
||||||
stream.pipe(this.stream, { end: false });
|
stream.on('data', (c) => {
|
||||||
|
this.stream.push(c)
|
||||||
|
})
|
||||||
|
|
||||||
stream.once('error', async (err) => {
|
stream.once('error', async (err) => {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user