Modified Cover Search routine

If Strict is set and it can't find anything, it will automatically search again with Strict off.
This commit is contained in:
markjfine 2021-04-28 19:17:17 -04:00 committed by GitHub
parent a56ebb5e1d
commit 2ec6f0331a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -415,9 +415,7 @@ class NRSC5_DUI(object):
newArtist = self.fix_artist().replace("'","") newArtist = self.fix_artist().replace("'","")
setStrict = (self.cbStrict.get_sensitive() and self.cbStrict.get_active()) setStrict = (self.cbStrict.get_sensitive() and self.cbStrict.get_active())
#if setStrict:
searchArtist = newArtist searchArtist = newArtist
#else:
#searchArtist = artist=self.streamInfo["Artist"].replace("'","").replace("/","ft.") #searchArtist = artist=self.streamInfo["Artist"].replace("'","").replace("/","ft.")
newTitle = self.streamInfo["Title"].replace("'","") newTitle = self.streamInfo["Title"].replace("'","")
baseStr = str(newArtist+" - "+self.streamInfo["Title"]).replace(" ","_").replace("/","_").replace(":","_")+".jpg" baseStr = str(newArtist+" - "+self.streamInfo["Title"]).replace(" ","_").replace("/","_").replace(":","_")+".jpg"
@ -437,20 +435,30 @@ class NRSC5_DUI(object):
else: else:
try: try:
imgSaved = False imgSaved = False
i = 1
while (not imgSaved):
#if no image was downloaded the first time through and Strict was True, try again setting Strict to False
print()
if (i==2) and (setStrict):
setStrict = False
print("Running through again, setStrict is ",setStrict)
else:
print("Running through first time, setStrict is ",setStrict)
result = None result = None
#print() print("searching for {} - {}".format(searchArtist,newTitle))
#print("searching for {} - {}".format(searchArtist,newTitle))
try: try:
result = musicbrainzngs.search_recordings(strict=setStrict, artist=searchArtist, recording=newTitle, type='Album', status='Official') result = musicbrainzngs.search_recordings(strict=setStrict, artist=searchArtist, recording=newTitle, type='Album', status='Official')
#print("recording search succeeded") print("recording search succeeded")
except: except:
print("MusicBrainz recording search error") print("MusicBrainz recording search error")
#pass #pass
if (result is not None) and ('recording-list' in result): if (result is not None) and ('recording-list' in result) and (len(result['recording-list']) != 0):
#print("got recording search result with {} recordings".format(len(result['recording-list']))) print("got recording search result with {} recordings".format(len(result['recording-list'])))
# loop through the list until you get a match # loop through the list until you get a match
for (idx, release) in enumerate(result['recording-list']): for (idx, release) in enumerate(result['recording-list']):
@ -473,7 +481,7 @@ class NRSC5_DUI(object):
releaseMatch = False releaseMatch = False
imageMatch = False imageMatch = False
if recordingMatch and ('release-list' in release): if recordingMatch and ('release-list' in release):
#print("got release list with {} releases".format(len(release['release-list']))) print("got release list with {} releases".format(len(release['release-list'])))
for (idx2, release2) in enumerate(release['release-list']): for (idx2, release2) in enumerate(release['release-list']):
#print(release2) #print(release2)
imageMatch = False imageMatch = False
@ -488,7 +496,7 @@ class NRSC5_DUI(object):
#artistMatch2 = (resultArtist2 != "") and (not ('Various' in resultArtist2)) #artistMatch2 = (resultArtist2 != "") and (not ('Various' in resultArtist2))
artistMatch2 = (not ('Various' in resultArtist2)) artistMatch2 = (not ('Various' in resultArtist2))
releaseMatch = (artistMatch2 and albumMatch and typeMatch and statusMatch) releaseMatch = (artistMatch2 and albumMatch and typeMatch and statusMatch)
#print("#{} {}: Track: {} - {}, {}: {} - {}, {} {}% {}".format(idx, resultStatus, resultArtist, resultTitle, resultType, resultArtist2, resultAlbum, resultID, resultScore, resultGenre)) print("#{} {}: Track: {} - {}, {}: {} - {}, {} {}% {}".format(idx, resultStatus, resultArtist, resultTitle, resultType, resultArtist2, resultAlbum, resultID, resultScore, resultGenre))
# don't bother checking for covers unless album, type, and status match # don't bother checking for covers unless album, type, and status match
if releaseMatch: if releaseMatch:
imageMatch = self.check_musicbrainz_cover(resultID) imageMatch = self.check_musicbrainz_cover(resultID)
@ -498,22 +506,30 @@ class NRSC5_DUI(object):
if (recordingMatch and releaseMatch and imageMatch): if (recordingMatch and releaseMatch and imageMatch):
# got a full match, now get the cover art # got a full match, now get the cover art
#print("Found {}: Track: {} - {}, {}: {} - {}, {} {}% {}".format(resultStatus, resultArtist, resultTitle, resultType, resultArtist2, resultAlbum, resultID, resultScore, resultGenre)) print("Found {}: Track: {} - {}, {}: {} - {}, {} {}% {}".format(resultStatus, resultArtist, resultTitle, resultType, resultArtist2, resultAlbum, resultID, resultScore, resultGenre))
if self.save_musicbrainz_cover(resultID,saveStr): if self.save_musicbrainz_cover(resultID,saveStr):
self.coverImage = saveStr self.coverImage = saveStr
imgSaved = True imgSaved = True
if (self.streamInfo['Album'] == ""): if (self.streamInfo['Album'] == ""):
self.streamInfo['Album']=resultAlbum self.streamInfo['Album']=resultAlbum
if (self.streamInfo['Genre'] == ""):
self.streamInfo['Genre']=resultGenre
self.coverMetas[baseStr] = [self.streamInfo["Title"],self.streamInfo["Artist"],self.streamInfo["Album"],self.streamInfo["Genre"]] self.coverMetas[baseStr] = [self.streamInfo["Title"],self.streamInfo["Artist"],self.streamInfo["Album"],self.streamInfo["Genre"]]
if (imgSaved) and ((idx+1) < len(result['recording-list'])) or (not scoreMatch): if (imgSaved) and ((idx+1) < len(result['recording-list'])) or (not scoreMatch):
break break
i = 2
# if we got an image or Strict was false the first time through, there's no need to run through it again
if (imgSaved) or (setStrict==False):
break
# If no match use the station logo if there is one # If no match use the station logo if there is one
if (not imgSaved): if (not imgSaved):
#print("No image found, using logo") print("No image found, using logo")
self.coverImage = os.path.join(aasDir, self.stationLogos[self.stationStr][self.streamNum]) self.coverImage = os.path.join(aasDir, self.stationLogos[self.stationStr][self.streamNum])
self.streamInfo['Album']="" self.streamInfo['Album']=""
self.streamInfo['Genre']=""
except: except:
print("general error in the musicbrainz routine") print("general error in the musicbrainz routine")
#pass #pass