mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-31 14:58:05 +00:00
Live Stream Fixes
This commit is contained in:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user