From 71b4d5c7023a8c20d1308f05a70ba1d6f7882949 Mon Sep 17 00:00:00 2001 From: Nicolas Guillaumin Date: Sat, 30 Dec 2017 19:18:07 -0800 Subject: [PATCH 1/3] Fixes #1210: Skip non-audio tracks from MusicBrainz 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. --- beets/autotag/mb.py | 11 +++++++++++ docs/changelog.rst | 3 +++ test/test_mb.py | 26 +++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index b5ed4f358..6cf2818fd 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -39,6 +39,8 @@ else: 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/') @@ -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( diff --git a/docs/changelog.rst b/docs/changelog.rst index 2a7349d65..4ff54b222 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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) diff --git a/test/test_mb.py b/test/test_mb.py index 9c51d0fe3..4683793f4 100644 --- a/test/test_mb.py +++ b/test/test_mb.py @@ -95,7 +95,7 @@ class MBAlbumInfoTest(_common.TestCase): }) 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, @@ -113,6 +113,8 @@ class MBAlbumInfoTest(_common.TestCase): 'name': 'RECORDING ARTIST CREDIT', } ] + if video: + track['video'] = 'true' return track def test_parse_release_with_year(self): @@ -345,6 +347,28 @@ class MBAlbumInfoTest(_common.TestCase): 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): From d325bceb1d2d3d8d863839ac3258faa609401cec Mon Sep 17 00:00:00 2001 From: Nicolas Guillaumin Date: Sun, 31 Dec 2017 10:46:48 -0800 Subject: [PATCH 2/3] Added a setting to control if video tracks are ignored Users may want to keep tracking video tracks, for example if they rip the audio part of the video tracks. Added a setting to allow this. --- beets/autotag/mb.py | 3 ++- beets/config_default.yaml | 1 + docs/reference/config.rst | 11 +++++++++++ test/test_mb.py | 15 ++++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 6cf2818fd..e32f73329 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -294,7 +294,8 @@ def album_info(release): continue if ('video' in track['recording'] and - track['recording']['video'] == 'true'): + track['recording']['video'] == 'true' and + config['match']['ignore_video_tracks'].get(bool) is True): continue # Basic information from the recording. diff --git a/beets/config_default.yaml b/beets/config_default.yaml index 942459738..01c1e0f65 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -126,5 +126,6 @@ match: original_year: no ignored: [] required: [] + ignore_video_tracks: yes track_length_grace: 10 track_length_max: 30 diff --git a/docs/reference/config.rst b/docs/reference/config.rst index 4015a4fc2..84f41a385 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -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 diff --git a/test/test_mb.py b/test/test_mb.py index 4683793f4..35f7c3aa2 100644 --- a/test/test_mb.py +++ b/test/test_mb.py @@ -358,7 +358,7 @@ class MBAlbumInfoTest(_common.TestCase): self.assertEqual(d.tracks[0].title, 'TITLE ONE') self.assertEqual(d.tracks[1].title, 'TITLE TWO') - def test_skip_video_track(self): + 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), @@ -369,6 +369,19 @@ class MBAlbumInfoTest(_common.TestCase): 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): From da8e17d2df040ffa4336ae8d8ffc74861b30c584 Mon Sep 17 00:00:00 2001 From: Nicolas Guillaumin Date: Sun, 31 Dec 2017 14:24:36 -0800 Subject: [PATCH 3/3] Simplify boolean check --- beets/autotag/mb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index e32f73329..eb7c30808 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -295,7 +295,7 @@ def album_info(release): if ('video' in track['recording'] and track['recording']['video'] == 'true' and - config['match']['ignore_video_tracks'].get(bool) is True): + config['match']['ignore_video_tracks']): continue # Basic information from the recording.