From c948530279f6488964b7715e131946484f0fa5dc Mon Sep 17 00:00:00 2001 From: soergeld Date: Sun, 10 May 2020 13:05:55 +0200 Subject: [PATCH 1/5] Fetching parentwork if changed, even if not force --- beetsplug/parentwork.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/beetsplug/parentwork.py b/beetsplug/parentwork.py index d40254696..e2460e875 100644 --- a/beetsplug/parentwork.py +++ b/beetsplug/parentwork.py @@ -173,13 +173,17 @@ add one at https://musicbrainz.org/recording/{}', item, item.mb_trackid) return hasparent = hasattr(item, 'parentwork') - if force or not hasparent: + workfalse = True + if hasattr(item, 'mb_workid_current'): + workfalse = item.mb_workid_current != item.mb_workid + if force or (not hasparent) or workfalse: try: work_info, work_date = find_parentwork_info(item.mb_workid) except musicbrainzngs.musicbrainz.WebServiceError as e: self._log.debug("error fetching work: {}", e) return parent_info = self.get_info(item, work_info) + parent_info['mb_workid_current'] = item.mb_workid if 'parent_composer' in parent_info: self._log.debug("Work fetched: {} - {}", parent_info['parentwork'], @@ -202,4 +206,5 @@ add one at https://musicbrainz.org/recording/{}', item, item.mb_trackid) return ui.show_model_changes( item, fields=['parentwork', 'parentwork_disambig', 'mb_parentworkid', 'parent_composer', - 'parent_composer_sort', 'work_date']) + 'parent_composer_sort', 'work_date', + 'mb_workid_current']) From 1f93ce5a49fc356566b00da165bc4d35d1ca4bfc Mon Sep 17 00:00:00 2001 From: soergeld Date: Mon, 11 May 2020 16:14:52 +0200 Subject: [PATCH 2/5] small changes, docs --- beetsplug/parentwork.py | 8 ++++---- docs/plugins/parentwork.rst | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/beetsplug/parentwork.py b/beetsplug/parentwork.py index e2460e875..e4978ebf4 100644 --- a/beetsplug/parentwork.py +++ b/beetsplug/parentwork.py @@ -174,16 +174,16 @@ add one at https://musicbrainz.org/recording/{}', item, item.mb_trackid) hasparent = hasattr(item, 'parentwork') workfalse = True - if hasattr(item, 'mb_workid_current'): + if hasattr(item, 'parentwork_workid_current'): workfalse = item.mb_workid_current != item.mb_workid - if force or (not hasparent) or workfalse: + if force or not hasparent or workfalse: try: work_info, work_date = find_parentwork_info(item.mb_workid) except musicbrainzngs.musicbrainz.WebServiceError as e: self._log.debug("error fetching work: {}", e) return parent_info = self.get_info(item, work_info) - parent_info['mb_workid_current'] = item.mb_workid + parent_info['parentwork_workid_current'] = item.mb_workid if 'parent_composer' in parent_info: self._log.debug("Work fetched: {} - {}", parent_info['parentwork'], @@ -207,4 +207,4 @@ add one at https://musicbrainz.org/recording/{}', item, item.mb_trackid) item, fields=['parentwork', 'parentwork_disambig', 'mb_parentworkid', 'parent_composer', 'parent_composer_sort', 'work_date', - 'mb_workid_current']) + 'parentwork_workid_current']) diff --git a/docs/plugins/parentwork.rst b/docs/plugins/parentwork.rst index 9707650b4..e25f01395 100644 --- a/docs/plugins/parentwork.rst +++ b/docs/plugins/parentwork.rst @@ -18,7 +18,7 @@ example, all the movements of a symphony. This plugin aims to solve this problem by also fetching the parent work, which would be the whole symphony in this example. -This plugin adds five tags: +This plugin adds six tags: - **parentwork**: The title of the parent work. - **mb_parentworkid**: The musicbrainz id of the parent work. @@ -27,6 +27,9 @@ This plugin adds five tags: - **parent_composer_sort**: The sort name of the parent work composer. - **work_date**: The composition date of the work, or the first parent work that has a composition date. Format: yyyy-mm-dd. +- **parentwork_workid_current**: The musicbrainz id of the work as it was when + the parentwork was retrieved. This tag exists only for internal bookkeeping, + to keep track of recordings whose work have changed. To use the ``parentwork`` plugin, enable it in your configuration (see :ref:`using-plugins`). From 918fea5ecaa729de335a8da8eb170021559caafb Mon Sep 17 00:00:00 2001 From: soergeld Date: Tue, 12 May 2020 16:05:08 +0200 Subject: [PATCH 3/5] small changes, documentation --- beetsplug/parentwork.py | 6 +++--- docs/plugins/parentwork.rst | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/beetsplug/parentwork.py b/beetsplug/parentwork.py index e4978ebf4..781485ba4 100644 --- a/beetsplug/parentwork.py +++ b/beetsplug/parentwork.py @@ -173,10 +173,10 @@ add one at https://musicbrainz.org/recording/{}', item, item.mb_trackid) return hasparent = hasattr(item, 'parentwork') - workfalse = True + work_changed = True if hasattr(item, 'parentwork_workid_current'): - workfalse = item.mb_workid_current != item.mb_workid - if force or not hasparent or workfalse: + work_changed = item.mb_workid_current != item.mb_workid + if force or not hasparent or work_changed: try: work_info, work_date = find_parentwork_info(item.mb_workid) except musicbrainzngs.musicbrainz.WebServiceError as e: diff --git a/docs/plugins/parentwork.rst b/docs/plugins/parentwork.rst index e25f01395..a3b203c7b 100644 --- a/docs/plugins/parentwork.rst +++ b/docs/plugins/parentwork.rst @@ -18,6 +18,12 @@ example, all the movements of a symphony. This plugin aims to solve this problem by also fetching the parent work, which would be the whole symphony in this example. +It uses the ``mb_workid`` tag to retrieve the *parent work* and stores the +``mb_workid`` as ``parentwork_workid_current``. When one executes +``beet parentwork`` it checks if ``mb_workid`` has changed by comparing it +with ``parentwork_workid_current``, if it has changed or if ``force`` is +enabled it fetches the *parent work* again. + This plugin adds six tags: - **parentwork**: The title of the parent work. @@ -27,7 +33,7 @@ This plugin adds six tags: - **parent_composer_sort**: The sort name of the parent work composer. - **work_date**: The composition date of the work, or the first parent work that has a composition date. Format: yyyy-mm-dd. -- **parentwork_workid_current**: The musicbrainz id of the work as it was when +- **parentwork_workid_current**: The Musicbrainz id of the work as it was when the parentwork was retrieved. This tag exists only for internal bookkeeping, to keep track of recordings whose work have changed. @@ -41,7 +47,8 @@ To configure the plugin, make a ``parentwork:`` section in your configuration file. The available options are: - **force**: As a default, ``parentwork`` only fetches work info for - recordings that do not already have a ``parentwork`` tag. If ``force`` + recordings that do not already have a ``parentwork`` tag or where + ``mb_workid`` differs from ``parentwork_workid_current``. If ``force`` is enabled, it fetches it for all recordings. Default: ``no`` From e8b57dfda6057404906dfffefabf0e562923faf3 Mon Sep 17 00:00:00 2001 From: Dorian Soergel Date: Wed, 13 May 2020 14:55:00 +0200 Subject: [PATCH 4/5] Update docs/plugins/parentwork.rst Co-authored-by: Adrian Sampson --- docs/plugins/parentwork.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins/parentwork.rst b/docs/plugins/parentwork.rst index a3b203c7b..1aea9e9ff 100644 --- a/docs/plugins/parentwork.rst +++ b/docs/plugins/parentwork.rst @@ -35,7 +35,7 @@ This plugin adds six tags: that has a composition date. Format: yyyy-mm-dd. - **parentwork_workid_current**: The Musicbrainz id of the work as it was when the parentwork was retrieved. This tag exists only for internal bookkeeping, - to keep track of recordings whose work have changed. + to keep track of recordings whose works have changed. To use the ``parentwork`` plugin, enable it in your configuration (see :ref:`using-plugins`). From ed97b984b02cc2ff41da9b1ec73931687b11ce79 Mon Sep 17 00:00:00 2001 From: soergeld Date: Wed, 13 May 2020 18:02:14 +0200 Subject: [PATCH 5/5] Documentation --- docs/plugins/parentwork.rst | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/plugins/parentwork.rst b/docs/plugins/parentwork.rst index 1aea9e9ff..cc3f21c0c 100644 --- a/docs/plugins/parentwork.rst +++ b/docs/plugins/parentwork.rst @@ -18,22 +18,24 @@ example, all the movements of a symphony. This plugin aims to solve this problem by also fetching the parent work, which would be the whole symphony in this example. -It uses the ``mb_workid`` tag to retrieve the *parent work* and stores the -``mb_workid`` as ``parentwork_workid_current``. When one executes -``beet parentwork`` it checks if ``mb_workid`` has changed by comparing it -with ``parentwork_workid_current``, if it has changed or if ``force`` is -enabled it fetches the *parent work* again. +The plugin can detect changes in ``mb_workid`` so it knows when to re-fetch +other metadata, such as ``parentwork``. To do this, when it runs, it stores a +copy of ``mb_workid`` in the bookkeeping field ``parentwork_workid_current``. +At any later run of ``beet parentwork`` it will check if the tags +``mb_workid`` and ``parentwork_workid_current`` are still identical. If it is +not the case, it means the work has changed and all the tags need to be +fetched again. This plugin adds six tags: - **parentwork**: The title of the parent work. -- **mb_parentworkid**: The musicbrainz id of the parent work. +- **mb_parentworkid**: The MusicBrainz id of the parent work. - **parentwork_disambig**: The disambiguation of the parent work title. - **parent_composer**: The composer of the parent work. - **parent_composer_sort**: The sort name of the parent work composer. - **work_date**: The composition date of the work, or the first parent work that has a composition date. Format: yyyy-mm-dd. -- **parentwork_workid_current**: The Musicbrainz id of the work as it was when +- **parentwork_workid_current**: The MusicBrainz id of the work as it was when the parentwork was retrieved. This tag exists only for internal bookkeeping, to keep track of recordings whose works have changed. @@ -53,5 +55,5 @@ configuration file. The available options are: Default: ``no`` - **auto**: If enabled, automatically fetches works at import. It takes quite - some time, because beets is restricted to one musicbrainz query per second. + some time, because beets is restricted to one MusicBrainz query per second. Default: ``no``