From d187eba1f86f69a1283c55143c54fbd2dde13193 Mon Sep 17 00:00:00 2001 From: Bob Swift Date: Mon, 25 Apr 2022 11:02:11 -0600 Subject: [PATCH] Add helper function to use `album.id` as album dictionary key --- .../persistent_variables.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/plugins/persistent_variables/persistent_variables.py b/plugins/persistent_variables/persistent_variables.py index 8e4698c3..d84f88ff 100644 --- a/plugins/persistent_variables/persistent_variables.py +++ b/plugins/persistent_variables/persistent_variables.py @@ -109,6 +109,13 @@ def get_session_var(cls, key): return cls.session_variables[key] if key in cls.session_variables else "" +def _get_album_id(parser): + file = parser.file + if file and file.parent and hasattr(file.parent, 'album') and file.parent.album: + return str(file.parent.album.id) + return "" + + def func_set_s(parser, name, value): if value: PersistentVariables.set_session_var(normalize_tagname(name), value) @@ -132,25 +139,30 @@ def func_clear_s(parser): def func_unset_a(parser, name): - album_id = parser.context['musicbrainz_albumid'] - PersistentVariables.unset_album_var(album_id, normalize_tagname(name)) + album_id = _get_album_id(parser) + if album_id: + PersistentVariables.unset_album_var(album_id, normalize_tagname(name)) return "" def func_set_a(parser, name, value): - album_id = parser.context['musicbrainz_albumid'] - PersistentVariables.set_album_var(album_id, normalize_tagname(name), value) + album_id = _get_album_id(parser) + if album_id: + PersistentVariables.set_album_var(album_id, normalize_tagname(name), value) return "" def func_get_a(parser, name): - album_id = parser.context['musicbrainz_albumid'] - return PersistentVariables.get_album_var(album_id, normalize_tagname(name)) + album_id = _get_album_id(parser) + if album_id: + return PersistentVariables.get_album_var(album_id, normalize_tagname(name)) + return "" def func_clear_a(parser): - album_id = parser.context['musicbrainz_albumid'] - PersistentVariables.clear_album_vars(album_id) + album_id = _get_album_id(parser) + if album_id: + PersistentVariables.clear_album_vars(album_id) return ""