Skip to content

Use the logged-in account for YouTube Music searches - #5896

Merged
MarvinSchenkel merged 3 commits into
devfrom
fix/ytmusic-authenticated-search
Aug 21, 2026
Merged

Use the logged-in account for YouTube Music searches#5896
MarvinSchenkel merged 3 commits into
devfrom
fix/ytmusic-authenticated-search

Conversation

@MarvinSchenkel

@MarvinSchenkel MarvinSchenkel commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

What does this implement/fix?

YouTube Music searches were performed without the user's credentials, while every other YTM call already authenticates. Because of that, YouTube could not apply the account and region context to search results, so tracks that are not playable for the user were still returned as regular results (and failed with "No playable items found" when played).

  • Pass the account headers and (brand account) user to the ytmusicapi search call, like all other YTM helpers already do.
  • Add a regression test that verifies search authenticates its client.

Note: the full fix for the linked issue also needs an upstream ytmusicapi change to expose the availability flag on search results (sigma67/ytmusicapi#1001); this PR is the server-side part and is safe on its own.

Related issue (if applicable):

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • New music/player/metadata/plugin provider — new-provider
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — documentation
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • pre-commit run --all-files passes.
  • pytest passes, and tests have been added/updated under tests/ where applicable.
  • For changes to shared models, the companion PR in music-assistant/models is linked.
  • For changes affecting the UI, the companion PR in music-assistant/frontend is linked.
  • I have read and complied with the project's AI Policy for any AI-assisted contributions.
  • I have raised a PR against the documentation repository targeting the main or beta branch as appropriate.

Copilot AI balanced review requested due to automatic review settings August 21, 2026 09:17
@musicassistant-bot

musicassistant-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

✅ The title and description are good to go. Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Authenticates YouTube Music searches so results respect the user’s account, region, and brand account context.

Changes:

  • Passes authentication headers and user context into searches.
  • Adds regression coverage for authenticated client construction.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
music_assistant/providers/ytmusic/helpers.py Authenticates the search client.
music_assistant/providers/ytmusic/__init__.py Supplies provider account context.
tests/providers/ytmusic/test_helpers.py Tests authenticated search setup.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread music_assistant/providers/ytmusic/__init__.py
@MarvinSchenkel
MarvinSchenkel marked this pull request as ready for review August 21, 2026 09:23
Copilot AI review requested due to automatic review settings August 21, 2026 09:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

music_assistant/providers/ytmusic/helpers.py:340

  • [PROBLEM] This is a user-visible bug fix, but the PR is classified as Maintenance; select the Bugfix checkbox instead so CI applies the correct label and the change appears in the bug-fix release notes.
        ytm = ytmusicapi.YTMusic(auth=headers, language=language, user=user)

Copilot AI review requested due to automatic review settings August 21, 2026 09:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread music_assistant/providers/builtin/__init__.py Outdated
Copilot AI review requested due to automatic review settings August 21, 2026 09:32
@MarvinSchenkel
MarvinSchenkel force-pushed the fix/ytmusic-authenticated-search branch from 184d777 to 90eab2d Compare August 21, 2026 09:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

music_assistant/providers/ytmusic/init.py:220

  • [CRITICAL] This constant only invalidates the old anonymous entries once, but the newly cached results are account-specific: reconfiguring this provider with another username/cookie preserves its instance_id, and provider reload does not clear that cache (music_assistant/mass.py:1292-1295, 1035-1074), so the previous account/region's search results can be served for seven days. Include a non-secret account-context discriminator in the search cache key/checksum, or clear these entries when credentials change.
    @use_cache(3600 * 24 * 7, cache_checksum="authenticated_search_v1")  # Cache for 7 days

music_assistant/providers/ytmusic/helpers.py:340

  • [PROBLEM] This is a user-visible bug fix, but the PR description selects “Maintenance / chore”; because CI derives the release label and release-notes category from that checkbox, select “Bugfix” instead.
        ytm = ytmusicapi.YTMusic(auth=headers, language=language, user=user)

@MarvinSchenkel
MarvinSchenkel merged commit 06e6628 into dev Aug 21, 2026
18 checks passed
@MarvinSchenkel
MarvinSchenkel deleted the fix/ytmusic-authenticated-search branch August 21, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants