Skip to content

Commit

Permalink
add tr/st test case to mb (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
aw-was-here committed Jul 3, 2023
1 parent effe1ae commit 90640fd
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
14 changes: 10 additions & 4 deletions nowplaying/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def _pickarecording(self, testdata, mbdata, allowothers=False): #pylint: disabl
continue
logging.debug('checking %s', recording['id'])
if riddata := self.recordingid(recording['id']):
logging.debug('selected %s', recording['id'])
return riddata

return riddata
Expand Down Expand Up @@ -114,6 +113,8 @@ def lastditcheffort(self, metadata):
riddata = self._pickarecording(addmeta, mydict)
if not riddata:
riddata = self._pickarecording(addmeta, mydict, allowothers=True)
logging.debug('metadata added artistid = %s / recordingid = %s',
riddata.get('musicbrainzartistid'), riddata.get('musicbrainzrecordingid'))
return riddata

def recognize(self, metadata):
Expand Down Expand Up @@ -295,7 +296,8 @@ def artistids(self, idlist):
return {'artistwebsites': self._websites(idlist)}

def _websites(self, idlist):
if not self.config.cparser.value('acoustidmb/websites', type=bool) or not idlist:

if not idlist:
return None

sitelist = []
Expand All @@ -321,8 +323,12 @@ def _websites(self, idlist):
for urlrel in webdata['artist']['url-relation-list']:
logging.debug('checking %s', urlrel['type'])
for src, dest in convdict.items():
if urlrel['type'] == src and self.config.cparser.value(f'acoustidmb/{dest}',
type=bool):
if self.config.cparser.value('discogs/enabled',
type=bool) and urlrel['type'] == 'discogs':
sitelist.append(urlrel['target'])
logging.debug('placed %s', dest)
elif urlrel['type'] == src and self.config.cparser.value(f'acoustidmb/{dest}',
type=bool):
sitelist.append(urlrel['target'])
logging.debug('placed %s', dest)

Expand Down
11 changes: 3 additions & 8 deletions nowplaying/recognition/acoustidmb.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,10 @@ def defaults(self, qsettings):
qsettings.setValue('acoustidmb/websites', False)
qsettings.setValue('musicbrainz/fallback', False)

for website in [
'bandcamp',
'homepage',
'lastfm',
'musicbrainz',
'discogs',
]:
for website in ['bandcamp', 'homepage', 'lastfm', 'musicbrainz']:
qsettings.setValue(f'acoustidmb/{website}', False)
qsettings.setValue('acoustidmb/homepage', True)

qsettings.setValue('acoustidmb/discogs', True)


def main():
Expand Down
31 changes: 31 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,34 @@ async def test_year_zerostr(bootstrap):
).getmoremetadata(metadata=metadatain
)
assert not metadataout.get('date')


@pytest.mark.asyncio
async def test_discogs_from_mb(bootstrap): # pylint: disable=redefined-outer-name
''' noimagecache '''

if not os.environ.get('DISCOGS_API_KEY'):
return

config = bootstrap
config.cparser.setValue('acoustidmb/homepage', False)
config.cparser.setValue('acoustidmb/enabled', False)
config.cparser.setValue('discogs/apikey', os.environ['DISCOGS_API_KEY'])
config.cparser.setValue('musicbrainz/enabled', True)
config.cparser.setValue('discogs/enabled', True)
config.cparser.setValue('discogs/bio', True)
config.cparser.setValue('musicbrainz/fallback', True)
metadatain = {'artist': 'TR/ST', 'title': 'Iris'}
logging.debug(config.cparser.value('acoustidmb/homepage', type=bool))
mdp = nowplaying.metadata.MetadataProcessors(config=config)
metadataout = await mdp.getmoremetadata(metadata=metadatain)
del metadataout['coverimageraw']
logging.debug(metadataout)
assert metadataout['album'] == 'Iris'
assert metadataout['artistwebsites'] == ['https://www.discogs.com/artist/2028711']
assert metadataout['artist'] == 'TR/ST'
assert metadataout['date'] == '2019-07-25'
assert metadataout['label'] == 'House Arrest'
assert metadataout['musicbrainzartistid'] == ['b8e3d1ae-5983-4af1-b226-aa009b294111']
assert metadataout['musicbrainzrecordingid'] == '9ecf96f5-dbba-4fda-a5cf-7728837fb1b6'
assert metadataout['title'] == 'Iris'
16 changes: 16 additions & 0 deletions tests/test_musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def getmusicbrainz(bootstrap):
config = bootstrap
config.cparser.setValue('acoustidmb/enabled', False)
config.cparser.setValue('musicbrainz/enabled', True)
config.cparser.setValue('acoustidmb/websites', True)
for site in ['bandcamp', 'homepage', 'lastfm', 'discogs']:
config.cparser.setValue(f'acoustidmb/{site}', True)
config.cparser.setValue('acoustidmb/emailaddress', 'aw+wnptest@effectivemachines.com')
return nowplaying.musicbrainz.MusicBrainzHelper(config=config)

Expand Down Expand Up @@ -159,3 +162,16 @@ def test_fallback7(getmusicbrainz): # pylint: disable=redefined-outer-name
#
assert newdata['musicbrainzartistid'] == ['09095919-c549-4f33-9555-70df9dd941e1']
assert newdata['album'] == 'The Perfect Girl'


def test_fallback8(getmusicbrainz): # pylint: disable=redefined-outer-name
''' automated integration test '''
mbhelper = getmusicbrainz
metadata = {'artist': 'TR/ST', 'title': 'Iris'}
newdata = mbhelper.lastditcheffort(metadata)
#
# Not the best choice, but passable
#
assert newdata['musicbrainzartistid'] == ['b8e3d1ae-5983-4af1-b226-aa009b294111']
assert newdata['musicbrainzrecordingid'] == '9ecf96f5-dbba-4fda-a5cf-7728837fb1b6'
assert newdata['album'] == 'Iris'

0 comments on commit 90640fd

Please sign in to comment.