From cc6eefa73dbe247e92df10dd159d9cb8d35c1b4c Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sun, 4 May 2025 10:50:56 +0100 Subject: [PATCH 1/3] new plugin event "recommendation" --- beets/autotag/match.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/beets/autotag/match.py b/beets/autotag/match.py index bc30ccea2..01774d145 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -390,6 +390,11 @@ def _recommendation( rec = Recommendation.low else: # No conclusion. Return immediately. Can't be downgraded any further. + # but allow plugins to modify the recommendation + new_rec_list = plugins.send("recommendation", results=results, org_rec=Recommendation.none) + # take the first recommendation from a plugin + if len(new_rec_list) > 0 and isinstance(new_rec_list[0], Recommendation): + return new_rec_list[0] return Recommendation.none # Downgrade to the max rec if it is lower than the current rec for an @@ -411,6 +416,11 @@ def _recommendation( ) rec = min(rec, max_rec) + # allow plugins to modify the recommendation + new_rec_list = plugins.send("recommendation", results=results, org_rec=rec) + # take the first recommendation from a plugin + if len(new_rec_list) > 0 and isinstance(new_rec_list[0], Recommendation): + rec = new_rec_list[0] return rec From 074a2783165b9b09ff7113531125ce4bd66910c9 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sun, 4 May 2025 11:15:15 +0100 Subject: [PATCH 2/3] new plugin event "assign_items" --- beets/autotag/match.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/beets/autotag/match.py b/beets/autotag/match.py index 01774d145..7569f0dc8 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -142,6 +142,16 @@ def assign_items( for iidx, t in zip(assigned_item_idxs, tracks) if iidx != -1 } + + # allow plugins to modify the mapping + new_assign_list = plugins.send("assign_items", mapping=mapping, org_items=items, org_tracks=tracks) + + # get the first plugin provided mapping that is a dict and not empty + new_mapping = next((item for item in new_assign_list if isinstance(item, dict) and item), None) + if new_mapping: + # if a plugin provided a mapping, use that instead of the default one + mapping = new_mapping + extra_items = list(set(items) - mapping.keys()) extra_items.sort(key=lambda i: (i.disc, i.track, i.title)) extra_tracks = list(set(tracks) - set(mapping.values())) From 05fa515867ce023f7d61bd9069ab15b63174674f Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sun, 4 May 2025 12:35:27 +0100 Subject: [PATCH 3/3] Fix formating --- beets/autotag/match.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/beets/autotag/match.py b/beets/autotag/match.py index 7569f0dc8..9e4bc2ad5 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -144,14 +144,19 @@ def assign_items( } # allow plugins to modify the mapping - new_assign_list = plugins.send("assign_items", mapping=mapping, org_items=items, org_tracks=tracks) - + new_assign_list = plugins.send( + "assign_items", mapping=mapping, org_items=items, org_tracks=tracks + ) + # get the first plugin provided mapping that is a dict and not empty - new_mapping = next((item for item in new_assign_list if isinstance(item, dict) and item), None) + new_mapping = next( + (item for item in new_assign_list if isinstance(item, dict) and item), + None, + ) if new_mapping: # if a plugin provided a mapping, use that instead of the default one mapping = new_mapping - + extra_items = list(set(items) - mapping.keys()) extra_items.sort(key=lambda i: (i.disc, i.track, i.title)) extra_tracks = list(set(tracks) - set(mapping.values())) @@ -401,9 +406,13 @@ def _recommendation( else: # No conclusion. Return immediately. Can't be downgraded any further. # but allow plugins to modify the recommendation - new_rec_list = plugins.send("recommendation", results=results, org_rec=Recommendation.none) + new_rec_list = plugins.send( + "recommendation", results=results, org_rec=Recommendation.none + ) # take the first recommendation from a plugin - if len(new_rec_list) > 0 and isinstance(new_rec_list[0], Recommendation): + if len(new_rec_list) > 0 and isinstance( + new_rec_list[0], Recommendation + ): return new_rec_list[0] return Recommendation.none