Added exceptions for wrong URLs and added support for UPC and ISRC URLs
This commit is contained in:
parent
e478e5b031
commit
f72fe5ceee
|
@ -7,6 +7,7 @@ from Cryptodome.Cipher import Blowfish, AES
|
||||||
from Cryptodome.Hash import MD5
|
from Cryptodome.Hash import MD5
|
||||||
from Cryptodome.Util.Padding import pad
|
from Cryptodome.Util.Padding import pad
|
||||||
import re
|
import re
|
||||||
|
import json
|
||||||
|
|
||||||
USER_AGENT_HEADER = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
USER_AGENT_HEADER = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
||||||
"Chrome/79.0.3945.130 Safari/537.36"
|
"Chrome/79.0.3945.130 Safari/537.36"
|
||||||
|
@ -95,7 +96,7 @@ class Deezer:
|
||||||
if 'code' in result_json['error'] and result_json['error']['code'] == 4:
|
if 'code' in result_json['error'] and result_json['error']['code'] == 4:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
return self.api_call(method, args)
|
return self.api_call(method, args)
|
||||||
raise APIError(result_json)
|
raise APIError(json.dumps(result_json))
|
||||||
return result_json
|
return result_json
|
||||||
|
|
||||||
def login(self, email, password, re_captcha_token, child=0):
|
def login(self, email, password, re_captcha_token, child=0):
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from deemix.app.downloader import download
|
from deemix.app.downloader import download
|
||||||
from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt
|
from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt
|
||||||
|
from deemix.api.deezer import APIError
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger('deemix')
|
logger = logging.getLogger('deemix')
|
||||||
|
@ -67,6 +69,20 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
logger.warn("URL not recognized")
|
logger.warn("URL not recognized")
|
||||||
result['error'] = "URL not recognized"
|
result['error'] = "URL not recognized"
|
||||||
elif type == "track":
|
elif type == "track":
|
||||||
|
if id.startswith("isrc"):
|
||||||
|
try:
|
||||||
|
trackAPI = dz.get_track(id)
|
||||||
|
if 'id' in dz_track and 'title' in dz_track:
|
||||||
|
id = trackAPI['id']
|
||||||
|
else:
|
||||||
|
result['error'] = "Track ISRC is not available on deezer"
|
||||||
|
return result
|
||||||
|
except APIError as e:
|
||||||
|
e = json.loads(str(e))
|
||||||
|
result['error'] = "Wrong URL"
|
||||||
|
if 'error' in e:
|
||||||
|
result['error'] += f": {e['error']['type']+': ' if 'type' in e['error'] else ''}{e['error']['message'] if 'message' in e['error'] else ''}"
|
||||||
|
return result
|
||||||
trackAPI = dz.get_track_gw(id)
|
trackAPI = dz.get_track_gw(id)
|
||||||
if albumAPI:
|
if albumAPI:
|
||||||
trackAPI['_EXTRA_ALBUM'] = albumAPI
|
trackAPI['_EXTRA_ALBUM'] = albumAPI
|
||||||
|
@ -95,7 +111,16 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
result['single'] = trackAPI
|
result['single'] = trackAPI
|
||||||
|
|
||||||
elif type == "album":
|
elif type == "album":
|
||||||
albumAPI = dz.get_album(id)
|
try:
|
||||||
|
albumAPI = dz.get_album(id)
|
||||||
|
except APIError as e:
|
||||||
|
e = json.loads(str(e))
|
||||||
|
result['error'] = "Wrong URL"
|
||||||
|
if 'error' in e:
|
||||||
|
result['error'] += f": {e['error']['type']+': ' if 'type' in e['error'] else ''}{e['error']['message'] if 'message' in e['error'] else ''}"
|
||||||
|
return result
|
||||||
|
if id.startswith('upc'):
|
||||||
|
id = albumAPI['id']
|
||||||
albumAPI_gw = dz.get_album_gw(id)
|
albumAPI_gw = dz.get_album_gw(id)
|
||||||
albumAPI['nb_disk'] = albumAPI_gw['NUMBER_DISK']
|
albumAPI['nb_disk'] = albumAPI_gw['NUMBER_DISK']
|
||||||
albumAPI['copyright'] = albumAPI_gw['COPYRIGHT']
|
albumAPI['copyright'] = albumAPI_gw['COPYRIGHT']
|
||||||
|
@ -198,7 +223,14 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
playlistAPI['explicit'] = False
|
playlistAPI['explicit'] = False
|
||||||
|
|
||||||
elif type == "artist":
|
elif type == "artist":
|
||||||
artistAPI = dz.get_artist(id)
|
try:
|
||||||
|
albumAPI = artistAPI = dz.get_artist(id)
|
||||||
|
except APIError as e:
|
||||||
|
e = json.loads(str(e))
|
||||||
|
result['error'] = "Wrong URL"
|
||||||
|
if 'error' in e:
|
||||||
|
result['error'] += f": {e['error']['type']+': ' if 'type' in e['error'] else ''}{e['error']['message'] if 'message' in e['error'] else ''}"
|
||||||
|
return result
|
||||||
if interface:
|
if interface:
|
||||||
interface.send("startAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
interface.send("startAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']})
|
||||||
artistAPITracks = dz.get_artist_albums(id)
|
artistAPITracks = dz.get_artist_albums(id)
|
||||||
|
|
Loading…
Reference in New Issue