MusicBrainz Query

Heavily tweaked the query from releases to 'official' recordings (which includes matching track names). Picks the first one that is above a 90% match for any single, album, or EP, and of course has a valid Front image. Seems to lean towards providing album covers, whereas the release query only gave you singles.
This commit is contained in:
markjfine 2021-04-23 15:25:47 -04:00 committed by GitHub
parent aa49f2ae17
commit 16877d83cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -354,25 +354,37 @@ class NRSC5_DUI(object):
# if not, get it from MusicBrainz # if not, get it from MusicBrainz
else: else:
try: try:
result = musicbrainzngs.search_releases(artist=self.streamInfo["Artist"], release=self.streamInfo["Title"]) result = musicbrainzngs.search_recordings(artist=self.streamInfo["Artist"], recording=self.streamInfo["Title"])
if result['release-list']: if result['recording-list']:
# loop through the list until you get a match # loop through the list until you get a match
#print()
resultID = "" resultID = ""
for (idx, release) in enumerate(result['release-list']): imgSaved = False
#print(release["artist-credit-phrase"]+" - "+release['title']+" "+release['id']) for (idx, release) in enumerate(result['recording-list']):
artistMatch = (newArtist.lower() in release["artist-credit-phrase"].lower()) resultScore=release['ext:score']
titleMatch = (self.streamInfo["Title"].lower() in release['title'].lower()) resultArtist=release['artist-credit-phrase']
if (artistMatch and titleMatch): resultTitle=release['title']
resultID = release['id'] resultid=release['id']
for (idx2, release2) in enumerate(release['release-list']):
resultStatus=release2['status']
resultType=release2['release-group']['type']
resultid = release2['id']
typeMatch = (resultType in ['Single','Album','EP'])
statusMatch = (resultStatus == 'Official')
if (typeMatch and statusMatch):
break
scoreMatch = (int(resultScore) > 90)
artistMatch = (newArtist.lower() in resultArtist.lower())
titleMatch = (self.streamInfo["Title"].lower() in resultTitle.lower())
if (artistMatch and titleMatch and scoreMatch):
resultID=resultid
# got a match, now get the cover art # got a match, now get the cover art
#print("Found {} - {}, {}".format(release["artist-credit-phrase"], release['title'], resultID)) #print("Found {}: {} - {}, {} {}%".format(resultType, resultArtist, resultTitle, resultID, resultScore))
imageList = musicbrainzngs.get_image_list(resultID) imageList = musicbrainzngs.get_image_list(resultID)
for image in imageList["images"]: for image in imageList["images"]:
if "Front" in image["types"] and image["approved"]: if "Front" in image["types"]: # and image["approved"]:
# now save it # now save it
#print("Found approved image") #print("Found approved image")
@ -382,9 +394,13 @@ class NRSC5_DUI(object):
imgCvr = Image.open(dataBytes) imgCvr = Image.open(dataBytes)
imgCvr.save(saveStr) imgCvr.save(saveStr)
self.coverImage = saveStr self.coverImage = saveStr
imgSaved = True
if (imgSaved):
break break
break if (imgSaved):
break
# If no match use the station logo if there is one # If no match use the station logo if there is one
else: else: