smartplaylist: rename output format m3u8 to extm3u

This commit is contained in:
Max Goltzsche 2024-03-17 19:02:16 +01:00
parent c0afd3eb3c
commit 883bbb3e4b
No known key found for this signature in database
GPG key ID: 364FA5A62B410BA4
3 changed files with 12 additions and 12 deletions

View file

@ -121,7 +121,7 @@ class SmartPlaylistPlugin(BeetsPlugin):
spl_update.parser.add_option( spl_update.parser.add_option(
"--output", "--output",
type="string", type="string",
help="specify the playlist format: m3u|m3u8.", help="specify the playlist format: m3u|extm3u.",
) )
spl_update.func = self.update_cmd spl_update.func = self.update_cmd
return [spl_update] return [spl_update]
@ -313,20 +313,20 @@ class SmartPlaylistPlugin(BeetsPlugin):
) )
mkdirall(m3u_path) mkdirall(m3u_path)
pl_format = self.config["output"].get() pl_format = self.config["output"].get()
if pl_format != "m3u" and pl_format != "m3u8": if pl_format != "m3u" and pl_format != "extm3u":
msg = "Unsupported output format '{}' provided! " msg = "Unsupported output format '{}' provided! "
msg += "Supported: m3u, m3u8" msg += "Supported: m3u, extm3u"
raise Exception(msg.format(pl_format)) raise Exception(msg.format(pl_format))
m3u8 = pl_format == "m3u8" extm3u = pl_format == "extm3u"
with open(syspath(m3u_path), "wb") as f: with open(syspath(m3u_path), "wb") as f:
keys = [] keys = []
if m3u8: if extm3u:
keys = self.config["fields"].get(list) keys = self.config["fields"].get(list)
f.write(b"#EXTM3U\n") f.write(b"#EXTM3U\n")
for entry in m3us[m3u]: for entry in m3us[m3u]:
item = entry.item item = entry.item
comment = "" comment = ""
if m3u8: if extm3u:
attr = [(k, entry.item[k]) for k in keys] attr = [(k, entry.item[k]) for k in keys]
al = [ al = [
f" {a[0]}={json.dumps(str(a[1]))}" for a in attr f" {a[0]}={json.dumps(str(a[1]))}" for a in attr

View file

@ -122,11 +122,11 @@ other configuration options are:
playlist item URI, e.g. ``http://beets:8337/item/$id/file``. playlist item URI, e.g. ``http://beets:8337/item/$id/file``.
When this option is specified, the local path-related options ``prefix``, When this option is specified, the local path-related options ``prefix``,
``relative_to``, ``forward_slash`` and ``urlencode`` are ignored. ``relative_to``, ``forward_slash`` and ``urlencode`` are ignored.
- **output**: Specify the playlist format: m3u|m3u8. Default ``m3u``. - **output**: Specify the playlist format: m3u|extm3u. Default ``m3u``.
- **fields**: Specify the names of the additional item fields to export into - **fields**: Specify the names of the additional item fields to export into
the playlist. This allows using e.g. the ``id`` field within other tools such the playlist. This allows using e.g. the ``id`` field within other tools such
as the `webm3u`_ plugin. as the `webm3u`_ plugin.
To use this option, you must set the ``output`` option to ``m3u8``. To use this option, you must set the ``output`` option to ``extm3u``.
.. _webm3u: https://github.com/mgoltzsche/beets-webm3u .. _webm3u: https://github.com/mgoltzsche/beets-webm3u

View file

@ -191,7 +191,7 @@ class SmartPlaylistTest(_common.TestCase):
self.assertEqual(content, b"/tagada.mp3\n") self.assertEqual(content, b"/tagada.mp3\n")
def test_playlist_update_output_m3u8(self): def test_playlist_update_output_extm3u(self):
spl = SmartPlaylistPlugin() spl = SmartPlaylistPlugin()
i = MagicMock() i = MagicMock()
@ -215,7 +215,7 @@ class SmartPlaylistTest(_common.TestCase):
spl._matched_playlists = [pl] spl._matched_playlists = [pl]
dir = bytestring_path(mkdtemp()) dir = bytestring_path(mkdtemp())
config["smartplaylist"]["output"] = "m3u8" config["smartplaylist"]["output"] = "extm3u"
config["smartplaylist"]["prefix"] = "http://beets:8337/files" config["smartplaylist"]["prefix"] = "http://beets:8337/files"
config["smartplaylist"]["relative_to"] = False config["smartplaylist"]["relative_to"] = False
config["smartplaylist"]["playlist_dir"] = py3_path(dir) config["smartplaylist"]["playlist_dir"] = py3_path(dir)
@ -241,7 +241,7 @@ class SmartPlaylistTest(_common.TestCase):
+ b"http://beets:8337/files/tagada.mp3\n", + b"http://beets:8337/files/tagada.mp3\n",
) )
def test_playlist_update_output_m3u8_fields(self): def test_playlist_update_output_extm3u_fields(self):
spl = SmartPlaylistPlugin() spl = SmartPlaylistPlugin()
i = MagicMock() i = MagicMock()
@ -267,7 +267,7 @@ class SmartPlaylistTest(_common.TestCase):
spl._matched_playlists = [pl] spl._matched_playlists = [pl]
dir = bytestring_path(mkdtemp()) dir = bytestring_path(mkdtemp())
config["smartplaylist"]["output"] = "m3u8" config["smartplaylist"]["output"] = "extm3u"
config["smartplaylist"]["relative_to"] = False config["smartplaylist"]["relative_to"] = False
config["smartplaylist"]["playlist_dir"] = py3_path(dir) config["smartplaylist"]["playlist_dir"] = py3_path(dir)
config["smartplaylist"]["fields"] = ["id", "genre"] config["smartplaylist"]["fields"] = ["id", "genre"]