Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/linkplay/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,14 @@ def album(self) -> str:

@property
def album_art(self) -> str:
"""Returns the url to the album art."""
return self.metainfo.get(MetaInfo.METADATA, {}).get(
"""Returns the url to the album art, or an empty string if there is none."""
album_art = self.metainfo.get(MetaInfo.METADATA, {}).get(
MetaInfoMetaData.ALBUM_ART, ""
)
# Devices report missing album art as a placeholder such as "unknow"
if not album_art.startswith(("http://", "https://")):
return ""
return album_art

@property
def volume(self) -> int:
Expand Down
27 changes: 27 additions & 0 deletions tests/linkplay/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
EqualizerMode,
LinkPlayCommand,
LoopMode,
MetaInfo,
MetaInfoMetaData,
MuteMode,
PlayerAttribute,
PlayingMode,
Expand Down Expand Up @@ -602,6 +604,31 @@ async def mock_session_call_api_json_side_effect(endpoint, session, command):
mock_api.assert_called_with("http://1.2.3.4", None, LinkPlayCommand.META_INFO)


@pytest.mark.parametrize(
("album_art_uri", "expected"),
[
("https://example.com/cover.jpg", "https://example.com/cover.jpg"),
("http://example.com/cover.jpg", "http://example.com/cover.jpg"),
("unknow", ""),
("", ""),
],
)
def test_album_art(album_art_uri: str, expected: str):
"""Test that only http(s) album art urls are returned."""
player = LinkPlayPlayer(MagicMock())
player.metainfo = {MetaInfo.METADATA: {MetaInfoMetaData.ALBUM_ART: album_art_uri}}

assert player.album_art == expected


def test_album_art_without_metainfo():
"""Test that the album art is empty when no meta info is available."""
player = LinkPlayPlayer(MagicMock())
player.metainfo = {}

assert player.album_art == ""


async def test_audio_output_control():
"""Test that the player handles a audio output control correctly."""

Expand Down