Repository: beetbox/beets

Issue:
Don't try to match non-audio media fetched from MusicBrainz
Matching a folder containing all audio files of a MB release made of CD+DVD for instance fails since beets does take into account also the video files.
For instance (1 CD+ 1DVD):
https://musicbrainz.org/release/2775743e-2d9c-4b7f-9baa-1d24dc44c769
https://musicbrainz.org/release/f457c3e1-0d98-4904-9d9e-a085bc5b232b
I imagine the same happens for enhanced CDs with some additional video track.
In general I think the right thing to do is that all media files that are marked as video in MB should not be considered for matching. After all beets currently only deals with audio files.

Discussion:
nguillaumin: This is the first time I do something in Python, so let me know if I did anything wrong, thanks!

Patch:
diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py
index 5c484d2b3..b5ed4f358 100644
--- a/beets/autotag/mb.py
+++ b/beets/autotag/mb.py
@@ -36,6 +36,9 @@ if util.SNI_SUPPORTED:
 else:
     BASE_URL = 'http://musicbrainz.org/'
 
+NON_AUDIO_FORMATS = ['Data CD', 'DVD', 'DVD-Video', 'Blu-ray', 'HD-DVD', 'VCD',
+                     'SVCD', 'UMD', 'VHS']
+
 musicbrainzngs.set_useragent('beets', beets.__version__,
                              'http://beets.io/')
 
@@ -275,6 +278,9 @@ def album_info(release):
         disctitle = medium.get('title')
         format = medium.get('format')
 
+        if format in NON_AUDIO_FORMATS:
+            continue
+
         all_tracks = medium['track-list']
         if 'pregap' in medium:
             all_tracks.insert(0, medium['pregap'])
diff --git a/docs/changelog.rst b/docs/changelog.rst
index bd084a890..2a7349d65 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -6,6 +6,9 @@ Changelog
 
 Changelog goes here!
 
+Fixes:
+* Non-audio media (DVD-Video, etc.) are now skipped by the autotagger. :bug:`2688`
+
 
 1.4.6 (December 21, 2017)
 -------------------------


Test patch:
diff --git a/test/test_mb.py b/test/test_mb.py
index ca1bf2a1a..9c51d0fe3 100644
--- a/test/test_mb.py
+++ b/test/test_mb.py
@@ -27,7 +27,7 @@ import mock
 
 class MBAlbumInfoTest(_common.TestCase):
     def _make_release(self, date_str='2009', tracks=None, track_length=None,
-                      track_artist=False):
+                      track_artist=False, medium_format='FORMAT'):
         release = {
             'title': 'ALBUM TITLE',
             'id': 'ALBUM ID',
@@ -90,7 +90,7 @@ class MBAlbumInfoTest(_common.TestCase):
             release['medium-list'].append({
                 'position': '1',
                 'track-list': track_list,
-                'format': 'FORMAT',
+                'format': medium_format,
                 'title': 'MEDIUM TITLE',
             })
         return release
@@ -324,6 +324,27 @@ class MBAlbumInfoTest(_common.TestCase):
         d = mb.album_info(release)
         self.assertEqual(d.data_source, 'MusicBrainz')
 
+    def test_skip_non_audio_dvd(self):
+        tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
+                  self._make_track('TITLE TWO', 'ID TWO', 200.0 * 1000.0)]
+        release = self._make_release(tracks=tracks, medium_format="DVD")
+        d = mb.album_info(release)
+        self.assertEqual(len(d.tracks), 0)
+
+    def test_skip_non_audio_dvd_video(self):
+        tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
+                  self._make_track('TITLE TWO', 'ID TWO', 200.0 * 1000.0)]
+        release = self._make_release(tracks=tracks, medium_format="DVD-Video")
+        d = mb.album_info(release)
+        self.assertEqual(len(d.tracks), 0)
+
+    def test_no_skip_dvd_audio(self):
+        tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
+                  self._make_track('TITLE TWO', 'ID TWO', 200.0 * 1000.0)]
+        release = self._make_release(tracks=tracks, medium_format="DVD-Audio")
+        d = mb.album_info(release)
+        self.assertEqual(len(d.tracks), 2)
+
 
 class ParseIDTest(_common.TestCase):
     def test_parse_id_correct(self):