mirror of
https://gitlab.com/RemixDev/deemix-js.git
synced 2024-12-29 10:56:18 +00:00
Moved errors in separate file
This commit is contained in:
parent
1d1317c135
commit
dafee37945
|
@ -1,5 +1,6 @@
|
||||||
const got = require('got')
|
const got = require('got')
|
||||||
const {_md5, _ecbCrypt, _ecbDecrypt, generateBlowfishKey, decryptChunk} = require('./utils/crypto.js')
|
const {_md5, _ecbCrypt, _ecbDecrypt, generateBlowfishKey, decryptChunk} = require('./utils/crypto.js')
|
||||||
|
const { DownloadCanceled, DownloadEmpty} = require('./errors.js')
|
||||||
|
|
||||||
const { USER_AGENT_HEADER, pipeline } = require('./utils/index.js')
|
const { USER_AGENT_HEADER, pipeline } = require('./utils/index.js')
|
||||||
|
|
||||||
|
@ -143,27 +144,11 @@ async function streamTrack(outputStream, track, start=0, downloadObject, listene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DownloadEmpty extends Error {
|
|
||||||
constructor() {
|
|
||||||
super()
|
|
||||||
this.name = "DownloadEmpty"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DownloadCanceled extends Error {
|
|
||||||
constructor() {
|
|
||||||
super()
|
|
||||||
this.name = "DownloadCanceled"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateStreamPath,
|
generateStreamPath,
|
||||||
generateStreamURL,
|
generateStreamURL,
|
||||||
generateCryptedStreamURL,
|
generateCryptedStreamURL,
|
||||||
reverseStreamPath,
|
reverseStreamPath,
|
||||||
reverseStreamURL,
|
reverseStreamURL,
|
||||||
streamTrack,
|
streamTrack
|
||||||
DownloadEmpty,
|
|
||||||
DownloadCanceled
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ const { tagID3, tagID3v1, tagFLAC } = require('./tagger.js')
|
||||||
const { USER_AGENT_HEADER, pipeline, shellEscape } = require('./utils/index.js')
|
const { USER_AGENT_HEADER, pipeline, shellEscape } = require('./utils/index.js')
|
||||||
const { DEFAULTS, OverwriteOption } = require('./settings.js')
|
const { DEFAULTS, OverwriteOption } = require('./settings.js')
|
||||||
const { generatePath, generateAlbumName, generateArtistName, generateDownloadObjectName } = require('./utils/pathtemplates.js')
|
const { generatePath, generateAlbumName, generateArtistName, generateDownloadObjectName } = require('./utils/pathtemplates.js')
|
||||||
|
const { PreferredBitrateNotFound, TrackNot360, DownloadFailed, ErrorMessages} = require('./errors.js')
|
||||||
const { TrackFormats } = require('deezer-js')
|
const { TrackFormats } = require('deezer-js')
|
||||||
const { WrongLicense, WrongGeolocation } = require('deezer-js').errors
|
const { WrongLicense, WrongGeolocation } = require('deezer-js').errors
|
||||||
const got = require('got')
|
const got = require('got')
|
||||||
|
@ -558,7 +559,7 @@ class Downloader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.errid += "NoAlternative"
|
e.errid += "NoAlternative"
|
||||||
e.message = errorMessages[e.errid]
|
e.message = ErrorMessages[e.errid]
|
||||||
}
|
}
|
||||||
result = {error:{
|
result = {error:{
|
||||||
message: e.message,
|
message: e.message,
|
||||||
|
@ -690,59 +691,8 @@ class Downloader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DownloadError extends Error {
|
|
||||||
constructor() {
|
|
||||||
super()
|
|
||||||
this.name = "DownloadError"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const errorMessages = {
|
|
||||||
notOnDeezer: "Track not available on Deezer!",
|
|
||||||
notEncoded: "Track not yet encoded!",
|
|
||||||
notEncodedNoAlternative: "Track not yet encoded and no alternative found!",
|
|
||||||
wrongBitrate: "Track not found at desired bitrate.",
|
|
||||||
wrongBitrateNoAlternative: "Track not found at desired bitrate and no alternative found!",
|
|
||||||
wrongLicense: "Your account can't stream the track at the desired bitrate.",
|
|
||||||
no360RA: "Track is not available in Reality Audio 360.",
|
|
||||||
notAvailable: "Track not available on deezer's servers!",
|
|
||||||
notAvailableNoAlternative: "Track not available on deezer's servers and no alternative found!",
|
|
||||||
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."
|
|
||||||
}
|
|
||||||
|
|
||||||
class DownloadFailed extends DownloadError {
|
|
||||||
constructor(errid, track) {
|
|
||||||
super()
|
|
||||||
this.errid = errid
|
|
||||||
this.message = errorMessages[errid]
|
|
||||||
this.name = "DownloadFailed"
|
|
||||||
this.track = track
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TrackNot360 extends DownloadError {
|
|
||||||
constructor() {
|
|
||||||
super()
|
|
||||||
this.name = "TrackNot360"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PreferredBitrateNotFound extends DownloadError {
|
|
||||||
constructor() {
|
|
||||||
super()
|
|
||||||
this.name = "PreferredBitrateNotFound"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Downloader,
|
Downloader,
|
||||||
DownloadError,
|
|
||||||
DownloadFailed,
|
|
||||||
downloadImage,
|
downloadImage,
|
||||||
getPreferredBitrate,
|
getPreferredBitrate
|
||||||
TrackNot360,
|
|
||||||
PreferredBitrateNotFound
|
|
||||||
}
|
}
|
||||||
|
|
182
deemix/errors.js
Normal file
182
deemix/errors.js
Normal file
|
@ -0,0 +1,182 @@
|
||||||
|
class DeemixError extends Error {
|
||||||
|
constructor(message) {
|
||||||
|
super(message)
|
||||||
|
this.name = "DeemixError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GenerationError extends DeemixError {
|
||||||
|
constructor(link, message) {
|
||||||
|
super(message)
|
||||||
|
this.link = link
|
||||||
|
this.name = "GenerationError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ISRCnotOnDeezer extends GenerationError {
|
||||||
|
constructor(link) {
|
||||||
|
super(link, "Track ISRC is not available on deezer")
|
||||||
|
this.name = "ISRCnotOnDeezer"
|
||||||
|
this.errid = "ISRCnotOnDeezer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NotYourPrivatePlaylist extends GenerationError {
|
||||||
|
constructor(link) {
|
||||||
|
super(link, "You can't download others private playlists.")
|
||||||
|
this.name = "NotYourPrivatePlaylist"
|
||||||
|
this.errid = "notYourPrivatePlaylist"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TrackNotOnDeezer extends GenerationError {
|
||||||
|
constructor(link) {
|
||||||
|
super(link, "Track not found on deezer!")
|
||||||
|
this.name = "TrackNotOnDeezer"
|
||||||
|
this.errid = "trackNotOnDeezer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AlbumNotOnDeezer extends GenerationError {
|
||||||
|
constructor(link) {
|
||||||
|
super(link, "Album not found on deezer!")
|
||||||
|
this.name = "AlbumNotOnDeezer"
|
||||||
|
this.errid = "albumNotOnDeezer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InvalidID extends GenerationError {
|
||||||
|
constructor(link) {
|
||||||
|
super(link, "Link ID is invalid!")
|
||||||
|
this.name = "InvalidID"
|
||||||
|
this.errid = "invalidID"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LinkNotSupported extends GenerationError {
|
||||||
|
constructor(link) {
|
||||||
|
super(link, "Link is not supported.")
|
||||||
|
this.name = "LinkNotSupported"
|
||||||
|
this.errid = "unsupportedURL"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LinkNotRecognized extends GenerationError {
|
||||||
|
constructor(link) {
|
||||||
|
super(link, "Link is not recognized.")
|
||||||
|
this.name = "LinkNotRecognized"
|
||||||
|
this.errid = "invalidURL"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DownloadError extends DeemixError {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.name = "DownloadError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ErrorMessages = {
|
||||||
|
notOnDeezer: "Track not available on Deezer!",
|
||||||
|
notEncoded: "Track not yet encoded!",
|
||||||
|
notEncodedNoAlternative: "Track not yet encoded and no alternative found!",
|
||||||
|
wrongBitrate: "Track not found at desired bitrate.",
|
||||||
|
wrongBitrateNoAlternative: "Track not found at desired bitrate and no alternative found!",
|
||||||
|
wrongLicense: "Your account can't stream the track at the desired bitrate.",
|
||||||
|
no360RA: "Track is not available in Reality Audio 360.",
|
||||||
|
notAvailable: "Track not available on deezer's servers!",
|
||||||
|
notAvailableNoAlternative: "Track not available on deezer's servers and no alternative found!",
|
||||||
|
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."
|
||||||
|
}
|
||||||
|
|
||||||
|
class DownloadFailed extends DownloadError {
|
||||||
|
constructor(errid, track) {
|
||||||
|
super()
|
||||||
|
this.errid = errid
|
||||||
|
this.message = ErrorMessages[errid]
|
||||||
|
this.name = "DownloadFailed"
|
||||||
|
this.track = track
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TrackNot360 extends DownloadError {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.name = "TrackNot360"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PreferredBitrateNotFound extends DownloadError {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.name = "PreferredBitrateNotFound"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DownloadEmpty extends DeemixError {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.name = "DownloadEmpty"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DownloadCanceled extends DeemixError {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.name = "DownloadCanceled"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TrackError extends DeemixError {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.name = "TrackError";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MD5NotFound extends TrackError {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.name = "MD5NotFound";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NoDataToParse extends TrackError {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.name = "NoDataToParse";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AlbumDoesntExists extends TrackError {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.name = "AlbumDoesntExists";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
DeemixError,
|
||||||
|
GenerationError,
|
||||||
|
ISRCnotOnDeezer,
|
||||||
|
NotYourPrivatePlaylist,
|
||||||
|
TrackNotOnDeezer,
|
||||||
|
AlbumNotOnDeezer,
|
||||||
|
InvalidID,
|
||||||
|
LinkNotSupported,
|
||||||
|
LinkNotRecognized,
|
||||||
|
ErrorMessages,
|
||||||
|
DownloadError,
|
||||||
|
DownloadFailed,
|
||||||
|
TrackNot360,
|
||||||
|
PreferredBitrateNotFound,
|
||||||
|
DownloadEmpty,
|
||||||
|
DownloadCanceled,
|
||||||
|
TrackError,
|
||||||
|
MD5NotFound,
|
||||||
|
NoDataToParse,
|
||||||
|
AlbumDoesntExists
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ const {
|
||||||
Single,
|
Single,
|
||||||
Collection
|
Collection
|
||||||
} = require('./types/DownloadObjects.js')
|
} = require('./types/DownloadObjects.js')
|
||||||
|
const { GenerationError, ISRCnotOnDeezer, InvalidID, NotYourPrivatePlaylist } = require('./errors.js');
|
||||||
const { LyricsStatus } = require('deezer-js').gw
|
const { LyricsStatus } = require('deezer-js').gw
|
||||||
const { map_user_playlist } = require('deezer-js').utils
|
const { map_user_playlist } = require('deezer-js').utils
|
||||||
const { each } = require('async')
|
const { each } = require('async')
|
||||||
|
@ -310,84 +311,11 @@ async function generateArtistTopItem(dz, id, bitrate){
|
||||||
return generatePlaylistItem(dz, playlistAPI.id, bitrate, playlistAPI, artistTopTracksAPI_gw)
|
return generatePlaylistItem(dz, playlistAPI.id, bitrate, playlistAPI, artistTopTracksAPI_gw)
|
||||||
}
|
}
|
||||||
|
|
||||||
class GenerationError extends Error {
|
|
||||||
constructor(link, message) {
|
|
||||||
super(message)
|
|
||||||
this.link = link
|
|
||||||
this.name = "GenerationError"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ISRCnotOnDeezer extends GenerationError {
|
|
||||||
constructor(link) {
|
|
||||||
super(link, "Track ISRC is not available on deezer")
|
|
||||||
this.name = "ISRCnotOnDeezer"
|
|
||||||
this.errid = "ISRCnotOnDeezer"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class NotYourPrivatePlaylist extends GenerationError {
|
|
||||||
constructor(link) {
|
|
||||||
super(link, "You can't download others private playlists.")
|
|
||||||
this.name = "NotYourPrivatePlaylist"
|
|
||||||
this.errid = "notYourPrivatePlaylist"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TrackNotOnDeezer extends GenerationError {
|
|
||||||
constructor(link) {
|
|
||||||
super(link, "Track not found on deezer!")
|
|
||||||
this.name = "TrackNotOnDeezer"
|
|
||||||
this.errid = "trackNotOnDeezer"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AlbumNotOnDeezer extends GenerationError {
|
|
||||||
constructor(link) {
|
|
||||||
super(link, "Album not found on deezer!")
|
|
||||||
this.name = "AlbumNotOnDeezer"
|
|
||||||
this.errid = "albumNotOnDeezer"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class InvalidID extends GenerationError {
|
|
||||||
constructor(link) {
|
|
||||||
super(link, "Link ID is invalid!")
|
|
||||||
this.name = "InvalidID"
|
|
||||||
this.errid = "invalidID"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LinkNotSupported extends GenerationError {
|
|
||||||
constructor(link) {
|
|
||||||
super(link, "Link is not supported.")
|
|
||||||
this.name = "LinkNotSupported"
|
|
||||||
this.errid = "unsupportedURL"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LinkNotRecognized extends GenerationError {
|
|
||||||
constructor(link) {
|
|
||||||
super(link, "Link is not recognized.")
|
|
||||||
this.name = "LinkNotRecognized"
|
|
||||||
this.errid = "invalidURL"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateTrackItem,
|
generateTrackItem,
|
||||||
generateAlbumItem,
|
generateAlbumItem,
|
||||||
generatePlaylistItem,
|
generatePlaylistItem,
|
||||||
generateArtistItem,
|
generateArtistItem,
|
||||||
generateArtistDiscographyItem,
|
generateArtistDiscographyItem,
|
||||||
generateArtistTopItem,
|
generateArtistTopItem
|
||||||
|
|
||||||
GenerationError,
|
|
||||||
ISRCnotOnDeezer,
|
|
||||||
NotYourPrivatePlaylist,
|
|
||||||
TrackNotOnDeezer,
|
|
||||||
AlbumNotOnDeezer,
|
|
||||||
InvalidID,
|
|
||||||
LinkNotSupported,
|
|
||||||
LinkNotRecognized
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ const { Date } = require('./Date.js')
|
||||||
const { VARIOUS_ARTISTS } = require('./index.js')
|
const { VARIOUS_ARTISTS } = require('./index.js')
|
||||||
const { changeCase } = require('../utils/index.js')
|
const { changeCase } = require('../utils/index.js')
|
||||||
const { FeaturesOption } = require('../settings.js')
|
const { FeaturesOption } = require('../settings.js')
|
||||||
|
const { TrackError, NoDataToParse, AlbumDoesntExists } = require('../errros.js');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
generateReplayGainString,
|
generateReplayGainString,
|
||||||
|
@ -367,38 +368,6 @@ class Track {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TrackError extends Error {
|
|
||||||
constructor(message) {
|
|
||||||
super(message);
|
|
||||||
this.name = "TrackError";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MD5NotFound extends TrackError {
|
|
||||||
constructor(message) {
|
|
||||||
super(message);
|
|
||||||
this.name = "MD5NotFound";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class NoDataToParse extends TrackError {
|
|
||||||
constructor(message) {
|
|
||||||
super(message);
|
|
||||||
this.name = "NoDataToParse";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AlbumDoesntExists extends TrackError {
|
|
||||||
constructor(message) {
|
|
||||||
super(message);
|
|
||||||
this.name = "AlbumDoesntExists";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Track,
|
Track
|
||||||
TrackError,
|
|
||||||
MD5NotFound,
|
|
||||||
NoDataToParse,
|
|
||||||
AlbumDoesntExists
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue