diff --git a/deemix/downloader.js b/deemix/downloader.js index e5b7694..4e5ec29 100644 --- a/deemix/downloader.js +++ b/deemix/downloader.js @@ -70,7 +70,7 @@ async function downloadImage(url, path, overwrite = OverwriteOption.DONT_OVERWRI return path } -async function getPreferredBitrate(track, bitrate, shouldFallback, currentUser, uuid, listener){ +async function getPreferredBitrate(dz, track, bitrate, shouldFallback, currentUser, uuid, listener){ bitrate = parseInt(bitrate) if (track.localTrack) { return TrackFormats.LOCAL } @@ -100,8 +100,11 @@ async function getPreferredBitrate(track, bitrate, shouldFallback, currentUser, async function testBitrate(track, formatNumber, formatName){ let request try { - if (!track.urls[formatName]) - track.urls[formatName] = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, formatNumber) + if (!track.urls[formatName]){ + let url = await dz.get_track_url(track.trackToken, formatName) + if (!url) url = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, formatNumber) + track.urls[formatName] = url + } request = got.get( track.urls[formatName], { headers: {'User-Agent': USER_AGENT_HEADER}, timeout: 30000 } @@ -281,6 +284,7 @@ class Downloader { let selectedFormat try{ selectedFormat = await getPreferredBitrate( + this.dz, track, this.bitrate, this.settings.fallbackBitrate, @@ -425,8 +429,11 @@ class Downloader { // Download the track if (!trackAlreadyDownloaded || this.settings.overwriteFile == OverwriteOption.OVERWRITE){ - if (!track.urls[formatsName[track.bitrate]]) - track.urls[formatsName[track.bitrate]] = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, track.bitrate) + if (!track.urls[formatsName[track.bitrate]]){ + let url = await this.dz.get_track_url(track.trackToken, formatsName[track.bitrate]) + if (!url) url = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, track.bitrate) + track.urls[formatsName[track.bitrate]] = url + } track.downloadURL = track.urls[formatsName[track.bitrate]] let stream = fs.createWriteStream(writepath) try { @@ -496,7 +503,6 @@ class Downloader { this.warn(itemData, e.errid, 'fallback') let newTrack = await this.dz.gw.get_track_with_fallback(track.fallbackID) track.parseEssentialData(newTrack) - await track.retriveTrackURLs(this.dz) await track.retriveFilesizes(this.dz) return await this.downloadWrapper(extraData, track) } @@ -506,7 +512,6 @@ class Downloader { if (searchedID != "0"){ let newTrack = await this.dz.gw.get_track_with_fallback(searchedID) track.parseEssentialData(newTrack) - await track.retriveTrackURLs(this.dz) await track.retriveFilesizes(this.dz) track.searched = true if (this.listener) this.listener.send('queueUpdate', { diff --git a/deemix/types/Track.js b/deemix/types/Track.js index 692fdeb..01165fe 100644 --- a/deemix/types/Track.js +++ b/deemix/types/Track.js @@ -70,6 +70,7 @@ class Track { this.fallbackID = trackAPI_gw.FALLBACK.SNG_ID } this.localTrack = parseInt(this.id) < 0 + this.urls = {} } async retriveFilesizes(dz){ @@ -116,7 +117,6 @@ class Track { } this.parseEssentialData(trackAPI_gw, trackAPI) - this.retriveTrackURLs(dz) if (this.localTrack){ this.parseLocalTrackData(trackAPI_gw) @@ -259,14 +259,6 @@ class Track { }); } - async retriveTrackURLs(dz){ - let urls = await dz.get_tracks_urls(this.trackToken) - this.urls = {} - urls[0].media.forEach(url => { - this.urls[url.format] = url.sources[0].url - }) - } - removeDuplicateArtists(){ [this.artist, this.artists] = removeDuplicateArtists(this.artist, this.artists) } diff --git a/package.json b/package.json index 9182127..528a43d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "dependencies": { "async": "^3.2.0", "crypto": "^1.0.1", - "deezer-js": "^1.0.1", + "deezer-js": "^1.0.2", "got": "^11.8.2", "metaflac-js2": "^1.0.7", "spotify-web-api-node": "^5.0.2" diff --git a/yarn.lock b/yarn.lock index 192a969..7f02cd6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -370,10 +370,10 @@ deepmerge@^4.0.0: resolved "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz" integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== -deezer-js@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/deezer-js/-/deezer-js-1.0.1.tgz#97c3d3c7e84c333a331ecae6aa41d3270e3d4390" - integrity sha512-nD6E2+txyiAd9QnIY7anvzhiEH8myIAP8guIRJorCW/shkO6pBWdyXvHvjrf8mrWJGpL1T00qoe81uFPOQez2A== +deezer-js@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/deezer-js/-/deezer-js-1.0.2.tgz#fc0a7e0ef683588cfdfbdf3b6e6869bee5642acd" + integrity sha512-vvwu8KmY52q9pEvEW671jxNXLP00bFQ0EkCYeD6cOj9tsZAxAzReHktrJcZAty7N5BwCw/cGnbixtq87A4O2/Q== dependencies: got "^11.8.2" tough-cookie "^4.0.0"