Metatdata caching and Strict Queries

Added the ability to specify whether MusicBrainz queries are strict or not in the Settings. Default is True.
Also added metadata caching of track info. This will update the Album and Genre (if available) data in the display for already downloaded Album Art.
This commit is contained in:
markjfine 2021-04-27 15:58:09 -04:00 committed by GitHub
parent a41013c6b1
commit 97967af9ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -110,6 +110,7 @@ class NRSC5_DUI(object):
self.bookmarks = [] # station bookmarks self.bookmarks = [] # station bookmarks
self.booknames = ["","","",""] # station bookmark names self.booknames = ["","","",""] # station bookmark names
self.stationLogos = {} # station logos self.stationLogos = {} # station logos
self.coverMetas = {} # cover metadata
self.bookmarked = False # is current station bookmarked self.bookmarked = False # is current station bookmarked
self.mapViewer = None # map viewer window self.mapViewer = None # map viewer window
self.weatherMaps = [] # list of current weathermaps sorted by time self.weatherMaps = [] # list of current weathermaps sorted by time
@ -305,6 +306,8 @@ class NRSC5_DUI(object):
dlCoversSet = self.cbCovers.get_active() dlCoversSet = self.cbCovers.get_active()
self.lblCoverIncl.set_sensitive(dlCoversSet) self.lblCoverIncl.set_sensitive(dlCoversSet)
self.cbCoverIncl.set_sensitive(dlCoversSet) self.cbCoverIncl.set_sensitive(dlCoversSet)
self.lblStrict.set_sensitive(dlCoversSet)
self.cbStrict.set_sensitive(dlCoversSet)
def img_to_pixbuf(self,img): def img_to_pixbuf(self,img):
"""convert PIL.Image to GdkPixbuf.Pixbuf""" """convert PIL.Image to GdkPixbuf.Pixbuf"""
@ -410,11 +413,15 @@ class NRSC5_DUI(object):
# 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().replace("'","") newArtist = self.fix_artist().replace("'","")
setStrict = (self.cbStrict.get_sensitive() and self.cbStrict.get_active())
#if setStrict:
searchArtist = newArtist searchArtist = newArtist
#searchArtist = artist=self.streamInfo["Artist"].replace("'","") #else:
#searchArtist = artist=self.streamInfo["Artist"].replace("'","").replace("/","ft.")
newTitle = self.streamInfo["Title"].replace("'","") newTitle = self.streamInfo["Title"].replace("'","")
baseStr = str(newArtist+" - "+self.streamInfo["Title"]) baseStr = str(newArtist+" - "+self.streamInfo["Title"]).replace(" ","_").replace("/","_").replace(":","_")+".jpg"
saveStr = os.path.join(aasDir, baseStr.replace(" ","_").replace("/","_").replace(":","_")+".jpg") saveStr = os.path.join(aasDir, baseStr)
if (newArtist=="") and (newTitle==""): if (newArtist=="") and (newTitle==""):
return return
@ -422,6 +429,9 @@ class NRSC5_DUI(object):
# does it already exist? # does it already exist?
if (os.path.isfile(saveStr)): if (os.path.isfile(saveStr)):
self.coverImage = saveStr self.coverImage = saveStr
if (baseStr in self.coverMetas):
self.streamInfo['Album'] = self.coverMetas[baseStr][2]
self.streamInfo['Genre'] = self.coverMetas[baseStr][3]
# if not, get it from MusicBrainz # if not, get it from MusicBrainz
else: else:
@ -433,7 +443,7 @@ class NRSC5_DUI(object):
#print("searching for {} - {}".format(searchArtist,newTitle)) #print("searching for {} - {}".format(searchArtist,newTitle))
try: try:
result = musicbrainzngs.search_recordings(strict=True, 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")
@ -494,6 +504,7 @@ class NRSC5_DUI(object):
imgSaved = True imgSaved = True
if (self.streamInfo['Album'] == ""): if (self.streamInfo['Album'] == ""):
self.streamInfo['Album']=resultAlbum self.streamInfo['Album']=resultAlbum
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
@ -1594,6 +1605,8 @@ class NRSC5_DUI(object):
self.cbCovers = builder.get_object("cbCovers") self.cbCovers = builder.get_object("cbCovers")
self.lblCoverIncl = builder.get_object("lblCoverIncl") self.lblCoverIncl = builder.get_object("lblCoverIncl")
self.cbCoverIncl = builder.get_object("cbCoverIncl") self.cbCoverIncl = builder.get_object("cbCoverIncl")
self.lblStrict = builder.get_object("lblStrict")
self.cbStrict = builder.get_object("cbStrict")
self.btnPlay = builder.get_object("btnPlay") self.btnPlay = builder.get_object("btnPlay")
self.btnStop = builder.get_object("btnStop") self.btnStop = builder.get_object("btnStop")
self.btnBookmark = builder.get_object("btnBookmark") self.btnBookmark = builder.get_object("btnBookmark")
@ -1757,16 +1770,29 @@ class NRSC5_DUI(object):
# load station logos # load station logos
try: try:
with open(os.path.join(cfgDir,"stationLogos.json"), mode='r') as f: stationLogos = os.path.join(cfgDir,"stationLogos.json")
if (os.path.isfile(stationLogos)):
with open(stationLogos, mode='r') as f:
self.stationLogos = json.load(f) self.stationLogos = json.load(f)
except: except:
self.debugLog("Error: Unable to load station logo database", True) self.debugLog("Error: Unable to load station logo database", True)
#load cover metadata
try:
coverMetas = os.path.join(cfgDir,"coverMetas.json")
if (os.path.isfile(coverMetas)):
with open(coverMetas, mode='r') as f:
self.coverMetas = json.load(f)
except:
self.debugLog("Error: Unable to load cover metadata database", True)
self.mainWindow.resize(self.defaultSize[0],self.defaultSize[1]) self.mainWindow.resize(self.defaultSize[0],self.defaultSize[1])
# load settings # load settings
try: try:
with open(os.path.join(cfgDir,"config.json"), mode='r') as f: configFile = os.path.join(cfgDir,"config.json")
if (os.path.isfile(configFile)):
with open(configFile, mode='r') as f:
config = json.load(f) config = json.load(f)
if "MapData" in config: if "MapData" in config:
@ -1799,6 +1825,8 @@ class NRSC5_DUI(object):
self.cbCovers.set_active(config["DLoadArt"]) self.cbCovers.set_active(config["DLoadArt"])
if ("StationArt" in config): if ("StationArt" in config):
self.cbCoverIncl.set_active(config["StationArt"]) self.cbCoverIncl.set_active(config["StationArt"])
if ("StrictQ" in config):
self.cbStrict.set_active(config["StrictQ"])
if ("UseIP" in config): if ("UseIP" in config):
self.cbDevIP.set_active(config["UseIP"]) self.cbDevIP.set_active(config["UseIP"])
if ("DevIP" in config): if ("DevIP" in config):
@ -1885,6 +1913,7 @@ class NRSC5_DUI(object):
"LogToFile" : self.cbLog.get_active(), "LogToFile" : self.cbLog.get_active(),
"DLoadArt" : self.cbCovers.get_active(), "DLoadArt" : self.cbCovers.get_active(),
"StationArt" : self.cbCoverIncl.get_active(), "StationArt" : self.cbCoverIncl.get_active(),
"StrictQ" : self.cbStrict.get_active(),
"UseIP" : self.cbDevIP.get_active(), "UseIP" : self.cbDevIP.get_active(),
"Bookmarks" : self.bookmarks, "Bookmarks" : self.bookmarks,
"MapData" : self.mapData, "MapData" : self.mapData,
@ -1896,6 +1925,9 @@ class NRSC5_DUI(object):
with open(os.path.join(cfgDir,"stationLogos.json"), mode='w') as f: with open(os.path.join(cfgDir,"stationLogos.json"), mode='w') as f:
json.dump(self.stationLogos, f, indent=2) json.dump(self.stationLogos, f, indent=2)
with open(os.path.join(cfgDir,"coverMetas.json"), mode='w') as f:
json.dump(self.coverMetas, f, indent=2)
except: except:
self.debugLog("Error: Unable to save config", True) self.debugLog("Error: Unable to save config", True)