[beetsplug/spl] Add the dest_regen/dest-regen option

This commit is contained in:
Pierre Ayoub 2025-02-08 21:02:15 +01:00 committed by Šarūnas Nejus
parent 2c6f239ac5
commit aae0260484

View file

@ -53,6 +53,7 @@ class SmartPlaylistPlugin(BeetsPlugin):
super().__init__()
self.config.add(
{
"dest_regen": False,
"relative_to": None,
"playlist_dir": ".",
"auto": True,
@ -100,6 +101,12 @@ class SmartPlaylistPlugin(BeetsPlugin):
type="string",
help="directory to write the generated playlist files to.",
)
spl_update.parser.add_option(
"--dest-regen",
action="store_true",
dest="dest_regen",
help="regenerate the destination path as 'move' or 'convert' commands would do.",
)
spl_update.parser.add_option(
"--relative-to",
dest="relative_to",
@ -267,6 +274,7 @@ class SmartPlaylistPlugin(BeetsPlugin):
)
tpl = self.config["uri_format"].get()
prefix = bytestring_path(self.config["prefix"].as_str())
dest_regen = self.config["dest_regen"].get()
relative_to = self.config["relative_to"].get()
if relative_to:
relative_to = normpath(relative_to)
@ -318,6 +326,8 @@ class SmartPlaylistPlugin(BeetsPlugin):
if tpl:
item_uri = tpl.replace("$id", str(item.id)).encode("utf-8")
else:
if dest_regen is True:
item_uri = item.destination()
if relative_to:
item_uri = os.path.relpath(item_uri, relative_to)
if self.config["forward_slash"].get():