mirror of
https://github.com/beetbox/beets.git
synced 2026-01-04 23:12:51 +01:00
cleaning up, renaming dup_XXInfo() to copy()
This commit is contained in:
parent
370df6253d
commit
7c71bb87a2
4 changed files with 44 additions and 81 deletions
|
|
@ -80,9 +80,9 @@ class AlbumInfo(AttrDict):
|
|||
``mediums`` along with the fields up through ``tracks`` are required.
|
||||
The others are optional and may be None.
|
||||
"""
|
||||
def __init__(self, album=None, album_id=None, artist=None, artist_id=None,
|
||||
tracks=None, asin=None, albumtype=None, va=False, year=None,
|
||||
month=None, day=None, label=None, mediums=None,
|
||||
def __init__(self, tracks, album=None, album_id=None, artist=None,
|
||||
artist_id=None, asin=None, albumtype=None, va=False,
|
||||
year=None, month=None, day=None, label=None, mediums=None,
|
||||
artist_sort=None, releasegroup_id=None, catalognum=None,
|
||||
script=None, language=None, country=None, style=None,
|
||||
genre=None, albumstatus=None, media=None, albumdisambig=None,
|
||||
|
|
@ -144,18 +144,13 @@ class AlbumInfo(AttrDict):
|
|||
if isinstance(value, bytes):
|
||||
setattr(self, fld, value.decode(codec, 'ignore'))
|
||||
|
||||
if 'tracks' in self:
|
||||
for track in self.tracks:
|
||||
track.decode(codec)
|
||||
for track in self.tracks:
|
||||
track.decode(codec)
|
||||
|
||||
def dup_albuminfo(self):
|
||||
dupe = AlbumInfo()
|
||||
def copy(self):
|
||||
dupe = AlbumInfo([])
|
||||
dupe.update(self)
|
||||
if 'tracks' in self:
|
||||
tracks = []
|
||||
for track in self.tracks:
|
||||
tracks.append(track.dup_trackinfo())
|
||||
dupe.tracks = tracks
|
||||
dupe.tracks = [track.copy() for track in self.tracks]
|
||||
return dupe
|
||||
|
||||
|
||||
|
|
@ -219,7 +214,7 @@ class TrackInfo(AttrDict):
|
|||
if isinstance(value, bytes):
|
||||
setattr(self, fld, value.decode(codec, 'ignore'))
|
||||
|
||||
def dup_trackinfo(self):
|
||||
def copy(self):
|
||||
dupe = TrackInfo()
|
||||
dupe.update(self)
|
||||
return dupe
|
||||
|
|
|
|||
|
|
@ -357,17 +357,13 @@ class DiscogsPlugin(BeetsPlugin):
|
|||
original_year = self.get_master_year(master_id) if master_id else year
|
||||
|
||||
return AlbumInfo(album=album, album_id=album_id, artist=artist,
|
||||
artist_id=artist_id, tracks=tracks, asin=None,
|
||||
albumtype=albumtype, va=va, year=year, month=None,
|
||||
day=None, label=label, mediums=len(set(mediums)),
|
||||
artist_sort=None, releasegroup_id=master_id,
|
||||
catalognum=catalogno, script=None, language=None,
|
||||
artist_id=artist_id, tracks=tracks,
|
||||
albumtype=albumtype, va=va, year=year,
|
||||
label=label, mediums=len(set(mediums)),
|
||||
releasegroup_id=master_id, catalognum=catalogno,
|
||||
country=country, style=style, genre=genre,
|
||||
albumstatus=None, media=media,
|
||||
albumdisambig=None, artist_credit=None,
|
||||
original_year=original_year, original_month=None,
|
||||
original_day=None, data_source='Discogs',
|
||||
data_url=data_url,
|
||||
media=media, original_year=original_year,
|
||||
data_source='Discogs', data_url=data_url,
|
||||
discogs_albumid=discogs_albumid,
|
||||
discogs_labelid=labelid, discogs_artistid=artist_id)
|
||||
|
||||
|
|
@ -570,8 +566,7 @@ class DiscogsPlugin(BeetsPlugin):
|
|||
length = self.get_track_length(track['duration'])
|
||||
return TrackInfo(title=title, track_id=track_id, artist=artist,
|
||||
artist_id=artist_id, length=length, index=index,
|
||||
medium=medium, medium_index=medium_index,
|
||||
artist_sort=None, disctitle=None, artist_credit=None)
|
||||
medium=medium, medium_index=medium_index)
|
||||
|
||||
def get_track_index(self, position):
|
||||
"""Returns the medium, medium index and subtrack index for a discogs
|
||||
|
|
|
|||
|
|
@ -350,9 +350,7 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
va=False
|
||||
)
|
||||
self.assertEqual(self._dist(items, info), 0)
|
||||
|
||||
|
|
@ -364,9 +362,7 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
va=False
|
||||
)
|
||||
dist = self._dist(items, info)
|
||||
self.assertNotEqual(dist, 0)
|
||||
|
|
@ -382,9 +378,7 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
artist=u'someone else',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
va=False
|
||||
)
|
||||
self.assertNotEqual(self._dist(items, info), 0)
|
||||
|
||||
|
|
@ -397,9 +391,7 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
artist=u'should be ignored',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=True,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
va=True
|
||||
)
|
||||
self.assertEqual(self._dist(items, info), 0)
|
||||
|
||||
|
|
@ -413,9 +405,7 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
artist=u'should be ignored',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=True,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
va=True
|
||||
)
|
||||
info.tracks[0].artist = None
|
||||
info.tracks[1].artist = None
|
||||
|
|
@ -431,9 +421,7 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=True,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
va=True
|
||||
)
|
||||
self.assertNotEqual(self._dist(items, info), 0)
|
||||
|
||||
|
|
@ -446,9 +434,7 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
va=False
|
||||
)
|
||||
dist = self._dist(items, info)
|
||||
self.assertTrue(0 < dist < 0.2)
|
||||
|
|
@ -462,9 +448,7 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
va=False
|
||||
)
|
||||
info.tracks[0].medium_index = 1
|
||||
info.tracks[1].medium_index = 2
|
||||
|
|
@ -481,9 +465,7 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
va=False
|
||||
)
|
||||
info.tracks[0].medium_index = 1
|
||||
info.tracks[1].medium_index = 2
|
||||
|
|
@ -505,9 +487,9 @@ class AssignmentTest(unittest.TestCase):
|
|||
items.append(self.item(u'three', 2))
|
||||
items.append(self.item(u'two', 3))
|
||||
trackinfo = []
|
||||
trackinfo.append(TrackInfo(title=u'one', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'two', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'three', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'one'))
|
||||
trackinfo.append(TrackInfo(title=u'two'))
|
||||
trackinfo.append(TrackInfo(title=u'three'))
|
||||
mapping, extra_items, extra_tracks = \
|
||||
match.assign_items(items, trackinfo)
|
||||
self.assertEqual(extra_items, [])
|
||||
|
|
@ -524,9 +506,9 @@ class AssignmentTest(unittest.TestCase):
|
|||
items.append(self.item(u'three', 1))
|
||||
items.append(self.item(u'two', 1))
|
||||
trackinfo = []
|
||||
trackinfo.append(TrackInfo(title=u'one', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'two', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'three', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'one'))
|
||||
trackinfo.append(TrackInfo(title=u'two'))
|
||||
trackinfo.append(TrackInfo(title=u'three'))
|
||||
mapping, extra_items, extra_tracks = \
|
||||
match.assign_items(items, trackinfo)
|
||||
self.assertEqual(extra_items, [])
|
||||
|
|
@ -542,9 +524,9 @@ class AssignmentTest(unittest.TestCase):
|
|||
items.append(self.item(u'one', 1))
|
||||
items.append(self.item(u'three', 3))
|
||||
trackinfo = []
|
||||
trackinfo.append(TrackInfo(title=u'one', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'two', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'three', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'one'))
|
||||
trackinfo.append(TrackInfo(title=u'two'))
|
||||
trackinfo.append(TrackInfo(title=u'three'))
|
||||
mapping, extra_items, extra_tracks = \
|
||||
match.assign_items(items, trackinfo)
|
||||
self.assertEqual(extra_items, [])
|
||||
|
|
@ -560,8 +542,8 @@ class AssignmentTest(unittest.TestCase):
|
|||
items.append(self.item(u'two', 2))
|
||||
items.append(self.item(u'three', 3))
|
||||
trackinfo = []
|
||||
trackinfo.append(TrackInfo(title=u'one', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'three', track_id=None))
|
||||
trackinfo.append(TrackInfo(title=u'one'))
|
||||
trackinfo.append(TrackInfo(title=u'three'))
|
||||
mapping, extra_items, extra_tracks = \
|
||||
match.assign_items(items, trackinfo)
|
||||
self.assertEqual(extra_items, [items[1]])
|
||||
|
|
@ -597,7 +579,7 @@ class AssignmentTest(unittest.TestCase):
|
|||
items.append(item(12, 186.45916150485752))
|
||||
|
||||
def info(index, title, length):
|
||||
return TrackInfo(title=title, track_id=None, length=length,
|
||||
return TrackInfo(title=title, length=length,
|
||||
index=index)
|
||||
trackinfo = []
|
||||
trackinfo.append(info(1, u'Alone', 238.893))
|
||||
|
|
@ -752,15 +734,13 @@ class ApplyTest(_common.TestCase, ApplyTestUtil):
|
|||
self.assertEqual(self.items[1].albumtype, 'album')
|
||||
|
||||
def test_album_artist_overrides_empty_track_artist(self):
|
||||
# make a deepcopy of self.info
|
||||
my_info = self.info.dup_albuminfo()
|
||||
my_info = self.info.copy()
|
||||
self._apply(info=my_info)
|
||||
self.assertEqual(self.items[0].artist, 'artistNew')
|
||||
self.assertEqual(self.items[1].artist, 'artistNew')
|
||||
|
||||
def test_album_artist_overridden_by_nonempty_track_artist(self):
|
||||
# make a deepcopy of self.info
|
||||
my_info = self.info.dup_albuminfo()
|
||||
my_info = self.info.copy()
|
||||
my_info.tracks[0].artist = 'artist1!'
|
||||
my_info.tracks[1].artist = 'artist2!'
|
||||
self._apply(info=my_info)
|
||||
|
|
@ -782,8 +762,7 @@ class ApplyTest(_common.TestCase, ApplyTestUtil):
|
|||
self.assertEqual(self.items[1].artist_sort, 'albumArtistSort')
|
||||
|
||||
def test_full_date_applied(self):
|
||||
# make a deepcopy of self.info
|
||||
my_info = self.info.dup_albuminfo()
|
||||
my_info = self.info.copy()
|
||||
my_info.year = 2013
|
||||
my_info.month = 12
|
||||
my_info.day = 18
|
||||
|
|
@ -798,8 +777,7 @@ class ApplyTest(_common.TestCase, ApplyTestUtil):
|
|||
self.items.append(Item(year=1, month=2, day=3))
|
||||
self.items.append(Item(year=4, month=5, day=6))
|
||||
|
||||
# make a deepcopy of self.info
|
||||
my_info = self.info.dup_albuminfo()
|
||||
my_info = self.info.copy()
|
||||
my_info.year = 2013
|
||||
self._apply(info=my_info)
|
||||
|
||||
|
|
@ -819,8 +797,7 @@ class ApplyTest(_common.TestCase, ApplyTestUtil):
|
|||
self.assertEqual(self.items[0].day, 3)
|
||||
|
||||
def test_data_source_applied(self):
|
||||
# make a deepcopy of self.info
|
||||
my_info = self.info.dup_albuminfo()
|
||||
my_info = self.info.copy()
|
||||
my_info.data_source = 'MusicBrainz'
|
||||
self._apply(info=my_info)
|
||||
|
||||
|
|
@ -882,8 +859,7 @@ class ApplyCompilationTest(_common.TestCase, ApplyTestUtil):
|
|||
self.assertFalse(self.items[1].comp)
|
||||
|
||||
def test_va_flag_sets_comp(self):
|
||||
# make a deepcopy of self.info
|
||||
va_info = self.info.dup_albuminfo()
|
||||
va_info = self.info.copy()
|
||||
va_info.va = True
|
||||
self._apply(info=va_info)
|
||||
self.assertTrue(self.items[0].comp)
|
||||
|
|
|
|||
|
|
@ -1138,10 +1138,7 @@ class SummarizeItemsTest(_common.TestCase):
|
|||
self.assertEqual(summary, u"1 items, F, 4kbps, 10:54, 987.0 B")
|
||||
|
||||
# make a copy of self.item
|
||||
i2 = library.Item()
|
||||
i2.bitrate = 4321
|
||||
i2.length = 10 * 60 + 54
|
||||
i2.format = "F"
|
||||
i2 = self.item.copy()
|
||||
|
||||
summary = commands.summarize_items([self.item, i2], False)
|
||||
self.assertEqual(summary, u"2 items, F, 4kbps, 21:48, 1.9 KiB")
|
||||
|
|
|
|||
Loading…
Reference in a new issue