From 13c3d064cf7c40b70dcbd83f0acff4439960cbd7 Mon Sep 17 00:00:00 2001 From: "Evan G." Date: Sat, 20 Jul 2024 17:00:29 -0500 Subject: [PATCH 1/3] 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 9df2cca648..f494f4c95b 100644 --- a/beetsplug/smartplaylist.py +++ b/beetsplug/smartplaylist.py @@ -259,7 +259,7 @@ def update_playlists(self, lib, pretend=False): 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 @@ def update_playlists(self, lib, pretend=False): 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 @@ def update_playlists(self, lib, pretend=False): 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] From a929970761e8dfa2b2df1a137d3dcf90ae8065c2 Mon Sep 17 00:00:00 2001 From: "Evan G." Date: Sat, 20 Jul 2024 17:36:12 -0500 Subject: [PATCH 2/3] Changelog Update for Smartplaylist, and formatting fixing --- beetsplug/smartplaylist.py | 10 +++++++--- docs/changelog.rst | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/beetsplug/smartplaylist.py b/beetsplug/smartplaylist.py index f494f4c95b..dec7cf9be4 100644 --- a/beetsplug/smartplaylist.py +++ b/beetsplug/smartplaylist.py @@ -328,12 +328,16 @@ def update_playlists(self, lib, pretend=False): for entry in m3us[m3u]: item = entry.item if entry.uri == "m3u": - entry.uri = os.path.relpath(item.path, os.path.dirname(m3u_path)) + 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 + item_uri = bytestring_path( + pathname2url(item_uri) + ) + item_uri = prefix + item_uri comment = "" if extm3u: attr = [(k, entry.item[k]) for k in keys] diff --git a/docs/changelog.rst b/docs/changelog.rst index 7a94fa3fc3..e063586a3d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,6 +13,7 @@ New features: album queries involving `path` field have been sped up, like `beet list -a path:/path/`. +* Ability to use relative_to as "m3u" to set playlist files as relative to where each playlist is at, including subdirectories. Bug fixes: * Improved naming of temporary files by separating the random part with the file extension. From 10adecb6f86c806c5bfcefbaa99440f86166e189 Mon Sep 17 00:00:00 2001 From: "Evan G." Date: Sat, 20 Jul 2024 18:04:34 -0500 Subject: [PATCH 3/3] Fix Additonal Options- Smartplaylist --- beetsplug/smartplaylist.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/beetsplug/smartplaylist.py b/beetsplug/smartplaylist.py index dec7cf9be4..6124c7b408 100644 --- a/beetsplug/smartplaylist.py +++ b/beetsplug/smartplaylist.py @@ -332,12 +332,12 @@ def update_playlists(self, lib, pretend=False): item.path, os.path.dirname(m3u_path) ) if self.config["forward_slash"].get(): - item_uri = path_as_posix(item_uri) + entry.uri = path_as_posix(entry.uri) if self.config["urlencode"]: - item_uri = bytestring_path( - pathname2url(item_uri) + entry.uri = bytestring_path( + pathname2url(entry.uri) ) - item_uri = prefix + item_uri + entry.uri = prefix + entry.uri comment = "" if extm3u: attr = [(k, entry.item[k]) for k in keys]