0.9.0
Some fixes and some code changes
This commit is contained in:
commit
1353b0ead5
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "play-dl",
|
||||
"version": "0.8.9",
|
||||
"version": "0.9.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "play-dl",
|
||||
"version": "0.8.9",
|
||||
"version": "0.9.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"got": "^11.8.2"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "play-dl",
|
||||
"version": "0.8.9",
|
||||
"version": "0.9.0",
|
||||
"description": "YouTube, SoundCloud, Spotify streaming for discord.js bots",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
|
||||
@ -158,17 +158,10 @@ export async function RefreshToken(): Promise<true | false>{
|
||||
|
||||
if(typeof response === 'number') return false
|
||||
let resp_json = JSON.parse(response.body)
|
||||
spotifyData = {
|
||||
client_id : spotifyData.client_id,
|
||||
client_secret : spotifyData.client_secret,
|
||||
redirect_url : spotifyData.redirect_url,
|
||||
access_token : resp_json.access_token,
|
||||
refresh_token : spotifyData.refresh_token,
|
||||
expires_in : Number(resp_json.expires_in),
|
||||
expiry : Date.now() + (Number(resp_json.expires_in) * 1000),
|
||||
token_type : resp_json.token_type,
|
||||
market : spotifyData.market
|
||||
}
|
||||
spotifyData.access_token = resp_json.access_token
|
||||
spotifyData.expires_in = Number(resp_json.expires_in)
|
||||
spotifyData.expiry = Date.now() + (Number(resp_json.expires_in) * 1000)
|
||||
spotifyData.token_type = resp_json.token_type
|
||||
fs.writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4))
|
||||
return true
|
||||
}
|
||||
@ -115,6 +115,7 @@ export class Stream {
|
||||
private url : string
|
||||
private bytes_count : number;
|
||||
private per_sec_bytes : number;
|
||||
private timer : NodeJS.Timeout | null;
|
||||
private content_length : number
|
||||
private request : Request | null
|
||||
constructor(url : string, type : StreamType, duration : number, contentLength : number){
|
||||
@ -125,6 +126,7 @@ export class Stream {
|
||||
this.per_sec_bytes = Math.ceil(contentLength / duration)
|
||||
this.content_length = contentLength
|
||||
this.request = null
|
||||
this.timer = null
|
||||
this.stream.on('close', () => {
|
||||
this.cleanup()
|
||||
})
|
||||
@ -132,8 +134,10 @@ export class Stream {
|
||||
}
|
||||
|
||||
private cleanup(){
|
||||
clearTimeout(this.timer as NodeJS.Timeout)
|
||||
this.request?.unpipe(this.stream)
|
||||
this.request?.destroy()
|
||||
this.timer = null
|
||||
this.request = null
|
||||
this.url = ''
|
||||
this.bytes_count = 0
|
||||
@ -162,9 +166,9 @@ export class Stream {
|
||||
this.bytes_count += chunk.length
|
||||
})
|
||||
|
||||
stream.on('end', () => {
|
||||
setTimeout(() => {
|
||||
if(end < this.content_length) this.loop()
|
||||
else this.cleanup()
|
||||
})
|
||||
}, 280 * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user