Skip to content

Commit

Permalink
Merge pull request beetbox#5053 from mgoltzsche/change-smartplaylist-…
Browse files Browse the repository at this point in the history
…extm3u-option

smartplaylist: change option --extm3u to --output
  • Loading branch information
Serene-Arc committed Dec 16, 2023
2 parents b803d84 + 385c05f commit adf4b97
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
29 changes: 14 additions & 15 deletions beetsplug/smartplaylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self):
"prefix": "",
"urlencode": False,
"pretend_paths": False,
"extm3u": False,
"output": "m3u",
}
)

Expand Down Expand Up @@ -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",
Expand All @@ -102,23 +102,17 @@ 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",
action="store_true",
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]
Expand Down Expand Up @@ -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"]
Expand All @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ New features:
`synced` option to prefer synced lyrics over plain lyrics.
* :ref:`import-cmd`: Expose import.quiet_fallback as CLI option.
* :ref:`import-cmd`: Expose `import.incremental_skip_later` as CLI option.
* :doc:`/plugins/smartplaylist`: Add new config option `smartplaylist.extm3u`.
* :doc:`/plugins/smartplaylist`: Add new config option `smartplaylist.output`.
* :doc:`/plugins/smartplaylist`: Expose config options as CLI options.

Bug fixes:
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/smartplaylist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions test/plugins/test_smartplaylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit adf4b97

Please sign in to comment.