diff --git a/beetsplug/smartplaylist.py b/beetsplug/smartplaylist.py index ab561e094a..120361d311 100644 --- a/beetsplug/smartplaylist.py +++ b/beetsplug/smartplaylist.py @@ -49,7 +49,7 @@ def __init__(self): "prefix": "", "urlencode": False, "pretend_paths": False, - "extm3u": False, + "output": "m3u", } ) @@ -91,7 +91,7 @@ def commands(self): dest="relative_to", metavar="PATH", type="string", - help="Generate playlist item paths relative to this path.", + help="generate playlist item paths relative to this path.", ) spl_update.parser.add_option( "--prefix", @@ -102,7 +102,7 @@ def commands(self): "--forward-slash", action="store_true", dest="forward_slash", - help="Force forward slash in paths within playlists.", + help="force forward slash in paths within playlists.", ) spl_update.parser.add_option( "--urlencode", @@ -110,15 +110,9 @@ def commands(self): help="URL-encode all paths.", ) spl_update.parser.add_option( - "--extm3u", - action="store_true", - help="generate extm3u/m3u8 playlists.", - ) - spl_update.parser.add_option( - "--no-extm3u", - action="store_false", - dest="extm3u", - help="generate extm3u/m3u8 playlists.", + "--output", + type="string", + help="specify the playlist format: m3u|m3u8.", ) spl_update.func = self.update_cmd return [spl_update] @@ -299,9 +293,14 @@ def update_playlists(self, lib, pretend=False): os.path.join(playlist_dir, bytestring_path(m3u)) ) mkdirall(m3u_path) - extm3u = self.config["extm3u"] + pl_format = self.config["output"].get() + if pl_format != "m3u" and pl_format != "m3u8": + msg = "Unsupported output format '{}' provided! " + msg += "Supported: m3u, m3u8" + raise Exception(msg.format(pl_format)) + m3u8 = pl_format == "m3u8" with open(syspath(m3u_path), "wb") as f: - if extm3u: + if m3u8: f.write(b"#EXTM3U\n") for entry in m3us[m3u]: path = entry["path"] @@ -311,7 +310,7 @@ def update_playlists(self, lib, pretend=False): if self.config["urlencode"]: path = bytestring_path(pathname2url(path)) comment = "" - if extm3u: + if m3u8: comment = "#EXTINF:{},{} - {}\n".format( int(item.length), item.artist, item.title ) diff --git a/docs/plugins/smartplaylist.rst b/docs/plugins/smartplaylist.rst index 1d4de4eb55..365b5af321 100644 --- a/docs/plugins/smartplaylist.rst +++ b/docs/plugins/smartplaylist.rst @@ -118,9 +118,9 @@ other configuration options are: - **urlencode**: URL-encode all paths. Default: ``no``. - **pretend_paths**: When running with ``--pretend``, show the actual file paths that will be written to the m3u file. Default: ``false``. -- **extm3u**: Generate extm3u/m3u8 playlists. Default ``ǹo``. +- **output**: Specify the playlist format: m3u|m3u8. Default ``m3u``. For many configuration options, there is a corresponding CLI option, e.g. ``--playlist-dir``, ``--relative-to``, ``--prefix``, ``--forward-slash``, -``--urlencode``, ``--extm3u``, ``--pretend-paths``. +``--urlencode``, ``--output``, ``--pretend-paths``. CLI options take precedence over those specified within the configuration file. diff --git a/test/plugins/test_smartplaylist.py b/test/plugins/test_smartplaylist.py index f36601267d..96eac625fb 100644 --- a/test/plugins/test_smartplaylist.py +++ b/test/plugins/test_smartplaylist.py @@ -191,7 +191,7 @@ def test_playlist_update(self): self.assertEqual(content, b"/tagada.mp3\n") - def test_playlist_update_extm3u(self): + def test_playlist_update_output_m3u8(self): spl = SmartPlaylistPlugin() i = MagicMock() @@ -215,7 +215,7 @@ def test_playlist_update_extm3u(self): spl._matched_playlists = [pl] dir = bytestring_path(mkdtemp()) - config["smartplaylist"]["extm3u"] = True + config["smartplaylist"]["output"] = "m3u8" config["smartplaylist"]["prefix"] = "http://beets:8337/files" config["smartplaylist"]["relative_to"] = False config["smartplaylist"]["playlist_dir"] = py3_path(dir)