Merge branch 'developer' of https://github.com/play-dl/play-dl into developer
This commit is contained in:
commit
7707168014
@ -63,7 +63,7 @@ if(validate(url) || validate_playlist(url)) // This will check both and if anyon
|
|||||||
```
|
```
|
||||||
|
|
||||||
### stream_from_info(info : `infoData`)
|
### stream_from_info(info : `infoData`)
|
||||||
*This is basic to create a youtube stream from a info [ from video_info function ].*
|
*This is basic to create a youtube stream from a info [ from [video_info](https://github.com/play-dl/play-dl#video_infourl--string) function ].*
|
||||||
```js
|
```js
|
||||||
let info = await video_info("url")
|
let info = await video_info("url")
|
||||||
let source = await stream_from_info(info) // This will create a stream Class which contains type and stream to be played.
|
let source = await stream_from_info(info) // This will create a stream Class which contains type and stream to be played.
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "play-dl",
|
"name": "play-dl",
|
||||||
"version": "0.7.0",
|
"version": "0.7.3",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "play-dl",
|
"name": "play-dl",
|
||||||
"version": "0.7.0",
|
"version": "0.7.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"got": "^11.8.2"
|
"got": "^11.8.2"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "play-dl",
|
"name": "play-dl",
|
||||||
"version": "0.7.0",
|
"version": "0.7.3",
|
||||||
"description": "YouTube, SoundCloud, Spotify streaming for discord.js bots",
|
"description": "YouTube, SoundCloud, Spotify streaming for discord.js bots",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
|||||||
@ -77,6 +77,9 @@ export class LiveStreaming{
|
|||||||
this.packet_count++
|
this.packet_count++
|
||||||
resolve('')
|
resolve('')
|
||||||
})
|
})
|
||||||
|
stream.once('error', (err) => {
|
||||||
|
this.stream.emit('error', err)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
@ -151,6 +154,9 @@ export class LiveEnded{
|
|||||||
this.packet_count++
|
this.packet_count++
|
||||||
resolve('')
|
resolve('')
|
||||||
})
|
})
|
||||||
|
stream.once('error', (err) => {
|
||||||
|
this.stream.emit('error', err)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
@ -198,6 +204,11 @@ export class Stream {
|
|||||||
}
|
}
|
||||||
let stream = got.stream(this.url)
|
let stream = got.stream(this.url)
|
||||||
this.request = stream
|
this.request = stream
|
||||||
|
|
||||||
|
stream.once('error', (err) => {
|
||||||
|
this.stream.emit('error', err)
|
||||||
|
})
|
||||||
|
|
||||||
stream.pipe(this.stream)
|
stream.pipe(this.stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +223,10 @@ export class Stream {
|
|||||||
this.per_sec_bytes = Math.ceil((stream.downloadProgress.total as number)/this.duration)
|
this.per_sec_bytes = Math.ceil((stream.downloadProgress.total as number)/this.duration)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
stream.once('error', (err) => {
|
||||||
|
this.stream.emit('error', err)
|
||||||
|
})
|
||||||
|
|
||||||
stream.on('data', (chunk: any) => {
|
stream.on('data', (chunk: any) => {
|
||||||
this.bytes_count += chunk.length
|
this.bytes_count += chunk.length
|
||||||
this.stream.write(chunk)
|
this.stream.write(chunk)
|
||||||
@ -244,6 +259,11 @@ export class Stream {
|
|||||||
this.bytes_count += chunk.length
|
this.bytes_count += chunk.length
|
||||||
this.stream.write(chunk)
|
this.stream.write(chunk)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
stream.once('error', (err) => {
|
||||||
|
this.stream.emit('error', err)
|
||||||
|
})
|
||||||
|
|
||||||
stream.on('data', () => {
|
stream.on('data', () => {
|
||||||
if(absolute_bytes > (this.per_sec_bytes * 300)){
|
if(absolute_bytes > (this.per_sec_bytes * 300)){
|
||||||
stream.destroy()
|
stream.destroy()
|
||||||
|
|||||||
@ -32,6 +32,8 @@ export async function video_basic_info(url : string, cookie? : string){
|
|||||||
headers : (cookie) ? { 'cookie' : cookie } : {}
|
headers : (cookie) ? { 'cookie' : cookie } : {}
|
||||||
})
|
})
|
||||||
let player_response = JSON.parse(body.split("var ytInitialPlayerResponse = ")[1].split("}};")[0] + '}}')
|
let player_response = JSON.parse(body.split("var ytInitialPlayerResponse = ")[1].split("}};")[0] + '}}')
|
||||||
|
let initial_response = JSON.parse(body.split("var ytInitialData = ")[1].split("}};")[0] + '}}')
|
||||||
|
let badge = initial_response.contents.twoColumnWatchNextResults.results.results.contents[1]?.videoSecondaryInfoRenderer?.owner?.videoOwnerRenderer?.badges && initial_response.contents.twoColumnWatchNextResults.results.results.contents[1]?.videoSecondaryInfoRenderer?.owner?.videoOwnerRenderer?.badges[0]
|
||||||
if(player_response.playabilityStatus.status === 'ERROR') throw new Error(`While getting info from url \n ${player_response.playabilityStatus.reason}`)
|
if(player_response.playabilityStatus.status === 'ERROR') throw new Error(`While getting info from url \n ${player_response.playabilityStatus.reason}`)
|
||||||
if(player_response.playabilityStatus.status === 'LOGIN_REQUIRED') throw new Error(`While getting info from url \n ${ player_response.playabilityStatus.reason || player_response.playabilityStatus.messages[0]}`)
|
if(player_response.playabilityStatus.status === 'LOGIN_REQUIRED') throw new Error(`While getting info from url \n ${ player_response.playabilityStatus.reason || player_response.playabilityStatus.messages[0]}`)
|
||||||
let html5player = 'https://www.youtube.com' + body.split('"jsUrl":"')[1].split('"')[0]
|
let html5player = 'https://www.youtube.com' + body.split('"jsUrl":"')[1].split('"')[0]
|
||||||
@ -50,7 +52,8 @@ export async function video_basic_info(url : string, cookie? : string){
|
|||||||
channel : {
|
channel : {
|
||||||
name : vid.author,
|
name : vid.author,
|
||||||
id : vid.channelId,
|
id : vid.channelId,
|
||||||
url : `https://www.youtube.com/channel/${vid.channelId}`
|
url : `https://www.youtube.com/channel/${vid.channelId}`,
|
||||||
|
verified : Boolean(badge?.metadataBadgeRenderer?.style?.toLowerCase().includes('verified'))
|
||||||
},
|
},
|
||||||
views : vid.viewCount,
|
views : vid.viewCount,
|
||||||
tags : vid.keywords,
|
tags : vid.keywords,
|
||||||
|
|||||||
@ -143,7 +143,8 @@ export function parseVideo(data?: any): Video | void {
|
|||||||
verified: Boolean(badge?.metadataBadgeRenderer?.style?.toLowerCase().includes("verified"))
|
verified: Boolean(badge?.metadataBadgeRenderer?.style?.toLowerCase().includes("verified"))
|
||||||
},
|
},
|
||||||
uploadedAt: data.videoRenderer.publishedTimeText?.simpleText ?? null,
|
uploadedAt: data.videoRenderer.publishedTimeText?.simpleText ?? null,
|
||||||
views: data.videoRenderer.viewCountText?.simpleText?.replace(/[^0-9]/g, "") ?? 0
|
views: data.videoRenderer.viewCountText?.simpleText?.replace(/[^0-9]/g, "") ?? 0,
|
||||||
|
live : data.videoRenderer.lengthText ? false : true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user