Stream Changed to OLD
This commit is contained in:
parent
cc891d3fac
commit
2564c16b82
@ -51,7 +51,7 @@ _This is basic to create a stream from a youtube or soundcloud url._
|
|||||||
```js
|
```js
|
||||||
let source = await stream("url") // This will create a stream Class.
|
let source = await stream("url") // This will create a stream Class.
|
||||||
|
|
||||||
let resource = createAudioResource(source, {
|
let resource = createAudioResource(source.stream, {
|
||||||
inputType : source.type
|
inputType : source.type
|
||||||
}) // This creates resource for playing
|
}) // This creates resource for playing
|
||||||
```
|
```
|
||||||
@ -66,12 +66,12 @@ _This is basic to create a stream from a info [ from [video_info](https://github
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
let source = await stream_from_info(info) // This will create a stream Class from video_info or SoundCoudTrack Class.
|
let source = await stream_from_info(info) // This will create a stream Class from video_info or SoundCoudTrack Class.
|
||||||
|
|
||||||
/* OR
|
/* OR
|
||||||
let source = await stream_from_info(info, cookie) This will create a stream Class and also give cookies if retrying.
|
let source = await stream_from_info(info, cookie) This will create a stream Class and also give cookies if retrying.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let resource = createAudioResource(source, {
|
let resource = createAudioResource(source.stream, {
|
||||||
inputType : source.type
|
inputType : source.type
|
||||||
}) // This creates resource for playing
|
}) // This creates resource for playing
|
||||||
```
|
```
|
||||||
|
|||||||
@ -25,7 +25,7 @@ client.on('messageCreate', async message => {
|
|||||||
let stream = await play.stream_from_info(so_info)
|
let stream = await play.stream_from_info(so_info)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let resource = createAudioResource(stream, {
|
let resource = createAudioResource(stream.stream, {
|
||||||
inputType : stream.type
|
inputType : stream.type
|
||||||
})
|
})
|
||||||
let player = createAudioPlayer({
|
let player = createAudioPlayer({
|
||||||
|
|||||||
@ -22,7 +22,7 @@ client.on('messageCreate', async message => {
|
|||||||
let searched = await play.search(`${sp_data.name}`, { limit : 1 }) // This will search the found track on youtube.
|
let searched = await play.search(`${sp_data.name}`, { limit : 1 }) // This will search the found track on youtube.
|
||||||
let stream = await play.stream(searched[0].url) // This will create stream from the above search
|
let stream = await play.stream(searched[0].url) // This will create stream from the above search
|
||||||
|
|
||||||
let resource = createAudioResource(stream, {
|
let resource = createAudioResource(stream.stream, {
|
||||||
inputType : stream.type
|
inputType : stream.type
|
||||||
})
|
})
|
||||||
let player = createAudioPlayer({
|
let player = createAudioPlayer({
|
||||||
|
|||||||
@ -26,7 +26,7 @@ client.on('messageCreate', async message => {
|
|||||||
let stream = await play.stream_from_info(yt_info, COOKIE)
|
let stream = await play.stream_from_info(yt_info, COOKIE)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let resource = createAudioResource(stream, {
|
let resource = createAudioResource(stream.stream, {
|
||||||
inputType : stream.type
|
inputType : stream.type
|
||||||
})
|
})
|
||||||
let player = createAudioPlayer({
|
let player = createAudioPlayer({
|
||||||
|
|||||||
@ -18,7 +18,7 @@ client.on('messageCreate', async message => {
|
|||||||
let args = message.content.split('play')[1]
|
let args = message.content.split('play')[1]
|
||||||
let yt_info = await play.search(args, { limit : 1 })
|
let yt_info = await play.search(args, { limit : 1 })
|
||||||
let stream = await play.stream(yt_info[0].url)
|
let stream = await play.stream(yt_info[0].url)
|
||||||
let resource = createAudioResource(stream, {
|
let resource = createAudioResource(stream.stream, {
|
||||||
inputType : stream.type
|
inputType : stream.type
|
||||||
})
|
})
|
||||||
let player = createAudioPlayer({
|
let player = createAudioPlayer({
|
||||||
|
|||||||
@ -25,7 +25,7 @@ client.on('messageCreate', async message => {
|
|||||||
let stream = await play.stream_from_info(yt_info)
|
let stream = await play.stream_from_info(yt_info)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let resource = createAudioResource(stream, {
|
let resource = createAudioResource(stream.stream, {
|
||||||
inputType : stream.type
|
inputType : stream.type
|
||||||
})
|
})
|
||||||
let player = createAudioPlayer({
|
let player = createAudioPlayer({
|
||||||
|
|||||||
@ -194,7 +194,8 @@ export class SoundCloudPlaylist {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Stream extends PassThrough {
|
export class Stream {
|
||||||
|
stream : PassThrough;
|
||||||
type: StreamType;
|
type: StreamType;
|
||||||
private url: string;
|
private url: string;
|
||||||
private playing_count: number;
|
private playing_count: number;
|
||||||
@ -205,7 +206,7 @@ export class Stream extends PassThrough {
|
|||||||
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) {
|
||||||
super({ highWaterMark: 10 * 1000 * 1000 });
|
this.stream = new PassThrough({ highWaterMark: 10 * 1000 * 1000 });
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.playing_count = 0;
|
this.playing_count = 0;
|
||||||
@ -215,14 +216,14 @@ export class Stream extends PassThrough {
|
|||||||
this.data_ended = false;
|
this.data_ended = false;
|
||||||
this.time = [];
|
this.time = [];
|
||||||
this.segment_urls = [];
|
this.segment_urls = [];
|
||||||
this.on('close', () => {
|
this.stream.on('close', () => {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
});
|
});
|
||||||
this.on('pause', () => {
|
this.stream.on('pause', () => {
|
||||||
this.playing_count++;
|
this.playing_count++;
|
||||||
if (this.data_ended) {
|
if (this.data_ended) {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
this.removeAllListeners('pause');
|
this.stream.removeAllListeners('pause');
|
||||||
} else if (this.playing_count === 110) {
|
} else if (this.playing_count === 110) {
|
||||||
this.playing_count = 0;
|
this.playing_count = 0;
|
||||||
this.start();
|
this.start();
|
||||||
@ -248,7 +249,7 @@ export class Stream extends PassThrough {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async start() {
|
private async start() {
|
||||||
if (this.destroyed) {
|
if (this.stream.destroyed) {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -261,7 +262,7 @@ export class Stream extends PassThrough {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async loop() {
|
private async loop() {
|
||||||
if (this.destroyed) {
|
if (this.stream.destroyed) {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -274,18 +275,18 @@ export class Stream extends PassThrough {
|
|||||||
const stream = await request_stream(this.segment_urls.shift() as string).catch((err: Error) => err);
|
const stream = await request_stream(this.segment_urls.shift() as string).catch((err: Error) => err);
|
||||||
if (stream instanceof Error) throw stream;
|
if (stream instanceof Error) throw stream;
|
||||||
|
|
||||||
stream.pipe(this, { end: false });
|
stream.pipe(this.stream, { end: false });
|
||||||
stream.on('end', () => {
|
stream.on('end', () => {
|
||||||
if (this.downloaded_time >= 300) return;
|
if (this.downloaded_time >= 300) return;
|
||||||
else this.loop();
|
else this.loop();
|
||||||
});
|
});
|
||||||
stream.once('error', (err) => {
|
stream.once('error', (err) => {
|
||||||
this.emit('error', err);
|
this.stream.emit('error', err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private cleanup() {
|
private cleanup() {
|
||||||
this.request?.unpipe(this);
|
this.request?.unpipe(this.stream);
|
||||||
this.request?.destroy();
|
this.request?.destroy();
|
||||||
this.url = '';
|
this.url = '';
|
||||||
this.playing_count = 0;
|
this.playing_count = 0;
|
||||||
|
|||||||
@ -10,7 +10,8 @@ export interface FormatInterface {
|
|||||||
maxDvrDurationSec: number;
|
maxDvrDurationSec: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LiveStreaming extends PassThrough {
|
export class LiveStreaming {
|
||||||
|
stream : PassThrough;
|
||||||
type: StreamType;
|
type: StreamType;
|
||||||
private base_url: string;
|
private base_url: string;
|
||||||
private url: string;
|
private url: string;
|
||||||
@ -22,7 +23,7 @@ export class LiveStreaming extends PassThrough {
|
|||||||
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) {
|
||||||
super({ highWaterMark: 10 * 1000 * 1000 });
|
this.stream = new PassThrough({ highWaterMark: 10 * 1000 * 1000 })
|
||||||
this.type = StreamType.Arbitrary;
|
this.type = StreamType.Arbitrary;
|
||||||
this.url = dash_url;
|
this.url = dash_url;
|
||||||
this.base_url = '';
|
this.base_url = '';
|
||||||
@ -35,7 +36,7 @@ export class LiveStreaming extends PassThrough {
|
|||||||
this.dash_timer = setTimeout(() => {
|
this.dash_timer = setTimeout(() => {
|
||||||
this.dash_updater();
|
this.dash_updater();
|
||||||
}, 1800000);
|
}, 1800000);
|
||||||
this.on('close', () => {
|
this.stream.on('close', () => {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
});
|
});
|
||||||
this.start();
|
this.start();
|
||||||
@ -71,7 +72,7 @@ export class LiveStreaming extends PassThrough {
|
|||||||
private cleanup() {
|
private cleanup() {
|
||||||
clearTimeout(this.timer as NodeJS.Timer);
|
clearTimeout(this.timer as NodeJS.Timer);
|
||||||
clearTimeout(this.dash_timer as NodeJS.Timer);
|
clearTimeout(this.dash_timer as NodeJS.Timer);
|
||||||
this.request?.unpipe(this);
|
this.request?.unpipe(this.stream);
|
||||||
this.request?.destroy();
|
this.request?.destroy();
|
||||||
this.dash_timer = null;
|
this.dash_timer = null;
|
||||||
this.video_url = '';
|
this.video_url = '';
|
||||||
@ -85,7 +86,7 @@ export class LiveStreaming extends PassThrough {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async start() {
|
private async start() {
|
||||||
if (this.destroyed) {
|
if (this.stream.destroyed) {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -99,17 +100,17 @@ export class LiveStreaming extends PassThrough {
|
|||||||
await new Promise(async (resolve, reject) => {
|
await new Promise(async (resolve, reject) => {
|
||||||
const stream = await request_stream(this.base_url + segment).catch((err: Error) => err);
|
const stream = await request_stream(this.base_url + segment).catch((err: Error) => err);
|
||||||
if (stream instanceof Error) {
|
if (stream instanceof Error) {
|
||||||
this.emit('error', stream);
|
this.stream.emit('error', stream);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.request = stream;
|
this.request = stream;
|
||||||
stream.pipe(this, { end: false });
|
stream.pipe(this.stream, { end: false });
|
||||||
stream.on('end', () => {
|
stream.on('end', () => {
|
||||||
this.packet_count++;
|
this.packet_count++;
|
||||||
resolve('');
|
resolve('');
|
||||||
});
|
});
|
||||||
stream.once('error', (err) => {
|
stream.once('error', (err) => {
|
||||||
this.emit('error', err);
|
this.stream.emit('error', err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -119,7 +120,8 @@ export class LiveStreaming extends PassThrough {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Stream extends PassThrough {
|
export class Stream {
|
||||||
|
stream : PassThrough;
|
||||||
type: StreamType;
|
type: StreamType;
|
||||||
private url: string;
|
private url: string;
|
||||||
private bytes_count: number;
|
private bytes_count: number;
|
||||||
@ -139,7 +141,7 @@ export class Stream extends PassThrough {
|
|||||||
video_url: string,
|
video_url: string,
|
||||||
cookie: string
|
cookie: string
|
||||||
) {
|
) {
|
||||||
super({ highWaterMark: 10 * 1000 * 1000 });
|
this.stream = new PassThrough({ highWaterMark: 10 * 1000 * 1000 });
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.bytes_count = 0;
|
this.bytes_count = 0;
|
||||||
@ -153,16 +155,16 @@ export class Stream extends PassThrough {
|
|||||||
this.request = null;
|
this.request = null;
|
||||||
this.data_ended = false;
|
this.data_ended = false;
|
||||||
this.playing_count = 0;
|
this.playing_count = 0;
|
||||||
this.on('close', () => {
|
this.stream.on('close', () => {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
});
|
});
|
||||||
this.on('pause', () => {
|
this.stream.on('pause', () => {
|
||||||
this.playing_count++;
|
this.playing_count++;
|
||||||
if (this.data_ended) {
|
if (this.data_ended) {
|
||||||
this.bytes_count = 0;
|
this.bytes_count = 0;
|
||||||
this.per_sec_bytes = 0;
|
this.per_sec_bytes = 0;
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
this.removeAllListeners('pause');
|
this.stream.removeAllListeners('pause');
|
||||||
} else if (this.playing_count === 280) {
|
} else if (this.playing_count === 280) {
|
||||||
this.playing_count = 0;
|
this.playing_count = 0;
|
||||||
this.loop();
|
this.loop();
|
||||||
@ -178,7 +180,7 @@ export class Stream extends PassThrough {
|
|||||||
|
|
||||||
private cleanup() {
|
private cleanup() {
|
||||||
clearInterval(this.timer as NodeJS.Timer);
|
clearInterval(this.timer as NodeJS.Timer);
|
||||||
this.request?.unpipe(this);
|
this.request?.unpipe(this.stream);
|
||||||
this.request?.destroy();
|
this.request?.destroy();
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
this.request = null;
|
this.request = null;
|
||||||
@ -186,7 +188,7 @@ export class Stream extends PassThrough {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async loop() {
|
private async loop() {
|
||||||
if (this.destroyed) {
|
if (this.stream.destroyed) {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -197,7 +199,7 @@ export class Stream extends PassThrough {
|
|||||||
}
|
}
|
||||||
}).catch((err: Error) => err);
|
}).catch((err: Error) => err);
|
||||||
if (stream instanceof Error) {
|
if (stream instanceof Error) {
|
||||||
this.emit('error', stream);
|
this.stream.emit('error', stream);
|
||||||
this.data_ended = true;
|
this.data_ended = true;
|
||||||
this.bytes_count = 0;
|
this.bytes_count = 0;
|
||||||
this.per_sec_bytes = 0;
|
this.per_sec_bytes = 0;
|
||||||
@ -216,10 +218,10 @@ export class Stream extends PassThrough {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.request = stream;
|
this.request = stream;
|
||||||
stream.pipe(this, { end: false });
|
stream.pipe(this.stream, { end: false });
|
||||||
|
|
||||||
stream.once('error', (err) => {
|
stream.once('error', (err) => {
|
||||||
this.emit('error', err);
|
this.stream.emit('error', err);
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('data', (chunk: any) => {
|
stream.on('data', (chunk: any) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user