Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to use m3u in relative_to to create playlists relative to m3u_path #5365

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion beetsplug/smartplaylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -325,6 +327,17 @@ 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():
entry.uri = path_as_posix(entry.uri)
if self.config["urlencode"]:
entry.uri = bytestring_path(
pathname2url(entry.uri)
)
entry.uri = prefix + entry.uri
comment = ""
if extm3u:
attr = [(k, entry.item[k]) for k in keys]
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
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:

Check failure on line 17 in docs/changelog.rst

View workflow job for this annotation

GitHub Actions / Check docs

Bullet list ends without a blank line; unexpected unindent.

* Improved naming of temporary files by separating the random part with the file extension.
* Fixed the ``auto`` value for the :ref:`reflink` config option.
Expand Down
Loading