Added support for deezer-js 1.0.2

This commit is contained in:
RemixDev 2021-07-25 13:11:23 +02:00
parent 772087cc45
commit 4c935fa2e3
4 changed files with 18 additions and 21 deletions

View file

@ -70,7 +70,7 @@ async function downloadImage(url, path, overwrite = OverwriteOption.DONT_OVERWRI
return path return path
} }
async function getPreferredBitrate(track, bitrate, shouldFallback, currentUser, uuid, listener){ async function getPreferredBitrate(dz, track, bitrate, shouldFallback, currentUser, uuid, listener){
bitrate = parseInt(bitrate) bitrate = parseInt(bitrate)
if (track.localTrack) { return TrackFormats.LOCAL } if (track.localTrack) { return TrackFormats.LOCAL }
@ -100,8 +100,11 @@ async function getPreferredBitrate(track, bitrate, shouldFallback, currentUser,
async function testBitrate(track, formatNumber, formatName){ async function testBitrate(track, formatNumber, formatName){
let request let request
try { try {
if (!track.urls[formatName]) if (!track.urls[formatName]){
track.urls[formatName] = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, formatNumber) 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( request = got.get(
track.urls[formatName], track.urls[formatName],
{ headers: {'User-Agent': USER_AGENT_HEADER}, timeout: 30000 } { headers: {'User-Agent': USER_AGENT_HEADER}, timeout: 30000 }
@ -281,6 +284,7 @@ class Downloader {
let selectedFormat let selectedFormat
try{ try{
selectedFormat = await getPreferredBitrate( selectedFormat = await getPreferredBitrate(
this.dz,
track, track,
this.bitrate, this.bitrate,
this.settings.fallbackBitrate, this.settings.fallbackBitrate,
@ -425,8 +429,11 @@ class Downloader {
// Download the track // Download the track
if (!trackAlreadyDownloaded || this.settings.overwriteFile == OverwriteOption.OVERWRITE){ if (!trackAlreadyDownloaded || this.settings.overwriteFile == OverwriteOption.OVERWRITE){
if (!track.urls[formatsName[track.bitrate]]) if (!track.urls[formatsName[track.bitrate]]){
track.urls[formatsName[track.bitrate]] = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, 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]] track.downloadURL = track.urls[formatsName[track.bitrate]]
let stream = fs.createWriteStream(writepath) let stream = fs.createWriteStream(writepath)
try { try {
@ -496,7 +503,6 @@ class Downloader {
this.warn(itemData, e.errid, 'fallback') this.warn(itemData, e.errid, 'fallback')
let newTrack = await this.dz.gw.get_track_with_fallback(track.fallbackID) let newTrack = await this.dz.gw.get_track_with_fallback(track.fallbackID)
track.parseEssentialData(newTrack) track.parseEssentialData(newTrack)
await track.retriveTrackURLs(this.dz)
await track.retriveFilesizes(this.dz) await track.retriveFilesizes(this.dz)
return await this.downloadWrapper(extraData, track) return await this.downloadWrapper(extraData, track)
} }
@ -506,7 +512,6 @@ class Downloader {
if (searchedID != "0"){ if (searchedID != "0"){
let newTrack = await this.dz.gw.get_track_with_fallback(searchedID) let newTrack = await this.dz.gw.get_track_with_fallback(searchedID)
track.parseEssentialData(newTrack) track.parseEssentialData(newTrack)
await track.retriveTrackURLs(this.dz)
await track.retriveFilesizes(this.dz) await track.retriveFilesizes(this.dz)
track.searched = true track.searched = true
if (this.listener) this.listener.send('queueUpdate', { if (this.listener) this.listener.send('queueUpdate', {

View file

@ -70,6 +70,7 @@ class Track {
this.fallbackID = trackAPI_gw.FALLBACK.SNG_ID this.fallbackID = trackAPI_gw.FALLBACK.SNG_ID
} }
this.localTrack = parseInt(this.id) < 0 this.localTrack = parseInt(this.id) < 0
this.urls = {}
} }
async retriveFilesizes(dz){ async retriveFilesizes(dz){
@ -116,7 +117,6 @@ class Track {
} }
this.parseEssentialData(trackAPI_gw, trackAPI) this.parseEssentialData(trackAPI_gw, trackAPI)
this.retriveTrackURLs(dz)
if (this.localTrack){ if (this.localTrack){
this.parseLocalTrackData(trackAPI_gw) 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(){ removeDuplicateArtists(){
[this.artist, this.artists] = removeDuplicateArtists(this.artist, this.artists) [this.artist, this.artists] = removeDuplicateArtists(this.artist, this.artists)
} }

View file

@ -11,7 +11,7 @@
"dependencies": { "dependencies": {
"async": "^3.2.0", "async": "^3.2.0",
"crypto": "^1.0.1", "crypto": "^1.0.1",
"deezer-js": "^1.0.1", "deezer-js": "^1.0.2",
"got": "^11.8.2", "got": "^11.8.2",
"metaflac-js2": "^1.0.7", "metaflac-js2": "^1.0.7",
"spotify-web-api-node": "^5.0.2" "spotify-web-api-node": "^5.0.2"

View file

@ -370,10 +370,10 @@ deepmerge@^4.0.0:
resolved "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz" resolved "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz"
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==
deezer-js@^1.0.1: deezer-js@^1.0.2:
version "1.0.1" version "1.0.2"
resolved "https://registry.yarnpkg.com/deezer-js/-/deezer-js-1.0.1.tgz#97c3d3c7e84c333a331ecae6aa41d3270e3d4390" resolved "https://registry.yarnpkg.com/deezer-js/-/deezer-js-1.0.2.tgz#fc0a7e0ef683588cfdfbdf3b6e6869bee5642acd"
integrity sha512-nD6E2+txyiAd9QnIY7anvzhiEH8myIAP8guIRJorCW/shkO6pBWdyXvHvjrf8mrWJGpL1T00qoe81uFPOQez2A== integrity sha512-vvwu8KmY52q9pEvEW671jxNXLP00bFQ0EkCYeD6cOj9tsZAxAzReHktrJcZAty7N5BwCw/cGnbixtq87A4O2/Q==
dependencies: dependencies:
got "^11.8.2" got "^11.8.2"
tough-cookie "^4.0.0" tough-cookie "^4.0.0"