Fixed possible track_token expiration issues

This commit is contained in:
RemixDev 2021-12-23 15:16:07 +01:00
parent 2d58f931b2
commit da04a94191
No known key found for this signature in database
GPG key ID: B33962B465BDB51C
2 changed files with 14 additions and 2 deletions

View file

@ -155,6 +155,8 @@ async function getPreferredBitrate(dz, track, preferredBitrate, shouldFallback,
formats = {...formats_non_360}
}
// Check and renew trackToken before starting the check
await track.checkAndRenewTrackToken(dz)
for (let i = 0; i < Object.keys(formats).length; i++){
// Check bitrates
let formatNumber = Object.keys(formats).reverse()[i]

View file

@ -4,7 +4,7 @@ const { Album } = require('./Album.js')
const { Playlist } = require('./Playlist.js')
const { Picture } = require('./Picture.js')
const { Lyrics } = require('./Lyrics.js')
const { Date } = require('./Date.js')
const { Date: dzDate } = require('./Date.js')
const { VARIOUS_ARTISTS } = require('./index.js')
const { changeCase } = require('../utils/index.js')
const { FeaturesOption } = require('../settings.js')
@ -35,7 +35,7 @@ class Track {
this.album = null
this.trackNumber = "0"
this.discNumber = "0"
this.date = new Date()
this.date = new dzDate()
this.lyrics = null
this.bpm = 0
this.contributors = {}
@ -246,6 +246,16 @@ class Track {
}
}
async checkAndRenewTrackToken(dz){
let now = new Date()
let expiration = new Date(this.trackTokenExpiration*1000)
if (now > expiration){
let newTrack = await dz.gw.get_track_with_fallback(this.id)
this.trackToken = newTrack.TRACK_TOKEN
this.trackTokenExpiration = newTrack.TRACK_TOKEN_EXPIRE
}
}
applySettings(settings){
// Check if should save the playlist as a compilation
if (settings.tags.savePlaylistAsCompilation && this.playlist){