diff --git a/deemix/downloader.js b/deemix/downloader.js index 3f42280..c901622 100644 --- a/deemix/downloader.js +++ b/deemix/downloader.js @@ -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] diff --git a/deemix/types/Track.js b/deemix/types/Track.js index 0132416..83948ad 100644 --- a/deemix/types/Track.js +++ b/deemix/types/Track.js @@ -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){