Repository: beetbox/beets

Issue:
discogs: disc field is set to zero
Releases coming from MB with only a single disc are tagged in a correct way (to my view) like: 1/1. However, when using the discogs plugin for releases from discogs the disc field of a single disc album is set to 0/1.

What is exactly going wrong here? Is it just a mistake within the plugin or is it the discogs database serving the wrong 0/1 disc tag? And, is there a workaround to avoid this and have it tagged in the correct way like MB does as 1/1?



Discussion:
Thanks for the report—I was able to reproduce this; it seems to be a bug. The [code that numbers the discs (a.k.a. mediums) in discogs.py](https://github.com/sampsyo/beets/blob/master/beetsplug/discogs.py#L181) is somewhat obscure so the problem is not immediately obvious. Someone sober (perhaps you, @kooimens?) should stare at this section to see what's going on.

The whole mess there could use some simplification. See also #415.

You can write almost exactly what you said in Python: `1 if disc == 0 else disc`

Or even more Pythonically: `disc or 1`


Resolving patch:
diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py
--- a/beetsplug/discogs.py
+++ b/beetsplug/discogs.py
@@ -335,6 +335,7 @@ def get_tracks(self, tracklist):
                     index_count = 0
                     side_count = 0
             index_count += 1
+            medium_count = 1 if medium_count == 0 else medium_count
             track.medium, track.medium_index = medium_count, index_count
 
         # Get `disctitle` from Discogs index tracks. Assume that an index track


Test patch:
diff --git a/test/test_discogs.py b/test/test_discogs.py
--- a/test/test_discogs.py
+++ b/test/test_discogs.py
@@ -92,6 +92,44 @@ def test_parse_media_for_tracks(self):
         self.assertEqual(t[0].media, d.media)
         self.assertEqual(t[1].media, d.media)
 
+    def test_parse_medium_numbers_single_medium(self):
+        release = self._make_release_from_positions(['1', '2'])
+        d = DiscogsPlugin().get_album_info(release)
+        t = d.tracks
+
+        self.assertEqual(d.mediums, 1)
+        self.assertEqual(t[0].medium, 1)
+        self.assertEqual(t[0].medium_total, 1)
+        self.assertEqual(t[1].medium, 1)
+        self.assertEqual(t[0].medium_total, 1)
+
+    def test_parse_medium_numbers_two_mediums(self):
+        release = self._make_release_from_positions(['1-1', '2-1'])
+        d = DiscogsPlugin().get_album_info(release)
+        t = d.tracks
+
+        self.assertEqual(d.mediums, 2)
+        self.assertEqual(t[0].medium, 1)
+        self.assertEqual(t[0].medium_total, 2)
+        self.assertEqual(t[1].medium, 2)
+        self.assertEqual(t[1].medium_total, 2)
+
+    def test_parse_medium_numbers_two_mediums_two_sided(self):
+        release = self._make_release_from_positions(['A1', 'B1', 'C1'])
+        d = DiscogsPlugin().get_album_info(release)
+        t = d.tracks
+
+        self.assertEqual(d.mediums, 2)
+        self.assertEqual(t[0].medium, 1)
+        self.assertEqual(t[0].medium_total, 2)
+        self.assertEqual(t[0].medium_index, 1)
+        self.assertEqual(t[1].medium, 1)
+        self.assertEqual(t[1].medium_total, 2)
+        self.assertEqual(t[1].medium_index, 2)
+        self.assertEqual(t[2].medium, 2)
+        self.assertEqual(t[2].medium_total, 2)
+        self.assertEqual(t[2].medium_index, 1)
+
     def test_parse_track_indices(self):
         release = self._make_release_from_positions(['1', '2'])
         d = DiscogsPlugin().get_album_info(release)