From 5cfc7db7b16fd7fa1343f32d13fcb2b5fc3a8300 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 24 Jan 2011 08:57:49 -0800 Subject: [PATCH] move "various artists" detection from autotag module to mb --- beets/autotag/__init__.py | 5 +---- beets/autotag/mb.py | 4 +++- test/test_autotag.py | 17 +++++++++++++++-- test/test_mb.py | 11 +++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index c3ea00331..1e4036043 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -20,7 +20,6 @@ from collections import defaultdict from beets.autotag import mb import re from munkres import Munkres -from musicbrainz2.model import VARIOUS_ARTISTS_ID from beets import library, mediafile, plugins import logging @@ -73,8 +72,6 @@ SD_PATTERNS = [ (r'(, )?(pt\.|part) .+', 0.2), ] -VARIOUS_ARTISTS_ID = VARIOUS_ARTISTS_ID.rsplit('/', 1)[1] - # Autotagging exceptions. class AutotagError(Exception): pass @@ -386,7 +383,7 @@ def apply_metadata(items, info): item.albumtype = info['albumtype'] # Compilation flag. - item.comp = (info['artist_id'] == VARIOUS_ARTISTS_ID) + item.comp = info['va'] def match_by_id(items): """If the items are tagged with a MusicBrainz album ID, returns an diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 8ff80c093..9a34f0ab7 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -23,12 +23,13 @@ principal interface is the function `match_album`. from __future__ import with_statement # for Python 2.5 import re import time -import datetime import musicbrainz2.webservice as mbws from musicbrainz2.model import Release from threading import Lock +from musicbrainz2.model import VARIOUS_ARTISTS_ID SEARCH_LIMIT = 10 +VARIOUS_ARTISTS_ID = VARIOUS_ARTISTS_ID.rsplit('/', 1)[1] class ServerBusyError(Exception): pass @@ -170,6 +171,7 @@ def release_dict(release, tracks=None): 'asin': release.asin, 'albumtype': '', } + out['va'] = out['artist_id'] == VARIOUS_ARTISTS_ID # Release type not always populated. for releasetype in release.types: diff --git a/test/test_autotag.py b/test/test_autotag.py index 60725be83..4ce263629 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -204,6 +204,7 @@ class ApplyTest(unittest.TestCase): 'album_id': '7edb51cb-77d6-4416-a23c-3a8c2994a2c7', 'artist_id': 'a6623d39-2d8e-4f70-8242-0a9553b91e50', 'albumtype': 'album', + 'va': False, } def test_titles_applied(self): @@ -273,6 +274,7 @@ class ApplyCompilationTest(unittest.TestCase): 'album_id': '3b69ea40-39b8-487f-8818-04b6eff8c21a', 'artist_id': '89ad4ac3-39f7-470e-963a-56509c546377', 'albumtype': 'compilation', + 'va': False, } def test_album_and_track_artists_separate(self): @@ -282,13 +284,25 @@ class ApplyCompilationTest(unittest.TestCase): self.assertEqual(self.items[0].albumartist, 'variousNew') self.assertEqual(self.items[1].albumartist, 'variousNew') - def test_mb_albumartistid__applied(self): + def test_mb_albumartistid_applied(self): autotag.apply_metadata(self.items, self.info) self.assertEqual(self.items[0].mb_albumartistid, '89ad4ac3-39f7-470e-963a-56509c546377') self.assertEqual(self.items[1].mb_albumartistid, '89ad4ac3-39f7-470e-963a-56509c546377') self.assertEqual(self.items[0].mb_artistid, 'a05686fc-9db2-4c23-b99e-77f5db3e5282') self.assertEqual(self.items[1].mb_artistid, '80b3cf5e-18fe-4c59-98c7-e5bb87210710') + def test_va_flag_cleared_does_not_set_comp(self): + autotag.apply_metadata(self.items, self.info) + self.assertFalse(self.items[0].comp) + self.assertFalse(self.items[1].comp) + + def test_va_flag_sets_comp(self): + va_info = dict(self.info) # make a copy + va_info['va'] = True + autotag.apply_metadata(self.items, va_info) + self.assertTrue(self.items[0].comp) + self.assertTrue(self.items[1].comp) + class StringDistanceTest(unittest.TestCase): def test_equal_strings(self): dist = autotag.string_dist('Some String', 'Some String') @@ -361,4 +375,3 @@ def suite(): if __name__ == '__main__': unittest.main(defaultTest='suite') - diff --git a/test/test_mb.py b/test/test_mb.py index 6f09228a0..a2d97fea0 100644 --- a/test/test_mb.py +++ b/test/test_mb.py @@ -131,6 +131,17 @@ class MBReleaseDictTest(unittest.TestCase): self.assertFalse('month' in d) self.assertFalse('day' in d) + def test_various_artists_defaults_false(self): + release = self._make_release(None) + d = mb.release_dict(release) + self.assertFalse(d['va']) + + def test_detect_various_artists(self): + release = self._make_release(None) + release.artist.id = musicbrainz2.model.VARIOUS_ARTISTS_ID + d = mb.release_dict(release) + self.assertTrue(d['va']) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)