From 13c3d064cf7c40b70dcbd83f0acff4439960cbd7 Mon Sep 17 00:00:00 2001 From: "Evan G." Date: Sat, 20 Jul 2024 17:00:29 -0500 Subject: [PATCH] Allow user to use m3u in relative_to to create playlists relative to the m3u_path --- beetsplug/smartplaylist.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/beetsplug/smartplaylist.py b/beetsplug/smartplaylist.py index 9df2cca64..f494f4c95 100644 --- a/beetsplug/smartplaylist.py +++ b/beetsplug/smartplaylist.py @@ -259,7 +259,7 @@ class SmartPlaylistPlugin(BeetsPlugin): tpl = self.config["uri_format"].get() prefix = bytestring_path(self.config["prefix"].as_str()) relative_to = self.config["relative_to"].get() - if relative_to: + if relative_to != "m3u": relative_to = normpath(relative_to) # Maps playlist filenames to lists of track filenames. @@ -289,6 +289,8 @@ class SmartPlaylistPlugin(BeetsPlugin): item_uri = item.path if tpl: item_uri = tpl.replace("$id", str(item.id)).encode("utf-8") + if relative_to == "m3u": + item_uri = "m3u" else: if relative_to: item_uri = os.path.relpath(item_uri, relative_to) @@ -325,6 +327,13 @@ class SmartPlaylistPlugin(BeetsPlugin): f.write(b"#EXTM3U\n") for entry in m3us[m3u]: item = entry.item + if entry.uri == "m3u": + entry.uri = os.path.relpath(item.path, os.path.dirname(m3u_path)) + if self.config["forward_slash"].get(): + item_uri = path_as_posix(item_uri) + if self.config["urlencode"]: + item_uri = bytestring_path(pathname2url(item_uri)) + item_uri = prefix + item_uri comment = "" if extm3u: attr = [(k, entry.item[k]) for k in keys]