Skip to content

Commit e8286cb

Browse files
committed
smartplaylist: Add --quiet option
Add a --quiet flag to reduce splupdate output while keeping the matched-track counts visible, which helps when testing new queries in the config. In pretend mode: - suppress "Results for playlist ..." - suppress "Showing query results for X smart playlists..." - suppress the list of matching tracks, including --pretend-paths output - replace the final "Displayed results ..." message with a shorter "... playlists would be updated" summary When updating: - suppress "Creating playlist ..."
1 parent eeb8fdb commit e8286cb

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

beetsplug/smartplaylist.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(self) -> None:
6666
"urlencode": False,
6767
"pretend_paths": False,
6868
"output": "m3u",
69+
"quiet": False,
6970
}
7071
)
7172

@@ -94,6 +95,13 @@ def commands(self) -> list[ui.Subcommand]:
9495
dest="pretend_paths",
9596
help="in pretend mode, log the playlist item URIs/paths.",
9697
)
98+
spl_update.parser.add_option(
99+
"-q",
100+
"--quiet",
101+
action="store_true",
102+
dest="quiet",
103+
help="reduce output during playlist updates and pretend mode",
104+
)
97105
spl_update.parser.add_option(
98106
"-d",
99107
"--playlist-dir",
@@ -263,12 +271,13 @@ def db_change(self, lib: Library, model: Item | Album) -> None:
263271
self._unmatched_playlists -= self._matched_playlists
264272

265273
def update_playlists(self, lib: Library, pretend: bool = False) -> None:
266-
if pretend:
274+
quiet = self.config["quiet"].get(bool)
275+
if pretend and not quiet:
267276
self._log.info(
268277
"Showing query results for {} smart playlists...",
269278
len(self._matched_playlists),
270279
)
271-
else:
280+
elif not pretend:
272281
self._log.info(
273282
"Updating {} smart playlists...", len(self._matched_playlists)
274283
)
@@ -287,10 +296,11 @@ def update_playlists(self, lib: Library, pretend: bool = False) -> None:
287296
m3us: dict[str, list[PlaylistItem]] = {}
288297

289298
for playlist in self._matched_playlists:
299+
pretend_count = 0
290300
name, (query, q_sort), (album_query, a_q_sort) = playlist
291-
if pretend:
301+
if pretend and not quiet:
292302
self._log.info("Results for playlist {}:", name)
293-
else:
303+
elif not quiet:
294304
self._log.info("Creating playlist {}", name)
295305
items = []
296306

@@ -344,10 +354,13 @@ def update_playlists(self, lib: Library, pretend: bool = False) -> None:
344354

345355
if item_uri not in m3us[m3u_name]:
346356
m3us[m3u_name].append(PlaylistItem(item, item_uri))
347-
if pretend and self.config["pretend_paths"]:
357+
if pretend and self.config["pretend_paths"] and not quiet:
348358
print(displayable_path(item_uri))
349-
elif pretend:
359+
elif pretend and not quiet:
350360
print(item)
361+
pretend_count += 1
362+
if quiet:
363+
self._log.info("{}: {} items matched.", name, pretend_count)
351364

352365
if not pretend:
353366
# Write all of the accumulated track lists to files.
@@ -385,11 +398,15 @@ def update_playlists(self, lib: Library, pretend: bool = False) -> None:
385398
# Send an event when playlists were updated.
386399
send_event("smartplaylist_update") # type: ignore
387400

388-
if pretend:
401+
if pretend and not quiet:
389402
self._log.info(
390403
"Displayed results for {} playlists",
391404
len(self._matched_playlists),
392405
)
406+
elif pretend:
407+
self._log.info(
408+
"{} playlists would be updated", len(self._matched_playlists)
409+
)
393410
else:
394411
self._log.info("{} playlists updated", len(self._matched_playlists))
395412

0 commit comments

Comments
 (0)