Added fallbackISRC option

It will search for available alternatives with the same ISRC
This commit is contained in:
RemixDev 2021-12-23 16:00:55 +01:00
parent da04a94191
commit 47092d77b6
No known key found for this signature in database
GPG key ID: B33962B465BDB51C
5 changed files with 36 additions and 4 deletions

View file

@ -332,7 +332,7 @@ class Downloader {
)
}catch (e){
if (e.name === "WrongLicense") { throw new DownloadFailed("wrongLicense")}
if (e.name === "WrongGeolocation") { throw new DownloadFailed("wrongGeolocation")}
if (e.name === "WrongGeolocation") { throw new DownloadFailed("wrongGeolocation", track)}
if (e.name === "PreferredBitrateNotFound") { throw new DownloadFailed("wrongBitrate", track) }
if (e.name === "TrackNot360") { throw new DownloadFailed("no360RA") }
console.trace(e)
@ -535,17 +535,35 @@ class Downloader {
if (track.fallbackID != 0){
this.warn(itemData, e.errid, 'fallback')
let newTrack = await this.dz.gw.get_track_with_fallback(track.fallbackID)
newTrack = map_track(newTrack)
track.parseEssentialData(newTrack)
await track.retriveFilesizes(this.dz)
return await this.downloadWrapper(extraData, track)
}
if (track.albumsFallback.length && this.settings.fallbackISRC){
let newAlbumID = track.albumsFallback.pop()
let newAlbum = await this.dz.gw.get_album_page(newAlbumID)
let fallbackID = 0
for (let newTrack of newAlbum.SONGS.data) {
if (newTrack.ISRC === track.ISRC) {
fallbackID = newTrack.SNG_ID
break;
}
}
if (fallbackID != 0){
this.warn(itemData, e.errid, 'fallback')
let newTrack = await this.dz.gw.get_track_with_fallback(fallbackID)
newTrack = map_track(newTrack)
track.parseEssentialData(newTrack)
return await this.downloadWrapper(extraData, track)
}
}
if (!track.searched && this.settings.fallbackSearch){
this.warn(itemData, e.errid, 'search')
let searchedID = await this.dz.api.get_track_id_from_metadata(track.mainArtist.name, track.title, track.album.title)
if (searchedID != "0"){
let newTrack = await this.dz.gw.get_track_with_fallback(searchedID)
newTrack = map_track(newTrack)
track.parseEssentialData(newTrack)
await track.retriveFilesizes(this.dz)
track.searched = true
this.log(itemData, "searchFallback")
return await this.downloadWrapper(extraData, track)

View file

@ -89,7 +89,8 @@ const ErrorMessages = {
noSpaceLeft: "No space left on target drive, clean up some space for the tracks.",
albumDoesntExists: "Track's album does not exsist, failed to gather info.",
notLoggedIn: "You need to login to download tracks.",
wrongGeolocation: "Your account can't stream the track from your current country."
wrongGeolocation: "Your account can't stream the track from your current country.",
wrongGeolocationNoAlternative: "Your account can't stream the track from your current country and no alternative found."
}
class DownloadFailed extends DownloadError {

View file

@ -37,6 +37,8 @@ async function generateTrackItem(dz, id, bitrate, trackAPI, albumAPI){
cover = `https://e-cdns-images.dzcdn.net/images/cover/${trackAPI.md5_image}/75x75-000000-80-0-0.jpg`
}
delete trackAPI.track_token
return new Single({
type: 'track',
id: id,
@ -118,6 +120,7 @@ async function generateAlbumItem(dz, id, bitrate, rootArtist){
let collection = []
tracksArray.forEach((trackAPI, pos) => {
trackAPI = map_track(trackAPI)
delete trackAPI.track_token
trackAPI.position = pos+1
collection.push(trackAPI)
})
@ -178,6 +181,7 @@ async function generatePlaylistItem(dz, id, bitrate, playlistAPI, playlistTracks
trackAPI = map_track(trackAPI)
if (trackAPI.explicit_lyrics)
playlistAPI.explicit = true
delete trackAPI.track_token
trackAPI.position = pos+1
collection.push(trackAPI)
});

View file

@ -41,6 +41,7 @@ const DEFAULTS = {
feelingLucky: false,
fallbackBitrate: false,
fallbackSearch: false,
fallbackISRC: false,
logErrors: true,
logSearched: false,
overwriteFile: OverwriteOption.DONT_OVERWRITE,

View file

@ -27,6 +27,7 @@ class Track {
this.trackTokenExpiration = 0
this.duration = 0
this.fallbackID = "0"
this.albumsFallback = []
this.filesizes = {}
this.localTrack = false
this.mainArtist = null
@ -221,6 +222,13 @@ class Track {
this.artist[artist.role].push(artist.name)
}
})
if (trackAPI.alternative_albums){
trackAPI.alternative_albums.data.forEach(album => {
if (album.RIGHTS.STREAM_ADS_AVAILABLE || album.RIGHTS.STREAM_SUB_AVAILABLE)
this.albumsFallback.push(album.ALB_ID)
})
}
}
removeDuplicateArtists(){