fix autotagging of artist !!! via special-casing it

This commit is contained in:
Adrian Sampson 2010-09-18 10:51:16 -07:00
parent 8c159fa2f0
commit b565a3afd4
3 changed files with 41 additions and 0 deletions

1
NEWS
View file

@ -16,6 +16,7 @@
.beetsconfig.
* Fixed bug that completely broke non-autotagged imports ("import -A").
* Fixed bug that logged the wrong paths when using "import -l".
* Fixed autotagging for the creatively-named band !!!.
* A new "-v" command line switch enables debugging output.
1.0b4

View file

@ -31,6 +31,11 @@ SEARCH_LIMIT = 10
class ServerBusyError(Exception): pass
# We hard-code IDs for artists that can't easily be searched for.
SPECIAL_CASE_ARTISTS = {
'!!!': 'f26c72d3-e52c-467b-b651-679c73d8e1a7',
}
# MusicBrainz requires that a client does not query the server more
# than once a second. This function enforces that limit using a
# module-global variable to keep track of the last time a query was
@ -72,9 +77,18 @@ def get_releases(**params):
"""Given a list of parameters to ReleaseFilter, executes the
query and yields release dicts (complete with tracks).
"""
# Replace special cases.
if 'artistName' in params:
artist = params['artistName']
if artist in SPECIAL_CASE_ARTISTS:
del params['artistName']
params['artistId'] = SPECIAL_CASE_ARTISTS[artist]
# Issue query.
filt = mbws.ReleaseFilter(**params)
results = _query_wrap(mbws.Query().getReleases, filter=filt)
# Construct results.
for result in results:
release = result.release
tracks, _ = release_info(release.id)
@ -109,6 +123,13 @@ def find_releases(criteria, limit=SEARCH_LIMIT):
is detailed here:
http://wiki.musicbrainz.org/Text_Search_Syntax
"""
# Replace special cases.
if 'artist' in criteria:
artist = criteria['artist']
if artist in SPECIAL_CASE_ARTISTS:
del criteria['artist']
criteria['arid'] = SPECIAL_CASE_ARTISTS[artist]
# Build Lucene query (the MusicBrainz 'query' filter).
query_parts = []
for name, value in criteria.items():

View file

@ -148,6 +148,25 @@ class ByIDTest(unittest.TestCase):
a = mb.album_for_id('bogus-id')
self.assertEqual(a, None)
class SpecialCaseTest(unittest.TestCase):
def test_chkchkchk_by_query(self):
a = iter(mb.find_releases({
'artist': '!!!',
'album': '!!!',
'tracks': '7',
})).next()
self.assertEqual(a['artist'], '!!!')
self.assertEqual(a['album'], '!!!')
def test_chkchkchk_by_keys(self):
a = iter(mb.get_releases(
artistName='!!!',
title='!!!',
trackCount=7,
)).next()
self.assertEqual(a['artist'], '!!!')
self.assertEqual(a['album'], '!!!')
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)