Allow user to use m3u in relative_to to create playlists relative to the m3u_path

This commit is contained in:
Evan G. 2024-07-20 17:00:29 -05:00
parent 1163645604
commit 13c3d064cf
No known key found for this signature in database
GPG key ID: 55FAB8CB6842F080

View file

@ -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]