Merge pull request #3848 from catap/smartplaylist-url-firendly

This commit is contained in:
Adrian Sampson 2021-08-13 21:41:28 -04:00 committed by GitHub
commit 361cabe023
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

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

View file

@ -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 <datequery>`), 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:

View file

@ -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``.