mirror of
https://github.com/krateng/maloja.git
synced 2025-06-10 12:22:21 +03:00
Improve track image fetching from Musicbrainz
This commit is contained in:
parent
6a3fd46219
commit
7910ee3b6b
@ -160,6 +160,14 @@ def print_info():
|
|||||||
except Exception:
|
except Exception:
|
||||||
print("Could not determine system information.")
|
print("Could not determine system information.")
|
||||||
|
|
||||||
|
|
||||||
|
def print_settings():
|
||||||
|
print_header_info()
|
||||||
|
maxlen = max(len(k) for k in conf.malojaconfig)
|
||||||
|
for k in conf.malojaconfig:
|
||||||
|
print(col['lightblue'](k.ljust(maxlen+2)),conf.malojaconfig[k])
|
||||||
|
|
||||||
|
|
||||||
@mainfunction({"l":"level","v":"version","V":"version"},flags=['version','include_images','prefer_existing'],shield=True)
|
@mainfunction({"l":"level","v":"version","V":"version"},flags=['version','include_images','prefer_existing'],shield=True)
|
||||||
def main(*args,**kwargs):
|
def main(*args,**kwargs):
|
||||||
|
|
||||||
@ -180,7 +188,8 @@ def main(*args,**kwargs):
|
|||||||
"apidebug":apidebug.run, # maloja apidebug
|
"apidebug":apidebug.run, # maloja apidebug
|
||||||
"parsealbums":tasks.parse_albums, # maloja parsealbums --strategy majority
|
"parsealbums":tasks.parse_albums, # maloja parsealbums --strategy majority
|
||||||
# aux
|
# aux
|
||||||
"info":print_info
|
"info":print_info,
|
||||||
|
"settings":print_settings
|
||||||
}
|
}
|
||||||
|
|
||||||
if "version" in kwargs:
|
if "version" in kwargs:
|
||||||
|
39
maloja/thirdparty/musicbrainz.py
vendored
39
maloja/thirdparty/musicbrainz.py
vendored
@ -33,14 +33,15 @@ class MusicBrainz(MetadataInterface):
|
|||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
try:
|
try:
|
||||||
artists, title = track
|
artists, title = track
|
||||||
artiststring = ", ".join(artists) #Join artists collection into string
|
searchstr = f'recording:"{title}"'
|
||||||
titlestring = title
|
for artist in artists:
|
||||||
|
searchstr += f' artist:"{artist}"'
|
||||||
querystr = urllib.parse.urlencode({
|
querystr = urllib.parse.urlencode({
|
||||||
"fmt":"json",
|
"fmt":"json",
|
||||||
"query":"{title} {artist}".format(artist=artiststring,title=titlestring)
|
"query":searchstr
|
||||||
})
|
})
|
||||||
req = urllib.request.Request(**{
|
req = urllib.request.Request(**{
|
||||||
"url":"https://musicbrainz.org/ws/2/release?" + querystr,
|
"url":"https://musicbrainz.org/ws/2/recording?" + querystr,
|
||||||
"method":"GET",
|
"method":"GET",
|
||||||
"headers":{
|
"headers":{
|
||||||
"User-Agent":self.useragent
|
"User-Agent":self.useragent
|
||||||
@ -49,15 +50,27 @@ class MusicBrainz(MetadataInterface):
|
|||||||
response = urllib.request.urlopen(req)
|
response = urllib.request.urlopen(req)
|
||||||
responsedata = response.read()
|
responsedata = response.read()
|
||||||
data = json.loads(responsedata)
|
data = json.loads(responsedata)
|
||||||
mbid = data["releases"][0]["id"]
|
entity = data["recordings"][0]["releases"][0]
|
||||||
response = urllib.request.urlopen(
|
coverartendpoint = "release"
|
||||||
"https://coverartarchive.org/release/{mbid}?fmt=json".format(mbid=mbid)
|
while True:
|
||||||
)
|
mbid = entity["id"]
|
||||||
responsedata = response.read()
|
try:
|
||||||
data = json.loads(responsedata)
|
response = urllib.request.urlopen(
|
||||||
imgurl = self.metadata_parse_response_track(data)
|
f"https://coverartarchive.org/{coverartendpoint}/{mbid}?fmt=json"
|
||||||
if imgurl is not None: imgurl = self.postprocess_url(imgurl)
|
)
|
||||||
return imgurl
|
responsedata = response.read()
|
||||||
|
data = json.loads(responsedata)
|
||||||
|
imgurl = self.metadata_parse_response_track(data)
|
||||||
|
except:
|
||||||
|
imgurl = None
|
||||||
|
if imgurl is None:
|
||||||
|
entity = entity["release-group"]
|
||||||
|
# this will raise an error so we don't stay in the while loop forever
|
||||||
|
coverartendpoint = "release-group"
|
||||||
|
continue
|
||||||
|
|
||||||
|
imgurl = self.postprocess_url(imgurl)
|
||||||
|
return imgurl
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user