Some fixes and some code changes
This commit is contained in:
Killer069 2021-09-09 21:54:40 +05:30 committed by GitHub
commit 1353b0ead5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 16 deletions

4
package-lock.json generated
View File

@ -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"

View File

@ -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",

View File

@ -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
}

View File

@ -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)
}
}