From 42e6fdbc9bddb047f94a26e2ae53987a938c8a6c Mon Sep 17 00:00:00 2001 From: soergeld Date: Sun, 10 May 2020 17:00:50 +0200 Subject: [PATCH 1/9] Instead of applying all tags from a list, apply all not in a list --- beets/autotag/__init__.py | 62 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index f9e38413e..d3bb48117 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -157,52 +157,52 @@ def apply_metadata(album_info, mapping): # Track alt. item.track_alt = track_info.track_alt - # Miscellaneous/nullable metadata. + # Metadata that has already been set misc_fields = { 'album': ( - 'albumtype', - 'label', - 'asin', - 'catalognum', - 'script', - 'language', - 'country', - 'style', - 'genre', - 'discogs_albumid', - 'discogs_artistid', - 'discogs_labelid', - 'albumstatus', - 'albumdisambig', - 'releasegroupdisambig', - 'data_source', + 'va', + 'releasegroup_id', + 'artist_id', + 'album_id', + 'mediums', + 'tracks', + 'year', + 'month', + 'day', + 'artist', + 'artist_credit', ), 'track': ( - 'disctitle', - 'lyricist', - 'media', - 'composer', - 'composer_sort', - 'arranger', - 'work', - 'mb_workid', - 'work_disambig', - 'bpm', - 'initial_key', - 'genre' + 'track_alt', + 'artist_id', + 'release_track_id', + 'medium', + 'index', + 'medium_index', + 'title', + 'artist_credit', + 'artist_sort', + 'artist', + 'track_id', + 'medium_total', + 'data_url' ) } # Don't overwrite fields with empty values unless the # field is explicitly allowed to be overwritten - for field in misc_fields['album']: + for field in album_info.keys(): + if field in misc_fields['album']: + continue clobber = field in config['overwrite_null']['album'].as_str_seq() value = getattr(album_info, field) if value is None and not clobber: continue item[field] = value - for field in misc_fields['track']: + for field in track_info.keys(): + if field in misc_fields['track']: + continue clobber = field in config['overwrite_null']['track'].as_str_seq() value = getattr(track_info, field) if value is None and not clobber: From f39bc1f894606f0e13e8a09b060d9b6991f80741 Mon Sep 17 00:00:00 2001 From: soergeld Date: Sun, 10 May 2020 17:09:51 +0200 Subject: [PATCH 2/9] forgot a tag in the exclude list --- beets/autotag/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index d3bb48117..9cde24e27 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -171,6 +171,7 @@ def apply_metadata(album_info, mapping): 'day', 'artist', 'artist_credit', + 'artist_sort' ), 'track': ( 'track_alt', From e7d7c72ae151f086070c27b88be926835c9e22ef Mon Sep 17 00:00:00 2001 From: soergeld Date: Sun, 10 May 2020 17:16:57 +0200 Subject: [PATCH 3/9] forgot another one --- beets/autotag/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 9cde24e27..945dd06e9 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -171,7 +171,8 @@ def apply_metadata(album_info, mapping): 'day', 'artist', 'artist_credit', - 'artist_sort' + 'artist_sort', + 'data_url' ), 'track': ( 'track_alt', From cef8ab65367575b59559795f893b5f957ddf79c1 Mon Sep 17 00:00:00 2001 From: soergeld Date: Sun, 10 May 2020 17:27:52 +0200 Subject: [PATCH 4/9] Same for tracks --- beets/autotag/__init__.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 945dd06e9..f79606aaa 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -52,20 +52,24 @@ def apply_item_metadata(item, track_info): if track_info.data_source: item.data_source = track_info.data_source - if track_info.lyricist is not None: - item.lyricist = track_info.lyricist - if track_info.composer is not None: - item.composer = track_info.composer - if track_info.composer_sort is not None: - item.composer_sort = track_info.composer_sort - if track_info.arranger is not None: - item.arranger = track_info.arranger - if track_info.work is not None: - item.work = track_info.work - if track_info.mb_workid is not None: - item.mb_workid = track_info.mb_workid - if track_info.work_disambig is not None: - item.work_disambig = track_info.work_disambig + misc_fields = ['artist_id', + 'release_track_id', + 'title', + 'artist_credit', + 'artist_sort', + 'artist', + 'track_id', + 'data_url' + ] + + for field in track_info.keys(): + if field in misc_fields: + continue + clobber = field in config['overwrite_null']['track'].as_str_seq() + value = getattr(track_info, field) + if value is None and not clobber: + continue + item[field] = value # At the moment, the other metadata is left intact (including album # and track number). Perhaps these should be emptied? From 2d15060bf8d4fbb4a677f7cc68e6c7a2fd138676 Mon Sep 17 00:00:00 2001 From: soergeld Date: Sun, 10 May 2020 20:02:54 +0200 Subject: [PATCH 5/9] more forgotten tags --- beets/autotag/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index f79606aaa..670d55212 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -59,7 +59,8 @@ def apply_item_metadata(item, track_info): 'artist_sort', 'artist', 'track_id', - 'data_url' + 'data_url', + 'length' ] for field in track_info.keys(): @@ -191,7 +192,8 @@ def apply_metadata(album_info, mapping): 'artist', 'track_id', 'medium_total', - 'data_url' + 'data_url', + 'length' ) } From dda7e41aebf45b177e471f5f65d5ca91725aa8c0 Mon Sep 17 00:00:00 2001 From: soergeld Date: Mon, 11 May 2020 16:41:20 +0200 Subject: [PATCH 6/9] various small changes --- beets/autotag/__init__.py | 101 +++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 56 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 670d55212..dea1fe756 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -35,6 +35,41 @@ from .match import Recommendation # noqa # Global logger. log = logging.getLogger('beets') +# metadata that is already hardcoded +MISC_FIELDS = { + 'album': ( + 'va', + 'releasegroup_id', + 'artist_id', + 'album_id', + 'mediums', + 'tracks', + 'year', + 'month', + 'day', + 'artist', + 'artist_credit', + 'artist_sort', + 'data_url' + ), + 'track': ( + 'track_alt', + 'artist_id', + 'release_track_id', + 'medium', + 'index', + 'medium_index', + 'title', + 'artist_credit', + 'artist_sort', + 'artist', + 'track_id', + 'medium_total', + 'data_url', + 'length' + ) +} + # Additional utilities for the main interface. @@ -52,23 +87,11 @@ def apply_item_metadata(item, track_info): if track_info.data_source: item.data_source = track_info.data_source - misc_fields = ['artist_id', - 'release_track_id', - 'title', - 'artist_credit', - 'artist_sort', - 'artist', - 'track_id', - 'data_url', - 'length' - ] - - for field in track_info.keys(): - if field in misc_fields: + for field, value in track_info.items(): + # only overwrite fields that are not already hardcoded + if field in MISC_FIELDS['track']: continue - clobber = field in config['overwrite_null']['track'].as_str_seq() - value = getattr(track_info, field) - if value is None and not clobber: + if value is None: continue item[field] = value @@ -162,54 +185,20 @@ def apply_metadata(album_info, mapping): # Track alt. item.track_alt = track_info.track_alt - # Metadata that has already been set - misc_fields = { - 'album': ( - 'va', - 'releasegroup_id', - 'artist_id', - 'album_id', - 'mediums', - 'tracks', - 'year', - 'month', - 'day', - 'artist', - 'artist_credit', - 'artist_sort', - 'data_url' - ), - 'track': ( - 'track_alt', - 'artist_id', - 'release_track_id', - 'medium', - 'index', - 'medium_index', - 'title', - 'artist_credit', - 'artist_sort', - 'artist', - 'track_id', - 'medium_total', - 'data_url', - 'length' - ) - } - # Don't overwrite fields with empty values unless the # field is explicitly allowed to be overwritten - for field in album_info.keys(): - if field in misc_fields['album']: + for field, value in album_info.items(): + # only overwrite fields that are not already hardcoded + if field in MISC_FIELDS['album']: continue clobber = field in config['overwrite_null']['album'].as_str_seq() - value = getattr(album_info, field) if value is None and not clobber: continue item[field] = value - for field in track_info.keys(): - if field in misc_fields['track']: + for field, value in track_info.items(): + # only overwrite fields that are not already hardcoded + if field in MISC_FIELDS['track']: continue clobber = field in config['overwrite_null']['track'].as_str_seq() value = getattr(track_info, field) From 2923e90da1f3d0887d582024f2cefee56db5e923 Mon Sep 17 00:00:00 2001 From: soergeld Date: Wed, 13 May 2020 00:16:18 +0200 Subject: [PATCH 7/9] cosmetics --- beets/autotag/__init__.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index dea1fe756..5fc5b1c6c 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -36,7 +36,7 @@ from .match import Recommendation # noqa log = logging.getLogger('beets') # metadata that is already hardcoded -MISC_FIELDS = { +SPECIAL_FIELDS = { 'album': ( 'va', 'releasegroup_id', @@ -84,12 +84,10 @@ def apply_item_metadata(item, track_info): item.mb_releasetrackid = track_info.release_track_id if track_info.artist_id: item.mb_artistid = track_info.artist_id - if track_info.data_source: - item.data_source = track_info.data_source for field, value in track_info.items(): # only overwrite fields that are not already hardcoded - if field in MISC_FIELDS['track']: + if field in SPECIAL_FIELDS['track']: continue if value is None: continue @@ -188,8 +186,7 @@ def apply_metadata(album_info, mapping): # Don't overwrite fields with empty values unless the # field is explicitly allowed to be overwritten for field, value in album_info.items(): - # only overwrite fields that are not already hardcoded - if field in MISC_FIELDS['album']: + if field in SPECIAL_FIELDS['album']: continue clobber = field in config['overwrite_null']['album'].as_str_seq() if value is None and not clobber: @@ -197,8 +194,7 @@ def apply_metadata(album_info, mapping): item[field] = value for field, value in track_info.items(): - # only overwrite fields that are not already hardcoded - if field in MISC_FIELDS['track']: + if field in SPECIAL_FIELDS['track']: continue clobber = field in config['overwrite_null']['track'].as_str_seq() value = getattr(track_info, field) From 26a78a0c280c480601258c151e8185e9167a6b3c Mon Sep 17 00:00:00 2001 From: soergeld Date: Wed, 13 May 2020 16:54:04 +0200 Subject: [PATCH 8/9] Cosmetics --- beets/autotag/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 5fc5b1c6c..057daa405 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -35,7 +35,7 @@ from .match import Recommendation # noqa # Global logger. log = logging.getLogger('beets') -# metadata that is already hardcoded +# Metadata that is already hardcoded. SPECIAL_FIELDS = { 'album': ( 'va', @@ -86,7 +86,7 @@ def apply_item_metadata(item, track_info): item.mb_artistid = track_info.artist_id for field, value in track_info.items(): - # only overwrite fields that are not already hardcoded + # We only overwrite fields that are not already hardcoded. if field in SPECIAL_FIELDS['track']: continue if value is None: From 66085a231f88c1fcec91c7ef1807af91a1f1e084 Mon Sep 17 00:00:00 2001 From: soergeld Date: Wed, 13 May 2020 17:42:49 +0200 Subject: [PATCH 9/9] Cosmetics --- beets/autotag/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 057daa405..7ab0d57fd 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -35,7 +35,7 @@ from .match import Recommendation # noqa # Global logger. log = logging.getLogger('beets') -# Metadata that is already hardcoded. +# Metadata fields that are already hardcoded, or where the tag name changes. SPECIAL_FIELDS = { 'album': ( 'va',