mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-24 00:26:08 +00:00
Reduce search/lookup code redundancy
- drop filelookup.<entity>_search() - rename filelookup._search() to filelookup.search_entity() - use a dict to describe different possibilities in tagger.search() - use filelookup.search_entity() instead of building a methode name to call
This commit is contained in:
@@ -115,7 +115,7 @@ class FileLookup(object):
|
||||
def collection_lookup(self, userid):
|
||||
return self._build_launch('/user/%s/collections' % userid)
|
||||
|
||||
def _search(self, type_, query, adv=False):
|
||||
def search_entity(self, type_, query, adv=False):
|
||||
if self.mbid_lookup(query, type_):
|
||||
return True
|
||||
params = {
|
||||
@@ -126,12 +126,3 @@ class FileLookup(object):
|
||||
if adv:
|
||||
params['adv'] = 'on'
|
||||
return self._build_launch('/search/textsearch', params)
|
||||
|
||||
def artist_search(self, query, adv=False):
|
||||
return self._search('artist', query, adv)
|
||||
|
||||
def album_search(self, query, adv=False):
|
||||
return self._search('release', query, adv)
|
||||
|
||||
def track_search(self, query, adv=False):
|
||||
return self._search('recording', query, adv)
|
||||
|
||||
@@ -482,22 +482,31 @@ class Tagger(QtWidgets.QApplication):
|
||||
|
||||
def search(self, text, search_type, adv=False):
|
||||
"""Search on the MusicBrainz website."""
|
||||
search_types = {
|
||||
'track': {
|
||||
'entity': 'recording',
|
||||
'dialog': TrackSearchDialog
|
||||
},
|
||||
'album': {
|
||||
'entity': 'release',
|
||||
'dialog': AlbumSearchDialog
|
||||
},
|
||||
'artist': {
|
||||
'entity': 'artist',
|
||||
'dialog': ArtistSearchDialog
|
||||
},
|
||||
}
|
||||
if search_type not in search_types:
|
||||
return
|
||||
search = search_types[search_type]
|
||||
lookup = self.get_file_lookup()
|
||||
if config.setting["builtin_search"]:
|
||||
if search_type == "track" and not lookup.mbid_lookup(text, 'recording'):
|
||||
dialog = TrackSearchDialog(self.window)
|
||||
dialog.search(text)
|
||||
dialog.exec_()
|
||||
elif search_type == "album" and not lookup.mbid_lookup(text, 'release'):
|
||||
dialog = AlbumSearchDialog(self.window)
|
||||
dialog.search(text)
|
||||
dialog.exec_()
|
||||
elif search_type == "artist" and not lookup.mbid_lookup(text, 'artist'):
|
||||
dialog = ArtistSearchDialog(self.window)
|
||||
if not lookup.mbid_lookup(text, search['entity']):
|
||||
dialog = search['dialog'](self.window)
|
||||
dialog.search(text)
|
||||
dialog.exec_()
|
||||
else:
|
||||
getattr(lookup, search_type + "_search")(text, adv)
|
||||
lookup.search_entity(search['entity'], text, adv)
|
||||
|
||||
def collection_lookup(self):
|
||||
"""Lookup the users collections on the MusicBrainz website."""
|
||||
|
||||
Reference in New Issue
Block a user