From 602927a5c725bcc17bae9fc3fa9751d63997d430 Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Mon, 11 Oct 2021 17:29:10 +0530 Subject: [PATCH] PassThrough Changed --- play-dl/SoundCloud/classes.ts | 11 ++++++----- play-dl/YouTube/classes/LiveStream.ts | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/play-dl/SoundCloud/classes.ts b/play-dl/SoundCloud/classes.ts index f1f0398..81edce0 100644 --- a/play-dl/SoundCloud/classes.ts +++ b/play-dl/SoundCloud/classes.ts @@ -1,5 +1,5 @@ import { request, request_stream } from '../YouTube/utils/request'; -import { PassThrough } from 'stream'; +import { Readable } from 'stream'; import { IncomingMessage } from 'http'; import { StreamType } from '../YouTube/stream'; import { Timer } from '../YouTube/classes/LiveStream'; @@ -202,7 +202,7 @@ export class SoundCloudPlaylist { * SoundCloud Stream class */ export class Stream { - stream: PassThrough; + stream: Readable; type: StreamType; private url: string; private downloaded_time: number; @@ -212,7 +212,7 @@ export class Stream { private time: number[]; private segment_urls: string[]; 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.url = url; this.downloaded_time = 0; @@ -274,7 +274,9 @@ export class Stream { } this.request = stream; - stream.pipe(this.stream, { end: false }); + stream.on('data', (c) => { + this.stream.push(c) + }) stream.on('end', () => { if (this.downloaded_time >= 300) return; else this.loop(); @@ -286,7 +288,6 @@ export class Stream { private cleanup() { this.timer.destroy(); - this.request?.unpipe(this.stream); this.request?.destroy(); this.url = ''; this.downloaded_time = 0; diff --git a/play-dl/YouTube/classes/LiveStream.ts b/play-dl/YouTube/classes/LiveStream.ts index 4dc8fdd..f5e8f85 100644 --- a/play-dl/YouTube/classes/LiveStream.ts +++ b/play-dl/YouTube/classes/LiveStream.ts @@ -1,4 +1,4 @@ -import { PassThrough } from 'stream'; +import { Readable } from 'stream'; import { IncomingMessage } from 'http'; import { parseAudioFormats, StreamOptions, StreamType } from '../stream'; import { Proxy, request, request_stream } from '../utils/request'; @@ -11,7 +11,7 @@ export interface FormatInterface { } export class LiveStreaming { - stream: PassThrough; + stream: Readable; type: StreamType; private base_url: string; private url: string; @@ -23,7 +23,7 @@ export class LiveStreaming { private segments_urls: string[]; private request: IncomingMessage | null; 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.url = dash_url; this.base_url = ''; @@ -72,7 +72,6 @@ export class LiveStreaming { private cleanup() { this.timer.destroy(); this.dash_timer.destroy(); - this.request?.unpipe(this.stream); this.request?.destroy(); this.video_url = ''; this.request = null; @@ -102,7 +101,9 @@ export class LiveStreaming { return; } this.request = stream; - stream.pipe(this.stream, { end: false }); + stream.on('data', (c) => { + this.stream.push(c) + }) stream.on('end', () => { this.packet_count++; resolve(''); @@ -123,7 +124,7 @@ export class LiveStreaming { * Class for YouTube Stream */ export class Stream { - stream: PassThrough; + stream: Readable; type: StreamType; private url: string; private bytes_count: number; @@ -142,7 +143,7 @@ export class Stream { video_url: string, options: StreamOptions ) { - this.stream = new PassThrough({ highWaterMark: 10 * 1000 * 1000 }); + this.stream = new Readable({ highWaterMark : 10 * 1000 * 1000, read(){} }); this.url = url; this.quality = options.quality as number; this.proxy = options.proxy || undefined; @@ -170,7 +171,6 @@ export class Stream { } private cleanup() { - this.request?.unpipe(this.stream); this.request?.destroy(); this.request = null; this.url = ''; @@ -203,7 +203,9 @@ export class Stream { return; } this.request = stream; - stream.pipe(this.stream, { end: false }); + stream.on('data', (c) => { + this.stream.push(c) + }) stream.once('error', async (err) => { this.cleanup();