Skip to content

Commit

Permalink
Mask spotify content in owntone library (home-assistant#79247)
Browse files Browse the repository at this point in the history
  • Loading branch information
uvjustin authored and balloob committed Sep 30, 2022
1 parent e3d4a7c commit adc5e9f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions homeassistant/components/forked_daapd/browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ def create_browse_media_response(
if not children: # Directory searches will pass in subdirectories as children
children = []
for item in result:
if item.get("data_kind") == "spotify" or (
"path" in item and cast(str, item["path"]).startswith("spotify")
): # Exclude spotify data from Owntone library
continue
assert isinstance(item["uri"], str)
media_type = OWNTONE_TYPE_TO_MEDIA_TYPE[item["uri"].split(":")[1]]
title = item.get("name") or item.get("title") # only tracks use title
Expand Down
28 changes: 27 additions & 1 deletion tests/components/forked_daapd/test_browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from unittest.mock import patch

from homeassistant.components import media_source, spotify
from homeassistant.components.forked_daapd.browse_media import create_media_content_id
from homeassistant.components.forked_daapd.browse_media import (
MediaContent,
create_media_content_id,
is_owntone_media_content_id,
)
from homeassistant.components.media_player import BrowseMedia, MediaClass, MediaType
from homeassistant.components.spotify.const import (
MEDIA_PLAYER_PREFIX as SPOTIFY_MEDIA_PLAYER_PREFIX,
Expand Down Expand Up @@ -111,6 +115,16 @@ async def test_async_browse_media(hass, hass_ws_client, config_entry):
"length_ms": 2951554,
"uri": "library:artist:3815427709949443149",
},
{
"id": "456",
"name": "Spotify Artist",
"name_sort": "Spotify Artist",
"album_count": 1,
"track_count": 10,
"length_ms": 2254,
"uri": "spotify:artist:abc123",
"data_kind": "spotify",
},
]
mock_api.return_value.get_genres.return_value = [
{"name": "Classical"},
Expand All @@ -127,6 +141,13 @@ async def test_async_browse_media(hass, hass_ws_client, config_entry):
"smart_playlist": False,
"uri": "library:playlist:1",
},
{
"id": 2,
"name": "Spotify Playlist",
"path": "spotify:playlist:abc123",
"smart_playlist": False,
"uri": "library:playlist:2",
},
]

# Request browse root through WebSocket
Expand All @@ -150,6 +171,11 @@ async def browse_children(children):
"""Browse the children of this BrowseMedia."""
nonlocal msg_id
for child in children:
# Assert Spotify content is not passed through as Owntone media
assert not (
is_owntone_media_content_id(child["media_content_id"])
and "Spotify" in MediaContent(child["media_content_id"]).title
)
if child["can_expand"]:
await client.send_json(
{
Expand Down

0 comments on commit adc5e9f

Please sign in to comment.