PICARD-1849: add album_save_post_processors to plug-in API.#1565
PICARD-1849: add album_save_post_processors to plug-in API.#1565thomasvs wants to merge 2 commits intometabrainz:masterfrom
Conversation
I wanted to extend the M3U playlist plugin to automatically generate an .m3u8 when Albums get saved. To be able to do so, I needed to add album_save_post_processors so that I could get access to an album on save. File save is done in a thread, so I needed to implement a way to wait for those threads to finish by using the file_save_post_processors hook.
zas
left a comment
There was a problem hiding this comment.
Please ensure tests are passing (Codacy is complaining)
| files = self.get_files_from_objects(objects, save=True) | ||
| for file in files: | ||
| file.save() | ||
| for o in objects: |
| # run album_save hooks when the last file is saved | ||
| def _file_post_save(self, file): | ||
| for album, files in self._album_saves: | ||
| if file in files: |
There was a problem hiding this comment.
Since file will not be found in empty files:
if not files:
...
elif file in files:
...| file.save() | ||
| for o in objects: | ||
| log.debug('save object %r', o) | ||
| files = self.get_files_from_objects([o, ], save=True) |
There was a problem hiding this comment.
This defeats uniquification (?) implemented in
Lines 663 to 665 in 7b41e12
There was a problem hiding this comment.
Yes, this can potentially lead to the same file saved twice: You can have both the album and the files selected for saving, but saving should only happen once.
Also we need to be clear what is expected to happen:
- If I select the album and save, should the album_save_post_processor be run? (I assume this is a clear YES)
- If I select all files of an album, but not the album itself, should the album_save_post_processor be run?
- If I select only some files of an album, but not the album itself, should the album_save_post_processor be run?
I tend to say yes to all of the above. But for case 3 it might be useful if the registered processor gets some information, that only a subset has been saved. Optimal would be to pass a list of actually saved files to the processor, so it could figure out what to do with this based on the use case.
| log.debug("Album %r saved, running post_save_processors", album) | ||
| run_album_post_save_processors(album) | ||
| self._album_saves.remove((album, files)) | ||
| return |
There was a problem hiding this comment.
I'm not sure to understand why we return immediatly here
Fixes https://tickets.metabrainz.org/browse/PICARD-1849
I wanted to extend the M3U playlist plugin to automatically generate an .m3u8
when Albums get saved.
To be able to do so, I needed to add album_save_post_processors so that I could
get access to an album on save.
Solution
File save is done in a thread, so I needed to implement a way to wait for those
threads to finish by using the file_save_post_processors hook.