Merge pull request #3586 from dosoe/beet_update_parentwork

Fetching parentwork if changed, even if not force
This commit is contained in:
Adrian Sampson 2020-05-14 08:26:30 -04:00 committed by GitHub
commit b3656bcab9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View file

@ -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:
work_changed = True
if hasattr(item, 'parentwork_workid_current'):
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:
self._log.debug("error fetching work: {}", e)
return
parent_info = self.get_info(item, work_info)
parent_info['parentwork_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',
'parentwork_workid_current'])

View file

@ -18,15 +18,26 @@ 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:
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
the parentwork was retrieved. This tag exists only for internal bookkeeping,
to keep track of recordings whose works have changed.
To use the ``parentwork`` plugin, enable it in your configuration (see
:ref:`using-plugins`).
@ -38,10 +49,11 @@ 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``
- **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``