mirror of
https://github.com/beetbox/beets.git
synced 2026-01-08 00:45:55 +01:00
move "various artists" detection from autotag module to mb
This commit is contained in:
parent
0c24376e6a
commit
5cfc7db7b1
4 changed files with 30 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
|
|
@ -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__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue