Live Stream Fixes
This commit is contained in:
parent
f8d72f85d3
commit
849a0f7100
4
package-lock.json
generated
4
package-lock.json
generated
@ -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"
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Stream | LiveStreaming | LiveEnded>{
|
||||
export async function stream(url : string, options : StreamOptions = { actual_live : false, preferred_quality : "144p" }): Promise<Stream | LiveStreaming | LiveEnded>{
|
||||
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<Stream | LiveStreaming | LiveEnded>{
|
||||
export async function stream_from_info(info : InfoData, options : StreamOptions = { actual_live : false, preferred_quality : "144p" }): Promise<Stream | LiveStreaming | LiveEnded>{
|
||||
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<LiveStreaming | LiveEnded>{
|
||||
async function live_stream(info : InfoData, options : StreamOptions): Promise<LiveStreaming | LiveEnded>{
|
||||
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])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user