From ec56f2bbd453f91ba83d098499ece79c88feb8b5 Mon Sep 17 00:00:00 2001 From: Heinz Wiesinger Date: Sat, 4 Oct 2014 11:01:18 +0200 Subject: [PATCH] Make 'media' an item level field. Releases can consist of discs of various media types, most typically CD/DVD combo releases. Having the media value an album level field forces all discs to be of the same type. Making it an item level field instead seems to be the proper thing to do here. Fixes #161 --- beets/autotag/__init__.py | 4 +++- beets/autotag/hooks.py | 7 +++++-- beets/autotag/mb.py | 2 ++ beets/library.py | 2 -- beetsplug/missing.py | 2 +- docs/changelog.rst | 1 + 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index c9e6825e8..5ac2380db 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -122,10 +122,12 @@ def apply_metadata(album_info, mapping): 'language', 'country', 'albumstatus', - 'media', 'albumdisambig'): value = getattr(album_info, field) if value is not None: item[field] = value if track_info.disctitle is not None: item.disctitle = track_info.disctitle + + if track_info.media is not None: + item.media = track_info.media diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index 58b2580d1..beb3bd91b 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -127,6 +127,7 @@ class TrackInfo(object): - ``artist_id`` - ``length``: float: duration of the track in seconds - ``index``: position on the entire release + - ``media``: delivery mechanism (Vinyl, etc.) - ``medium``: the disc number this track appears on in the album - ``medium_index``: the track's position on the disc - ``medium_total``: the number of tracks on the item's disc @@ -141,13 +142,15 @@ class TrackInfo(object): def __init__(self, title, track_id, artist=None, artist_id=None, length=None, index=None, medium=None, medium_index=None, medium_total=None, artist_sort=None, disctitle=None, - artist_credit=None, data_source=None, data_url=None): + artist_credit=None, data_source=None, data_url=None, + media=None): self.title = title self.track_id = track_id self.artist = artist self.artist_id = artist_id self.length = length self.index = index + self.media = media self.medium = medium self.medium_index = medium_index self.medium_total = medium_total @@ -163,7 +166,7 @@ class TrackInfo(object): to Unicode. """ for fld in ['title', 'artist', 'medium', 'artist_sort', 'disctitle', - 'artist_credit']: + 'artist_credit', 'media']: value = getattr(self, fld) if isinstance(value, str): setattr(self, fld, value.decode(codec, 'ignore')) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index d7afbc52b..159d623d5 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -209,6 +209,7 @@ def album_info(release): index = 0 for medium in release['medium-list']: disctitle = medium.get('title') + format = medium.get('format') for track in medium['track-list']: # Basic information from the recording. index += 1 @@ -220,6 +221,7 @@ def album_info(release): len(medium['track-list']), ) ti.disctitle = disctitle + ti.media = format # Prefer track data, where present, over recording data. if track.get('title'): diff --git a/beets/library.py b/beets/library.py index 9f3ed36f8..f4e8f6b61 100644 --- a/beets/library.py +++ b/beets/library.py @@ -729,7 +729,6 @@ class Album(LibModel): 'language': types.STRING, 'country': types.STRING, 'albumstatus': types.STRING, - 'media': types.STRING, 'albumdisambig': types.STRING, 'rg_album_gain': types.NULL_FLOAT, 'rg_album_peak': types.NULL_FLOAT, @@ -769,7 +768,6 @@ class Album(LibModel): 'language', 'country', 'albumstatus', - 'media', 'albumdisambig', 'rg_album_gain', 'rg_album_peak', diff --git a/beetsplug/missing.py b/beetsplug/missing.py index addc0ae28..74f4d4b6c 100644 --- a/beetsplug/missing.py +++ b/beetsplug/missing.py @@ -88,7 +88,7 @@ def _item(track_info, album_info, album_id): 'mb_artistid': t.artist_id, 'mb_releasegroupid': a.releasegroup_id, 'mb_trackid': t.track_id, - 'media': a.media, + 'media': t.media, 'month': a.month, 'script': a.script, 'title': t.title, diff --git a/docs/changelog.rst b/docs/changelog.rst index 7f539a2e9..139af5d6f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -37,6 +37,7 @@ Fixes: temporarily * :doc:`/plugins/discogs`: Recover from HTTP errors when communicating with the Discogs servers. Thanks to Dustin Rodriguez. +* Fix storing media types for albums consisting of different media. 1.3.8 (September 17, 2014)