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

Fixes #1210: Skip non-audio tracks from MusicBrainz #2776

Merged
merged 3 commits into from
Jan 1, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 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,16 @@ 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' and
config['match']['ignore_video_tracks'].get(bool) is True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for is True—calling .get(bool) is guaranteed to return a bool.

In fact, it's actually possible to drop that part too—Confit automatically gets the truthiness of a view when it's used as a boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I changed it

continue

# Basic information from the recording.
index += 1
ti = track_info(
Expand Down
1 change: 1 addition & 0 deletions beets/config_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ match:
original_year: no
ignored: []
required: []
ignore_video_tracks: yes
track_length_grace: 10
track_length_max: 30
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
11 changes: 11 additions & 0 deletions docs/reference/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,17 @@ want to enforce to the ``required`` setting::

No tags are required by default.

.. _ignore_video_tracks:

ignore_video_tracks
~~~~~~~~~~~~~~~~~~~

By default, video tracks within a release will be ignored. If you want them to
be included (for example if you would like to track the audio-only versions of
the video tracks), set it to ``no``.

Default: ``yes``.

.. _path-format-config:

Path Format Configuration
Expand Down
39 changes: 38 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,41 @@ 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_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,
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')

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),
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), 3)
self.assertEqual(d.tracks[0].title, 'TITLE ONE')
self.assertEqual(d.tracks[1].title, 'TITLE VIDEO')
self.assertEqual(d.tracks[2].title, 'TITLE TWO')


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