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:
parent
a56ebb5e1d
commit
2ec6f0331a
38
nrsc5-dui.py
38
nrsc5-dui.py
@ -415,9 +415,7 @@ class NRSC5_DUI(object):
|
||||
newArtist = self.fix_artist().replace("'","’")
|
||||
|
||||
setStrict = (self.cbStrict.get_sensitive() and self.cbStrict.get_active())
|
||||
#if setStrict:
|
||||
searchArtist = newArtist
|
||||
#else:
|
||||
#searchArtist = artist=self.streamInfo["Artist"].replace("'","’").replace("/","ft.")
|
||||
newTitle = self.streamInfo["Title"].replace("'","’")
|
||||
baseStr = str(newArtist+" - "+self.streamInfo["Title"]).replace(" ","_").replace("/","_").replace(":","_")+".jpg"
|
||||
@ -437,20 +435,30 @@ class NRSC5_DUI(object):
|
||||
else:
|
||||
try:
|
||||
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
|
||||
|
||||
#print()
|
||||
#print("searching for {} - {}".format(searchArtist,newTitle))
|
||||
print("searching for {} - {}".format(searchArtist,newTitle))
|
||||
|
||||
try:
|
||||
result = musicbrainzngs.search_recordings(strict=setStrict, artist=searchArtist, recording=newTitle, type='Album', status='Official')
|
||||
#print("recording search succeeded")
|
||||
print("recording search succeeded")
|
||||
except:
|
||||
print("MusicBrainz recording search error")
|
||||
#pass
|
||||
|
||||
if (result is not None) and ('recording-list' in result):
|
||||
#print("got recording search result with {} recordings".format(len(result['recording-list'])))
|
||||
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'])))
|
||||
|
||||
# loop through the list until you get a match
|
||||
for (idx, release) in enumerate(result['recording-list']):
|
||||
@ -473,7 +481,7 @@ class NRSC5_DUI(object):
|
||||
releaseMatch = False
|
||||
imageMatch = False
|
||||
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']):
|
||||
#print(release2)
|
||||
imageMatch = False
|
||||
@ -488,7 +496,7 @@ class NRSC5_DUI(object):
|
||||
#artistMatch2 = (resultArtist2 != "") and (not ('Various' in resultArtist2))
|
||||
artistMatch2 = (not ('Various' in resultArtist2))
|
||||
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
|
||||
if releaseMatch:
|
||||
imageMatch = self.check_musicbrainz_cover(resultID)
|
||||
@ -498,22 +506,30 @@ class NRSC5_DUI(object):
|
||||
if (recordingMatch and releaseMatch and imageMatch):
|
||||
|
||||
# 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):
|
||||
self.coverImage = saveStr
|
||||
imgSaved = True
|
||||
if (self.streamInfo['Album'] == ""):
|
||||
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"]]
|
||||
|
||||
if (imgSaved) and ((idx+1) < len(result['recording-list'])) or (not scoreMatch):
|
||||
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 (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.streamInfo['Album']=""
|
||||
self.streamInfo['Genre']=""
|
||||
except:
|
||||
print("general error in the musicbrainz routine")
|
||||
#pass
|
||||
|
Loading…
Reference in New Issue
Block a user