Skip to content

feat(spotify): configurable bitrate#177

Merged
bjarneo merged 3 commits intobjarneo:mainfrom
gjermundgaraba:feat/spotify-bitrate-config
Apr 13, 2026
Merged

feat(spotify): configurable bitrate#177
bjarneo merged 3 commits intobjarneo:mainfrom
gjermundgaraba:feat/spotify-bitrate-config

Conversation

@gjermundgaraba
Copy link
Copy Markdown
Contributor

@gjermundgaraba gjermundgaraba commented Apr 8, 2026

Summary by CodeRabbit

  • New Features

    • Spotify streaming bitrate is now configurable in your settings. Defaults to 320 kbps; supported values are 96, 160, and 320. Values ≤ 0 default to 320; other values are rounded to the nearest supported bitrate.
  • Documentation

    • Added example config entry and docs describing the new bitrate option and its behavior.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 40706e79-a826-4805-8009-e8644f83e705

📥 Commits

Reviewing files that changed from the base of the PR and between 6cb1719 and 0457821.

📒 Files selected for processing (1)
  • config/config_test.go

📝 Walkthrough

Walkthrough

Adds a configurable Spotify bitrate: parsed from config, clamped to supported values (96, 160, 320; <=0 → 320), stored on the Spotify provider, and passed into stream creation instead of a hardcoded constant.

Changes

Cohort / File(s) Summary
Config Example & Schema
config.toml.example, config/config.go
Added optional bitrate to [spotify] and SpotifyConfig.Bitrate (default 320). Load() parses bitrate; clampSpotifyBitrate() normalizes values to {96,160,320}, treating <= 0 as 320.
Config Tests
config/config_test.go
Added assertions for default bitrate, TestClampSpotifyBitrate covering clamping/rounding, and TestLoadSpotifyBitrate writing a temp config to validate parsing and clamping.
Docs
docs/spotify.md
Documented bitrate = 320 example and behavior: default, accepted values (96,160,320), <=0 handling, and rounding to nearest supported bitrate.
Spotify Provider
external/spotify/provider.go, external/spotify/stub_windows.go
Removed package-level hardcoded bitrate. SpotifyProvider gains bitrate int; New signature updated to accept bitrate int. Stream creation uses the provider bitrate. Windows stub signature updated accordingly.
Application Integration
main.go
When initializing the Spotify provider, now passes cfg.Spotify.Bitrate into spotify.New(...).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConfigLoader
    participant App
    participant SpotifyProvider
    participant Session
    User->>ConfigLoader: start (reads config files)
    ConfigLoader->>ConfigLoader: parse [spotify].bitrate
    ConfigLoader->>ConfigLoader: clampSpotifyBitrate(value) -> supported bitrate
    ConfigLoader->>App: return Config (Spotify.Bitrate)
    App->>SpotifyProvider: New(session=nil, clientID, bitrate)
    SpotifyProvider->>Session: session.NewStream(trackID, bitrate)
    Session-->>SpotifyProvider: stream (uses provided bitrate)
    SpotifyProvider-->>App: streamer
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(spotify): configurable bitrate' accurately and concisely summarizes the main change: adding configurable Spotify bitrate support across config, tests, documentation, and provider implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@config/config_test.go`:
- Around line 145-157: Add an explicit negative-input case to the
TestClampSpotifyBitrate table to cover the v <= 0 branch in clampSpotifyBitrate:
update the tests slice in TestClampSpotifyBitrate to include a case such as {
-1, 320 } so the behavior that negative inputs map to 320 is asserted (locate
the TestClampSpotifyBitrate function and the tests variable to modify).

In `@docs/spotify.md`:
- Line 27: Update the docs text for the bitrate option to explicitly state that
non-positive values are treated as 320 rather than being rounded: mention that
when bitrate <= 0 the implementation maps it to 320, while unsupported positive
values are rounded to the nearest supported bitrate (96, 160, 320); reference
the config/option name "bitrate" and the implementation behavior that checks for
<= 0 to locate where this wording should be added.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 79dee6ba-a25e-42d2-bd5d-1e42b8839d90

📥 Commits

Reviewing files that changed from the base of the PR and between cdfe752 and 43d8d9f.

📒 Files selected for processing (7)
  • config.toml.example
  • config/config.go
  • config/config_test.go
  • docs/spotify.md
  • external/spotify/provider.go
  • external/spotify/stub_windows.go
  • main.go

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@config/config_test.go`:
- Around line 145-165: The tests for clampSpotifyBitrate need explicit midpoint
cases to lock tie-breaking behavior; update TestClampSpotifyBitrate in
config_test.go to include inputs exactly at midpoints between available bitrates
(e.g., 128 and 240) and assert the function returns the lower option
(clampSpotifyBitrate(128) == 96 and clampSpotifyBitrate(240) == 160) so the
current "pick lower on tie" behavior is preserved.
- Around line 356-387: Add a non-positive test case to TestLoadSpotifyBitrate:
include an entry like {"non-positive value", 0, ClampSpotifyBitrate(0)} (or use
the known clamp/default value) so Load() integration asserts that
cfg.Spotify.Bitrate is clamped when the TOML contains a non-positive bitrate;
update the tests slice in TestLoadSpotifyBitrate and keep the same
setup/verification that compares cfg.Spotify.Bitrate to the expected value
derived from ClampSpotifyBitrate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a614ce81-fff4-48c9-9a17-5aaff654fa73

📥 Commits

Reviewing files that changed from the base of the PR and between 43d8d9f and 6cb1719.

📒 Files selected for processing (4)
  • config/config_test.go
  • docs/spotify.md
  • external/spotify/provider.go
  • external/spotify/stub_windows.go

@bjarneo bjarneo merged commit 5f3586f into bjarneo:main Apr 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants