404 Error Fixed
This commit is contained in:
parent
7b1f082c27
commit
7f68addb6f
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "play-dl",
|
||||
"version": "0.6.4",
|
||||
"version": "0.6.9",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "play-dl",
|
||||
"version": "0.6.4",
|
||||
"version": "0.6.9",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"got": "^11.8.2"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "play-dl",
|
||||
"version": "0.6.4",
|
||||
"version": "0.6.9",
|
||||
"description": "YouTube, SoundCloud, Spotify streaming for discord.js bots",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { PassThrough } from 'stream'
|
||||
import got from 'got'
|
||||
import { StreamType } from '../stream';
|
||||
import { Socket } from 'net'
|
||||
|
||||
export interface FormatInterface{
|
||||
url : string;
|
||||
@ -17,7 +16,6 @@ export class LiveStreaming{
|
||||
private interval : number
|
||||
private packet_count : number
|
||||
private timer : NodeJS.Timer | null
|
||||
private socket : Socket | null
|
||||
private segments_urls : string[]
|
||||
constructor(dash_url : string, target_interval : number){
|
||||
this.type = StreamType.Arbitrary
|
||||
@ -27,7 +25,6 @@ export class LiveStreaming{
|
||||
this.segments_urls = []
|
||||
this.packet_count = 0
|
||||
this.timer = null
|
||||
this.socket = null
|
||||
this.interval = target_interval * 1000 || 0
|
||||
this.stream.on('close', () => {
|
||||
this.cleanup()
|
||||
@ -47,8 +44,6 @@ export class LiveStreaming{
|
||||
|
||||
private cleanup(){
|
||||
clearTimeout(this.timer as NodeJS.Timer)
|
||||
this.socket?.destroy()
|
||||
this.socket = null
|
||||
this.timer = null
|
||||
this.url = ''
|
||||
this.base_url = ''
|
||||
@ -92,7 +87,6 @@ export class LiveEnded{
|
||||
private base_url : string;
|
||||
private packet_count : number
|
||||
private segments_urls : string[]
|
||||
private socket : Socket | null
|
||||
constructor(dash_url : string){
|
||||
this.type = StreamType.Arbitrary
|
||||
this.url = dash_url
|
||||
@ -100,7 +94,6 @@ export class LiveEnded{
|
||||
this.stream = new PassThrough({ highWaterMark : 10 * 1000 * 1000 })
|
||||
this.segments_urls = []
|
||||
this.packet_count = 0
|
||||
this.socket = null
|
||||
this.stream.on('close', () => {
|
||||
this.cleanup()
|
||||
})
|
||||
@ -118,8 +111,6 @@ export class LiveEnded{
|
||||
}
|
||||
|
||||
private cleanup(){
|
||||
this.socket?.destroy()
|
||||
this.socket = null
|
||||
this.url = ''
|
||||
this.base_url = ''
|
||||
this.segments_urls = []
|
||||
@ -163,7 +154,6 @@ export class Stream {
|
||||
private per_sec_bytes : number;
|
||||
private duration : number;
|
||||
private timer : NodeJS.Timer | null
|
||||
private socket : Socket | null
|
||||
constructor(url : string, type : StreamType, duration : number){
|
||||
this.url = url
|
||||
this.type = type
|
||||
@ -171,14 +161,12 @@ export class Stream {
|
||||
this.bytes_count = 0
|
||||
this.per_sec_bytes = 0
|
||||
this.timer = null
|
||||
this.duration = duration
|
||||
this.socket = null;
|
||||
this.duration = duration;
|
||||
(duration > 300) ? this.loop_start() : this.normal_start()
|
||||
}
|
||||
|
||||
private cleanup(){
|
||||
clearTimeout(this.timer as NodeJS.Timer)
|
||||
this.socket?.destroy()
|
||||
this.timer = null
|
||||
this.url = ''
|
||||
this.bytes_count = 0
|
||||
@ -191,7 +179,6 @@ export class Stream {
|
||||
return
|
||||
}
|
||||
let stream = got.stream(this.url)
|
||||
this.socket = stream.socket as Socket
|
||||
stream.pipe(this.stream)
|
||||
}
|
||||
|
||||
@ -209,10 +196,8 @@ export class Stream {
|
||||
this.bytes_count += chunk.length
|
||||
this.stream.write(chunk)
|
||||
})
|
||||
this.socket = stream.socket as Socket
|
||||
stream.on('data', () => {
|
||||
if(this.bytes_count > (this.per_sec_bytes * 300)){
|
||||
this.socket?.destroy()
|
||||
stream.destroy()
|
||||
}
|
||||
})
|
||||
@ -239,10 +224,8 @@ export class Stream {
|
||||
this.bytes_count += chunk.length
|
||||
this.stream.write(chunk)
|
||||
})
|
||||
this.socket = stream.socket as Socket
|
||||
stream.on('data', () => {
|
||||
if(absolute_bytes > (this.per_sec_bytes * 300)){
|
||||
this.socket?.destroy()
|
||||
stream.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import got from "got/dist/source"
|
||||
import { video_info } from "."
|
||||
import { LiveEnded, LiveStreaming, Stream } from "./classes/LiveStream"
|
||||
|
||||
@ -34,13 +35,20 @@ function parseAudioFormats(formats : any[]){
|
||||
return result
|
||||
}
|
||||
|
||||
export async function stream(url : string): Promise<Stream | LiveStreaming | LiveEnded>{
|
||||
export async function stream(url : string, error_check : boolean = false): 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 live_stream(info as InfoData)
|
||||
}
|
||||
|
||||
if(error_check){
|
||||
let response = await got(info.video_details.url)
|
||||
if(response.statusCode >= 400){
|
||||
return await stream(info.video_details.url, true)
|
||||
}
|
||||
}
|
||||
|
||||
let audioFormat = parseAudioFormats(info.format)
|
||||
let opusFormats = filterFormat(audioFormat, "opus")
|
||||
@ -62,13 +70,20 @@ export async function stream(url : string): Promise<Stream | LiveStreaming | Liv
|
||||
return new Stream(final[0].url, type, info.video_details.durationInSec)
|
||||
}
|
||||
|
||||
export function stream_from_info(info : InfoData): Stream | LiveStreaming | LiveEnded{
|
||||
export async function stream_from_info(info : InfoData, error_check : boolean = false): Promise<Stream | LiveStreaming | LiveEnded>{
|
||||
let final: any[] = [];
|
||||
let type : StreamType;
|
||||
if(info.LiveStreamData.isLive === true && info.LiveStreamData.hlsManifestUrl !== null) {
|
||||
return live_stream(info as InfoData)
|
||||
}
|
||||
|
||||
if(error_check){
|
||||
let response = await got(info.video_details.url)
|
||||
if(response.statusCode >= 400){
|
||||
return await stream(info.video_details.url, true)
|
||||
}
|
||||
}
|
||||
|
||||
let audioFormat = parseAudioFormats(info.format)
|
||||
let opusFormats = filterFormat(audioFormat, "opus")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user