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", "name": "play-dl",
"version": "0.8.9", "version": "0.9.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "play-dl", "name": "play-dl",
"version": "0.8.9", "version": "0.9.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"got": "^11.8.2" "got": "^11.8.2"

View File

@ -1,6 +1,6 @@
{ {
"name": "play-dl", "name": "play-dl",
"version": "0.8.9", "version": "0.9.0",
"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",

View File

@ -158,17 +158,10 @@ export async function RefreshToken(): Promise<true | false>{
if(typeof response === 'number') return false if(typeof response === 'number') return false
let resp_json = JSON.parse(response.body) let resp_json = JSON.parse(response.body)
spotifyData = { spotifyData.access_token = resp_json.access_token
client_id : spotifyData.client_id, spotifyData.expires_in = Number(resp_json.expires_in)
client_secret : spotifyData.client_secret, spotifyData.expiry = Date.now() + (Number(resp_json.expires_in) * 1000)
redirect_url : spotifyData.redirect_url, spotifyData.token_type = resp_json.token_type
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
}
fs.writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4)) fs.writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4))
return true return true
} }

View File

@ -115,6 +115,7 @@ export class Stream {
private url : string private url : string
private bytes_count : number; private bytes_count : number;
private per_sec_bytes : number; private per_sec_bytes : number;
private timer : NodeJS.Timeout | null;
private content_length : number private content_length : number
private request : Request | null private request : Request | null
constructor(url : string, type : StreamType, duration : number, contentLength : number){ 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.per_sec_bytes = Math.ceil(contentLength / duration)
this.content_length = contentLength this.content_length = contentLength
this.request = null this.request = null
this.timer = null
this.stream.on('close', () => { this.stream.on('close', () => {
this.cleanup() this.cleanup()
}) })
@ -132,8 +134,10 @@ export class Stream {
} }
private cleanup(){ private cleanup(){
clearTimeout(this.timer as NodeJS.Timeout)
this.request?.unpipe(this.stream) this.request?.unpipe(this.stream)
this.request?.destroy() this.request?.destroy()
this.timer = null
this.request = null this.request = null
this.url = '' this.url = ''
this.bytes_count = 0 this.bytes_count = 0
@ -162,9 +166,9 @@ export class Stream {
this.bytes_count += chunk.length this.bytes_count += chunk.length
}) })
stream.on('end', () => { setTimeout(() => {
if(end < this.content_length) this.loop() if(end < this.content_length) this.loop()
else this.cleanup() else this.cleanup()
}) }, 280 * 1000)
} }
} }