Skip to content

smartplaylist: Add --quiet option#6493

Open
JOJ0 wants to merge 7 commits intomasterfrom
spl_quiet
Open

smartplaylist: Add --quiet option#6493
JOJ0 wants to merge 7 commits intomasterfrom
spl_quiet

Conversation

@JOJ0
Copy link
Copy Markdown
Member

@JOJ0 JOJ0 commented Apr 3, 2026

Description

Adds a --quiet CLI flag and config option to the smartplaylist plugin.

The flag reduces splupdate output while keeping the matched-track counts visible, which most of all helps with the use-case of testing new queries in the config (for example - does the newly added smartplaylist's quersy match a decent amount of tracks or is it to narrow).

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 ..."

The new behavior is tested in test_splupdate_pretend_quiet_suppresses_banner

Additional refactoring

  • The __apply_opts_to_config helper was improved to also properly handle store_true values
  • Fix a tiny bug: Deduplicate playlist entries by URI and only increment matched counts when a new entry is added.

To Do

  • Documentation.
  • Changelog.
  • Tests.

@JOJ0 JOJ0 changed the base branch from master to spl_copy_paste_able April 3, 2026 17:44
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 68.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.16%. Comparing base (29d5fac) to head (1dff812).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/smartplaylist.py 68.00% 0 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6493      +/-   ##
==========================================
+ Coverage   70.11%   70.16%   +0.04%     
==========================================
  Files         147      147              
  Lines       18625    18638      +13     
  Branches     3038     3042       +4     
==========================================
+ Hits        13059    13077      +18     
+ Misses       4923     4921       -2     
+ Partials      643      640       -3     
Files with missing lines Coverage Δ
beetsplug/smartplaylist.py 79.14% <68.00%> (+2.88%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JOJ0 JOJ0 force-pushed the spl_copy_paste_able branch from e87d6f4 to 481ed7c Compare April 3, 2026 17:50
JOJ0 added a commit that referenced this pull request Apr 3, 2026
@JOJ0 JOJ0 added the plugin Pull requests that are plugins related label Apr 4, 2026
@snejus snejus force-pushed the spl_copy_paste_able branch from 481ed7c to b32f220 Compare April 4, 2026 12:35
@snejus snejus added smartplaylist smartplaylist plugin and removed plugin Pull requests that are plugins related labels Apr 4, 2026
Base automatically changed from spl_copy_paste_able to master April 4, 2026 12:41
@JOJ0 JOJ0 marked this pull request as ready for review April 5, 2026 06:31
@JOJ0 JOJ0 requested a review from a team as a code owner April 5, 2026 06:31
Copilot AI review requested due to automatic review settings April 5, 2026 06:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

PR add --quiet flag + quiet config for smartplaylist splupdate, to cut noisy output while still showing per-playlist match counts. Also tweak unknown-playlist error to be sorted + shell-quoted for easy copy/paste.

Changes:

  • Add --quiet CLI flag + quiet config key; suppress banner + per-item output in pretend mode.
  • Sort + POSIX shell-quote playlist names in “unknown playlist” error message.
  • Add CLI test coverage for quiet pretend output + quoted error.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
beetsplug/smartplaylist.py Implement quiet behavior, quoted error formatting, and per-playlist match-count logging.
test/plugins/test_smartplaylist.py Add regression tests for quoted error + quiet pretend output suppression.
docs/plugins/smartplaylist.rst Document new quiet option + --quiet flag.
docs/changelog.rst Note new quiet flag + improved unknown-playlist error formatting.

Comment on lines +184 to +185
self.__apply_opts_to_config(opts)
self.update_playlists(lib, opts.pretend)
self.update_playlists(lib, opts.pretend, quiet)
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grug see quiet config supposed work, but __apply_opts_to_config run after and will write opts default False into config when user not pass --quiet. then config quiet become False inside process, and later auto update (cli_exit) no longer quiet. grug suggest make --quiet option default None (like other beets commands) and only copy opts into config when value is not None / option explicitly set.

Copilot uses AI. Check for mistakes.
Comment on lines +275 to +276
self, lib: Library, pretend: bool = False, quiet: bool = False
) -> None:
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grug see update_playlists(..., quiet=False) take quiet param, but when plugin run auto mode it call update_playlists from cli_exit listener with no quiet arg. then new config option smartplaylist.quiet do nothing for auto updates. grug suggest inside update_playlists read config quiet when quiet param not explicitly set (ex: quiet is None), so config option work everywhere.

Suggested change
self, lib: Library, pretend: bool = False, quiet: bool = False
) -> None:
self,
lib: Library,
pretend: bool = False,
quiet: bool | None = None,
) -> None:
if quiet is None:
quiet = self.config["quiet"].get(bool)

Copilot uses AI. Check for mistakes.
Comment on lines +357 to +364
if item_uri not in m3us[m3u_name]:
m3us[m3u_name].append(PlaylistItem(item, item_uri))
if pretend and self.config["pretend_paths"]:
if pretend and self.config["pretend_paths"] and not quiet:
print(displayable_path(item_uri))
elif pretend:
elif pretend and not quiet:
print(item)
pretend_count += 1
self._log.info("{}: {} items matched.", name, pretend_count)
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grug see duplicate guard broken: m3us[m3u_name] is list of PlaylistItem, but code check if item_uri not in m3us[m3u_name] (bytes vs object) so always True. can write duplicate lines when item appear twice (ex item query + album_query), and pretend_count also count duplicates since increment happen even when not appended. grug suggest track uris in set (or compare against entry.uri) and only bump count when new entry actually added.

Copilot uses AI. Check for mistakes.
JOJ0 added 6 commits April 5, 2026 10:10
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 ..."
since we require handling of store_true cli options something for the `quiet`
which enhances code readability for future readers.
Deduplicate playlist output by URI instead of comparing bytes to
PlaylistItem objects. Increment matched/pretend counts only when a new
entry is actually added. This prevents duplicate lines when the same
track is reached via multiple query paths.

self.__apply_opts_to_config(opts)
self.update_playlists(lib, opts.pretend)
self.update_playlists(lib, opts.pretend, opts.quiet)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind using self.config["quiet"] in downstream functions instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

smartplaylist smartplaylist plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants