diff --git a/package-lock.json b/package-lock.json index b75a482..9f485ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "play-dl", - "version": "0.2.4", + "version": "0.2.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "play-dl", - "version": "0.2.4", + "version": "0.2.6", "license": "MIT", "dependencies": { "got": "^11.8.2" diff --git a/package.json b/package.json index 68994bb..ef2f0b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "play-dl", - "version": "0.2.4", + "version": "0.2.6", "description": "YouTube, SoundCloud, Spotify downloader", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/play-dl/YouTube/classes/LiveStream.ts b/play-dl/YouTube/classes/LiveStream.ts index fb4d59c..2b59de1 100644 --- a/play-dl/YouTube/classes/LiveStream.ts +++ b/play-dl/YouTube/classes/LiveStream.ts @@ -11,8 +11,8 @@ export interface FormatInterface{ export class LiveStreaming{ type : StreamType - actual_live : boolean; stream : PassThrough + private actual_live : boolean; private format : FormatInterface private interval : number private packet_count : number @@ -54,7 +54,7 @@ export class LiveStreaming{ }) })() } - this.interval = 1 + this.interval = 1 * 1000 this.timer = setTimeout(async () => { await this.looping() }, this.interval) @@ -79,7 +79,7 @@ export class LiveStreaming{ }) })() } - this.interval = 1 + this.interval = 1 * 1000 this.timer = setTimeout(async () => { await this.looping() }, this.interval) @@ -91,7 +91,7 @@ export class LiveStreaming{ } private cleanup(){ - clearInterval(this.timer as NodeJS.Timer) + clearTimeout(this.timer as NodeJS.Timer) this.segments_urls = [] this.packet_count = 0 } @@ -196,4 +196,4 @@ export class Stream { get stream(){ return this.playing_stream } -} \ No newline at end of file +} diff --git a/play-dl/YouTube/stream.ts b/play-dl/YouTube/stream.ts index b0693f6..b2c75db 100644 --- a/play-dl/YouTube/stream.ts +++ b/play-dl/YouTube/stream.ts @@ -10,7 +10,8 @@ export enum StreamType{ } interface StreamOptions { - actual_live : boolean + actual_live : boolean; + preferred_quality : "144p" | "240p" | "360p" | "480p" | "720p" | "1080p" } interface InfoData{ @@ -37,12 +38,12 @@ function parseAudioFormats(formats : any[]){ return result } -export async function stream(url : string, options : StreamOptions = { actual_live : false }): Promise{ +export async function stream(url : string, options : StreamOptions = { actual_live : false, preferred_quality : "144p" }): Promise{ let info = await video_info(url) let final: any[] = []; let type : StreamType; if(info.LiveStreamData.isLive === true && info.LiveStreamData.hlsManifestUrl !== null) { - return await live_stream(info as InfoData, options.actual_live) + return await live_stream(info as InfoData, options) } let audioFormat = parseAudioFormats(info.format) @@ -65,11 +66,11 @@ export async function stream(url : string, options : StreamOptions = { actual_li return new Stream(final[0].url, type) } -export async function stream_from_info(info : InfoData, options : StreamOptions = { actual_live : false }): Promise{ +export async function stream_from_info(info : InfoData, options : StreamOptions = { actual_live : false, preferred_quality : "144p" }): Promise{ let final: any[] = []; let type : StreamType; if(info.LiveStreamData.isLive === true && info.LiveStreamData.hlsManifestUrl !== null) { - return await live_stream(info as InfoData, options.actual_live) + return await live_stream(info as InfoData, options) } let audioFormat = parseAudioFormats(info.format) @@ -100,19 +101,19 @@ function filterFormat(formats : any[], codec : string){ return result } -async function live_stream(info : InfoData, actual_live : boolean): Promise{ +async function live_stream(info : InfoData, options : StreamOptions): Promise{ let res_144 : FormatInterface = { url : '', targetDurationSec : 0, maxDvrDurationSec : 0 } info.format.forEach((format) => { - if(format.qualityLabel === '144p') res_144 = format + if(format.qualityLabel === options.preferred_quality) res_144 = format else return }) let stream : LiveStreaming | LiveEnded if(info.video_details.duration === '0') { - stream = new LiveStreaming((res_144.url.length !== 0) ? res_144 : info.format[info.format.length - 1], actual_live) + stream = new LiveStreaming((res_144.url.length !== 0) ? res_144 : info.format[info.format.length - 1], options.actual_live) } else { stream = new LiveEnded((res_144.url.length !== 0) ? res_144 : info.format[info.format.length - 1])