diff --git a/beetsplug/smartplaylist.py b/beetsplug/smartplaylist.py index 700b0c76a..923703f57 100644 --- a/beetsplug/smartplaylist.py +++ b/beetsplug/smartplaylist.py @@ -28,6 +28,12 @@ from beets.dbcore.query import MultipleSort, ParsingError import os import six +try: + from urllib.request import pathname2url +except ImportError: + # python2 is a bit different + from urllib import pathname2url + class SmartPlaylistPlugin(BeetsPlugin): @@ -39,8 +45,11 @@ class SmartPlaylistPlugin(BeetsPlugin): 'auto': True, 'playlists': [], 'forward_slash': False, + 'prefix': u'', + 'urlencode': False, }) + self.config['prefix'].redact = True # May contain username/password. self._matched_playlists = None self._unmatched_playlists = None @@ -201,6 +210,7 @@ class SmartPlaylistPlugin(BeetsPlugin): if item_path not in m3us[m3u_name]: m3us[m3u_name].append(item_path) + prefix = bytestring_path(self.config['prefix'].as_str()) # Write all of the accumulated track lists to files. for m3u in m3us: m3u_path = normpath(os.path.join(playlist_dir, @@ -210,6 +220,8 @@ class SmartPlaylistPlugin(BeetsPlugin): for path in m3us[m3u]: if self.config['forward_slash'].get(): path = path_as_posix(path) - f.write(path + b'\n') + if self.config['urlencode']: + path = bytestring_path(pathname2url(path)) + f.write(prefix + path + b'\n') self._log.info(u"{0} playlists updated", len(self._matched_playlists)) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5eae9c855..33b333953 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2166,6 +2166,9 @@ And many little fixes and improvements: * When there's a parse error in a query (for example, when you type a malformed date in a :ref:`date query `), beets now stops with an error instead of silently ignoring the query component. +* :doc:`/plugins/smartplaylist`: Stream-friendly smart playlists. + The ``splupdate`` command can now also add a URL-encodable prefix to every + path in the playlist file. For developers: diff --git a/docs/plugins/smartplaylist.rst b/docs/plugins/smartplaylist.rst index dd3ee45ba..553ee48af 100644 --- a/docs/plugins/smartplaylist.rst +++ b/docs/plugins/smartplaylist.rst @@ -101,3 +101,7 @@ other configuration options are: If you intend to use this plugin to generate playlists for MPD on Windows, set this to yes. Default: Use system separator. +- **prefix**: Prepend this string to every path in the playlist file. For + example, you could use the URL for a server where the music is stored. + Default: empty string. +- **urlencoded**: URL-encode all paths. Default: ``no``.