Skip to content

Commit

Permalink
Fixes #1210: Skip non-audio tracks from MusicBrainz
Browse files Browse the repository at this point in the history
This ignores non-audio tracks during import:
- Data tracks, based on their title `[data track]` (which seems to be
the MusicBrainz convention, as there's no specific flag to indicate
that a track is a data one),
- Video tracks, based on the `video=true` attribute.

It's similar to the Picard changes mentioned in #1210, except it doesn't
deal with `[silence]` tracks: These ones will probably require a setting
to let the user control if they should be imported or not.
  • Loading branch information
nguillaumin committed Dec 31, 2017
1 parent a5fc80e commit 71b4d5c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
11 changes: 11 additions & 0 deletions beets/autotag/mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
NON_AUDIO_FORMATS = ['Data CD', 'DVD', 'DVD-Video', 'Blu-ray', 'HD-DVD', 'VCD',
'SVCD', 'UMD', 'VHS']

SKIPPED_TRACKS = ['[data track]']

musicbrainzngs.set_useragent('beets', beets.__version__,
'http://beets.io/')

Expand Down Expand Up @@ -286,6 +288,15 @@ def album_info(release):
all_tracks.insert(0, medium['pregap'])

for track in all_tracks:

if ('title' in track['recording'] and
track['recording']['title'] in SKIPPED_TRACKS):
continue

if ('video' in track['recording'] and
track['recording']['video'] == 'true'):
continue

# Basic information from the recording.
index += 1
ti = track_info(
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Changelog
Changelog goes here!

Fixes:

* Non-audio media (DVD-Video, etc.) are now skipped by the autotagger. :bug:`2688`
* Non-audio tracks (data tracks, video tracks, etc.) are now skipped by the
autotagger. :bug:`1210`


1.4.6 (December 21, 2017)
Expand Down
26 changes: 25 additions & 1 deletion test/test_mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _make_release(self, date_str='2009', tracks=None, track_length=None,
})
return release

def _make_track(self, title, tr_id, duration, artist=False):
def _make_track(self, title, tr_id, duration, artist=False, video=False):
track = {
'title': title,
'id': tr_id,
Expand All @@ -113,6 +113,8 @@ def _make_track(self, title, tr_id, duration, artist=False):
'name': 'RECORDING ARTIST CREDIT',
}
]
if video:
track['video'] = 'true'
return track

def test_parse_release_with_year(self):
Expand Down Expand Up @@ -345,6 +347,28 @@ def test_no_skip_dvd_audio(self):
d = mb.album_info(release)
self.assertEqual(len(d.tracks), 2)

def test_skip_data_track(self):
tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
self._make_track('[data track]', 'ID DATA TRACK',
100.0 * 1000.0),
self._make_track('TITLE TWO', 'ID TWO', 200.0 * 1000.0)]
release = self._make_release(tracks=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_skip_video_track(self):
tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
self._make_track('TITLE VIDEO', 'ID VIDEO', 100.0 * 1000.0,
False, True),
self._make_track('TITLE TWO', 'ID TWO', 200.0 * 1000.0)]
release = self._make_release(tracks=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')


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

0 comments on commit 71b4d5c

Please sign in to comment.