Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take the audio tracks in a data track into account. #1638

Merged
merged 8 commits into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion beets/autotag/mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ def album_info(release):
continue

all_tracks = medium['track-list']
if 'data-track-list' in medium:
all_tracks += medium['data-track-list']
track_count = len(all_tracks)

if 'pregap' in medium:
all_tracks.insert(0, medium['pregap'])

Expand All @@ -302,7 +306,7 @@ def album_info(release):
index,
int(medium['position']),
int(track['position']),
len(medium['track-list']),
track_count,
)
ti.disctitle = disctitle
ti.media = format
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ Fixes:
to which a track belongs, not the total number of different mediums present
on the release. :bug:`2887`
Thanks to :user:`dbogdanov`.
* The importer now supports audio files contained in data tracks when they are
listed in MusicBrainz: the corresponding audio tracks are now merged into the
main track list. Thanks to :user:`jdetrey`. :bug:`1638`
* :doc:`/plugins/keyfinder`: Avoid a crash when trying to process unmatched
tracks. :bug:`2537`

Expand Down
63 changes: 55 additions & 8 deletions test/test_mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

class MBAlbumInfoTest(_common.TestCase):
def _make_release(self, date_str='2009', tracks=None, track_length=None,
track_artist=False, medium_format='FORMAT'):
track_artist=False, data_tracks=None,
medium_format='FORMAT'):
release = {
'title': 'ALBUM TITLE',
'id': 'ALBUM ID',
Expand Down Expand Up @@ -62,8 +63,8 @@ def _make_release(self, date_str='2009', tracks=None, track_length=None,
'country': 'COUNTRY',
'status': 'STATUS',
}
track_list = []
if tracks:
track_list = []
for i, recording in enumerate(tracks):
track = {
'recording': recording,
Expand All @@ -87,12 +88,22 @@ def _make_release(self, date_str='2009', tracks=None, track_length=None,
}
]
track_list.append(track)
release['medium-list'].append({
'position': '1',
'track-list': track_list,
'format': medium_format,
'title': 'MEDIUM TITLE',
})
data_track_list = []
if data_tracks:
for i, recording in enumerate(data_tracks):
data_track = {
'recording': recording,
'position': len(track_list) + i + 1,
'number': 'A1',
}
data_track_list.append(data_track)
release['medium-list'].append({
'position': '1',
'track-list': track_list,
'data-track-list': data_track_list,
'format': medium_format,
'title': 'MEDIUM TITLE',
})
return release

def _make_track(self, title, tr_id, duration, artist=False, video=False):
Expand Down Expand Up @@ -354,6 +365,18 @@ def test_skip_data_track(self):
self.assertEqual(d.tracks[0].title, 'TITLE ONE')
self.assertEqual(d.tracks[1].title, 'TITLE TWO')

def test_no_skip_audio_data_tracks(self):
tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
self._make_track('TITLE TWO', 'ID TWO', 200.0 * 1000.0)]
data_tracks = [self._make_track('TITLE AUDIO DATA', 'ID DATA TRACK',
100.0 * 1000.0)]
release = self._make_release(tracks=tracks, data_tracks=data_tracks)
d = mb.album_info(release)
self.assertEqual(len(d.tracks), 3)
self.assertEqual(d.tracks[0].title, 'TITLE ONE')
self.assertEqual(d.tracks[1].title, 'TITLE TWO')
self.assertEqual(d.tracks[2].title, 'TITLE AUDIO DATA')

def test_skip_video_tracks_by_default(self):
tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
self._make_track('TITLE VIDEO', 'ID VIDEO', 100.0 * 1000.0,
Expand All @@ -365,6 +388,17 @@ def test_skip_video_tracks_by_default(self):
self.assertEqual(d.tracks[0].title, 'TITLE ONE')
self.assertEqual(d.tracks[1].title, 'TITLE TWO')

def test_skip_video_data_tracks_by_default(self):
tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
self._make_track('TITLE TWO', 'ID TWO', 200.0 * 1000.0)]
data_tracks = [self._make_track('TITLE VIDEO', 'ID VIDEO',
100.0 * 1000.0, False, True)]
release = self._make_release(tracks=tracks, data_tracks=data_tracks)
d = mb.album_info(release)
self.assertEqual(len(d.tracks), 2)
self.assertEqual(d.tracks[0].title, 'TITLE ONE')
self.assertEqual(d.tracks[1].title, 'TITLE TWO')

def test_no_skip_video_tracks_if_configured(self):
config['match']['ignore_video_tracks'] = False
tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
Expand All @@ -378,6 +412,19 @@ def test_no_skip_video_tracks_if_configured(self):
self.assertEqual(d.tracks[1].title, 'TITLE VIDEO')
self.assertEqual(d.tracks[2].title, 'TITLE TWO')

def test_no_skip_video_data_tracks_if_configured(self):
config['match']['ignore_video_tracks'] = False
tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
self._make_track('TITLE TWO', 'ID TWO', 200.0 * 1000.0)]
data_tracks = [self._make_track('TITLE VIDEO', 'ID VIDEO',
100.0 * 1000.0, False, True)]
release = self._make_release(tracks=tracks, data_tracks=data_tracks)
d = mb.album_info(release)
self.assertEqual(len(d.tracks), 3)
self.assertEqual(d.tracks[0].title, 'TITLE ONE')
self.assertEqual(d.tracks[1].title, 'TITLE TWO')
self.assertEqual(d.tracks[2].title, 'TITLE VIDEO')


class ParseIDTest(_common.TestCase):
def test_parse_id_correct(self):
Expand Down