Skip to content

Commit b0f7418

Browse files
committed
Stream-friendly smart playlists
This commit introduced a way to generate a stream-frienldy playlists.
1 parent 58cfa73 commit b0f7418

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

beetsplug/smartplaylist.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
import os
2929
import six
3030

31+
try:
32+
from urllib.request import pathname2url
33+
except ImportError:
34+
# python2 is a bit different
35+
from urllib import pathname2url
36+
3137

3238
class SmartPlaylistPlugin(BeetsPlugin):
3339

@@ -39,8 +45,11 @@ def __init__(self):
3945
'auto': True,
4046
'playlists': [],
4147
'forward_slash': False,
48+
'prefix': u'',
49+
'urlencode': False,
4250
})
4351

52+
self.config['prefix'].redact = True # May contain username/password.
4453
self._matched_playlists = None
4554
self._unmatched_playlists = None
4655

@@ -201,6 +210,7 @@ def update_playlists(self, lib):
201210
if item_path not in m3us[m3u_name]:
202211
m3us[m3u_name].append(item_path)
203212

213+
prefix = bytestring_path(self.config['prefix'].as_str())
204214
# Write all of the accumulated track lists to files.
205215
for m3u in m3us:
206216
m3u_path = normpath(os.path.join(playlist_dir,
@@ -210,6 +220,8 @@ def update_playlists(self, lib):
210220
for path in m3us[m3u]:
211221
if self.config['forward_slash'].get():
212222
path = path_as_posix(path)
213-
f.write(path + b'\n')
223+
if self.config['urlencode']:
224+
path = bytestring_path(pathname2url(path))
225+
f.write(prefix + path + b'\n')
214226

215227
self._log.info(u"{0} playlists updated", len(self._matched_playlists))

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,9 @@ And many little fixes and improvements:
21662166
* When there's a parse error in a query (for example, when you type a
21672167
malformed date in a :ref:`date query <datequery>`), beets now stops with an
21682168
error instead of silently ignoring the query component.
2169+
* :doc:`/plugins/smartplaylist`: Stream-friendly smart playlists.
2170+
The ``splupdate`` command can now also add a URL-encodable prefix to every
2171+
path in the playlist file.
21692172

21702173
For developers:
21712174

docs/plugins/smartplaylist.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,7 @@ other configuration options are:
101101
If you intend to use this plugin to generate playlists for MPD on
102102
Windows, set this to yes.
103103
Default: Use system separator.
104+
- **prefix**: Prepend this string to every path in the playlist file. For
105+
example, you could use the URL for a server where the music is stored.
106+
Default: empty string.
107+
- **urlencoded**: URL-encode all paths. Default: ``no``.

0 commit comments

Comments
 (0)