MusicBrainz data consistency
Added more robust checks to ensure routine wasn't blowing up due to missing or inconsistent data. Routine seems to be flowing correctly now. Added a quick and tentative replacement for apostrophes in artist or title - might fix that part, but there are more fusion-type issues with 'and' vs '&', 'J.J.' vs 'JJ', etc.
This commit is contained in:
parent
2128162fbf
commit
395bd5782c
124
nrsc5-dui.py
124
nrsc5-dui.py
@ -338,12 +338,19 @@ class NRSC5_DUI(object):
|
|||||||
newArtist = newArtist[:m.start()].strip()
|
newArtist = newArtist[:m.start()].strip()
|
||||||
return newArtist
|
return newArtist
|
||||||
|
|
||||||
|
def check_value(self,arg,group,default):
|
||||||
|
result = default
|
||||||
|
if(arg in group):
|
||||||
|
result = group[arg]
|
||||||
|
return result
|
||||||
|
|
||||||
def get_cover_image_online(self):
|
def get_cover_image_online(self):
|
||||||
global aasDir
|
global aasDir
|
||||||
got_cover = False
|
got_cover = False
|
||||||
|
|
||||||
# only care about the first artist listed if separated by slashes
|
# only care about the first artist listed if separated by slashes
|
||||||
newArtist = self.fix_artist()
|
newArtist = self.fix_artist()
|
||||||
|
newTitle = self.streamInfo["Title"].replace("'","’")
|
||||||
baseStr = str(newArtist+" - "+self.streamInfo["Title"])
|
baseStr = str(newArtist+" - "+self.streamInfo["Title"])
|
||||||
saveStr = os.path.join(aasDir, baseStr.replace(" ","_").replace("/","_").replace(":","_")+".jpg")
|
saveStr = os.path.join(aasDir, baseStr.replace(" ","_").replace("/","_").replace(":","_")+".jpg")
|
||||||
|
|
||||||
@ -354,58 +361,101 @@ class NRSC5_DUI(object):
|
|||||||
# if not, get it from MusicBrainz
|
# if not, get it from MusicBrainz
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
result = musicbrainzngs.search_recordings(artist=self.streamInfo["Artist"], recording=self.streamInfo["Title"])
|
imgSaved = False
|
||||||
|
result = None
|
||||||
|
|
||||||
if result['recording-list']:
|
#print()
|
||||||
|
#print("searching for {} - {}".format(self.streamInfo["Artist"],newTitle))
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = musicbrainzngs.search_recordings(artist=self.streamInfo["Artist"], recording=newTitle)
|
||||||
|
#print("recording search succeeded")
|
||||||
|
except:
|
||||||
|
#print("mb recording search error")
|
||||||
|
pass
|
||||||
|
|
||||||
|
if (result is not None) and ('recording-list' in result):
|
||||||
|
#print("got recording search result")
|
||||||
|
|
||||||
# loop through the list until you get a match
|
# loop through the list until you get a match
|
||||||
resultID = ""
|
|
||||||
imgSaved = False
|
|
||||||
for (idx, release) in enumerate(result['recording-list']):
|
for (idx, release) in enumerate(result['recording-list']):
|
||||||
resultScore=release['ext:score']
|
#print(release)
|
||||||
resultArtist=release['artist-credit-phrase']
|
resultid = self.check_value('id',release,"")
|
||||||
resultTitle=release['title']
|
resultScore = self.check_value('ext:score',release,"0")
|
||||||
resultid=release['id']
|
resultArtist = self.check_value('artist-credit-phrase',release,"")
|
||||||
for (idx2, release2) in enumerate(release['release-list']):
|
resultTitle = self.check_value('title',release,"")
|
||||||
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)
|
scoreMatch = (int(resultScore) > 90)
|
||||||
artistMatch = (newArtist.lower() in resultArtist.lower())
|
artistMatch = (newArtist.lower() in resultArtist.lower())
|
||||||
titleMatch = (self.streamInfo["Title"].lower() in resultTitle.lower())
|
titleMatch = (newTitle.lower() in resultTitle.lower())
|
||||||
if (artistMatch and titleMatch and scoreMatch):
|
if ('release-list' in release):
|
||||||
|
#print("got release-list")
|
||||||
|
for (idx2, release2) in enumerate(release['release-list']):
|
||||||
|
#print(release2)
|
||||||
|
resultid = self.check_value('id',release2,"")
|
||||||
|
resultStatus = self.check_value('status',release2,"")
|
||||||
|
resultType = self.check_value('type',self.check_value('release-group',release2,""),"")
|
||||||
|
resultAlbum = self.check_value('title',release2,"")
|
||||||
|
typeMatch = (resultType in ['Single','Album','EP'])
|
||||||
|
statusMatch = (resultStatus == 'Official')
|
||||||
|
#print(" release-list: #{} of {}".format(idx2, len(release['release-list'])))
|
||||||
|
if (typeMatch and statusMatch and ((idx2+1) < len(release['release-list']))):
|
||||||
|
break
|
||||||
|
#print("#{} {} {}: {} - {} - {}, {} {}%".format(idx, resultStatus, resultType, resultArtist, resultTitle, resultAlbum, resultid, resultScore))
|
||||||
|
if (artistMatch and titleMatch and scoreMatch and typeMatch and statusMatch):
|
||||||
resultID=resultid
|
resultID=resultid
|
||||||
|
|
||||||
# got a match, now get the cover art
|
# got a match, now get the cover art
|
||||||
#print("Found {}: {} - {}, {} {}%".format(resultType, resultArtist, resultTitle, resultID, resultScore))
|
#print("Found {}: {} - {} - {}, {} {}%".format(resultType, resultArtist, resultTitle, resultAlbum, resultID, resultScore))
|
||||||
imageList = musicbrainzngs.get_image_list(resultID)
|
imageList = None
|
||||||
for image in imageList["images"]:
|
|
||||||
if "Front" in image["types"]: # and image["approved"]:
|
|
||||||
|
|
||||||
# now save it
|
try:
|
||||||
#print("Found approved image")
|
imageList = musicbrainzngs.get_image_list(resultID)
|
||||||
imgData = musicbrainzngs.get_image_front(resultID, size="500")
|
except:
|
||||||
if (len(imgData) > 0):
|
#print("mb image error")
|
||||||
dataBytes = io.BytesIO(imgData)
|
pass
|
||||||
imgCvr = Image.open(dataBytes)
|
|
||||||
imgCvr.save(saveStr)
|
|
||||||
self.coverImage = saveStr
|
|
||||||
imgSaved = True
|
|
||||||
|
|
||||||
if (imgSaved):
|
if (imageList is not None) and ('images' in imageList):
|
||||||
break
|
#print('has images')
|
||||||
|
for (idx3, image) in enumerate(imageList['images']):
|
||||||
|
imgTypes = self.check_value('types', image, None)
|
||||||
|
imgApproved = self.check_value('approved', image, "False")
|
||||||
|
#print("image: {} {}".format(imgTypes, imgApproved))
|
||||||
|
if ('Front' in imgTypes) and imgApproved:
|
||||||
|
|
||||||
if (imgSaved):
|
# now save it
|
||||||
|
#print("Found approved image")
|
||||||
|
imgData = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
imgData = musicbrainzngs.get_image_front(resultID, size="500")
|
||||||
|
except:
|
||||||
|
#print("mb image retrieval error")
|
||||||
|
pass
|
||||||
|
|
||||||
|
#if (len(imgData) > 0):
|
||||||
|
if (imgData is not None) and (len(imgData) > 0):
|
||||||
|
dataBytes = io.BytesIO(imgData)
|
||||||
|
imgCvr = Image.open(dataBytes)
|
||||||
|
imgCvr.save(saveStr)
|
||||||
|
self.coverImage = saveStr
|
||||||
|
imgSaved = True
|
||||||
|
|
||||||
|
#print("image-list: #{} of {}".format(idx3, len(imageList['images'])))
|
||||||
|
if (imgSaved) and ((idx3+1) < len(imageList['images'])):
|
||||||
|
break
|
||||||
|
#print("End of image-list")
|
||||||
|
|
||||||
|
#print("recording-list: #{} of {}".format(idx, len(result['recording-list'])))
|
||||||
|
if (imgSaved) and ((idx+1) < len(result['recording-list'])) or (not scoreMatch):
|
||||||
break
|
break
|
||||||
|
#print("End of recording-list")
|
||||||
|
|
||||||
# If no match use the station logo if there is one
|
# If no match use the station logo if there is one
|
||||||
else:
|
if (not imgSaved):
|
||||||
self.coverImage = os.path.join(aasDir, self.stationLogos[self.stationStr][self.streamNum])
|
#print("No image found, using logo")
|
||||||
|
self.coverImage = os.path.join(aasDir, self.stationLogos[self.stationStr][self.streamNum])
|
||||||
except:
|
except:
|
||||||
|
#print("general error")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# now display it by simulating a window resize
|
# now display it by simulating a window resize
|
||||||
|
Loading…
Reference in New Issue
Block a user