Remove Spotify featured playlists and categories from media browser (#131758)

This commit is contained in:
Joost Lekkerkerker 2024-11-28 12:34:06 +01:00 committed by Franck Nijhof
parent 7ab1bfcf1f
commit 80bc70771e
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
8 changed files with 0 additions and 431 deletions

View File

@ -101,8 +101,6 @@ class BrowsableMedia(StrEnum):
CURRENT_USER_RECENTLY_PLAYED = "current_user_recently_played"
CURRENT_USER_TOP_ARTISTS = "current_user_top_artists"
CURRENT_USER_TOP_TRACKS = "current_user_top_tracks"
CATEGORIES = "categories"
FEATURED_PLAYLISTS = "featured_playlists"
NEW_RELEASES = "new_releases"
@ -115,8 +113,6 @@ LIBRARY_MAP = {
BrowsableMedia.CURRENT_USER_RECENTLY_PLAYED.value: "Recently played",
BrowsableMedia.CURRENT_USER_TOP_ARTISTS.value: "Top Artists",
BrowsableMedia.CURRENT_USER_TOP_TRACKS.value: "Top Tracks",
BrowsableMedia.CATEGORIES.value: "Categories",
BrowsableMedia.FEATURED_PLAYLISTS.value: "Featured Playlists",
BrowsableMedia.NEW_RELEASES.value: "New Releases",
}
@ -153,18 +149,6 @@ CONTENT_TYPE_MEDIA_CLASS: dict[str, Any] = {
"parent": MediaClass.DIRECTORY,
"children": MediaClass.TRACK,
},
BrowsableMedia.FEATURED_PLAYLISTS.value: {
"parent": MediaClass.DIRECTORY,
"children": MediaClass.PLAYLIST,
},
BrowsableMedia.CATEGORIES.value: {
"parent": MediaClass.DIRECTORY,
"children": MediaClass.GENRE,
},
"category_playlists": {
"parent": MediaClass.DIRECTORY,
"children": MediaClass.PLAYLIST,
},
BrowsableMedia.NEW_RELEASES.value: {
"parent": MediaClass.DIRECTORY,
"children": MediaClass.ALBUM,
@ -354,32 +338,6 @@ async def build_item_response( # noqa: C901
elif media_content_type == BrowsableMedia.CURRENT_USER_TOP_TRACKS:
if top_tracks := await spotify.get_top_tracks():
items = [_get_track_item_payload(track) for track in top_tracks]
elif media_content_type == BrowsableMedia.FEATURED_PLAYLISTS:
if featured_playlists := await spotify.get_featured_playlists():
items = [
_get_playlist_item_payload(playlist) for playlist in featured_playlists
]
elif media_content_type == BrowsableMedia.CATEGORIES:
if categories := await spotify.get_categories():
items = [
{
"id": category.category_id,
"name": category.name,
"type": "category_playlists",
"uri": category.category_id,
"thumbnail": category.icons[0].url if category.icons else None,
}
for category in categories
]
elif media_content_type == "category_playlists":
if (
playlists := await spotify.get_category_playlists(
category_id=media_content_id
)
) and (category := await spotify.get_category(media_content_id)):
title = category.name
image = category.icons[0].url if category.icons else None
items = [_get_playlist_item_payload(playlist) for playlist in playlists]
elif media_content_type == BrowsableMedia.NEW_RELEASES:
if new_releases := await spotify.get_new_releases():
items = [_get_album_item_payload(album) for album in new_releases]
@ -429,36 +387,6 @@ async def build_item_response( # noqa: C901
_LOGGER.debug("Unknown media type received: %s", media_content_type)
return None
if media_content_type == BrowsableMedia.CATEGORIES:
media_item = BrowseMedia(
can_expand=True,
can_play=False,
children_media_class=media_class["children"],
media_class=media_class["parent"],
media_content_id=media_content_id,
media_content_type=f"{MEDIA_PLAYER_PREFIX}{media_content_type}",
title=LIBRARY_MAP.get(media_content_id, "Unknown"),
)
media_item.children = []
for item in items:
if (item_id := item["id"]) is None:
_LOGGER.debug("Missing ID for media item: %s", item)
continue
media_item.children.append(
BrowseMedia(
can_expand=True,
can_play=False,
children_media_class=MediaClass.TRACK,
media_class=MediaClass.PLAYLIST,
media_content_id=item_id,
media_content_type=f"{MEDIA_PLAYER_PREFIX}category_playlists",
thumbnail=item["thumbnail"],
title=item["name"],
)
)
return media_item
if title is None:
title = LIBRARY_MAP.get(media_content_id, "Unknown")

View File

@ -9,11 +9,7 @@ from spotifyaio.models import (
Album,
Artist,
ArtistResponse,
CategoriesResponse,
Category,
CategoryPlaylistResponse,
Devices,
FeaturedPlaylistResponse,
NewReleasesResponse,
NewReleasesResponseInner,
PlaybackState,
@ -134,7 +130,6 @@ def mock_spotify() -> Generator[AsyncMock]:
PlaybackState,
),
("current_user.json", "get_current_user", UserProfile),
("category.json", "get_category", Category),
("playlist.json", "get_playlist", Playlist),
("album.json", "get_album", Album),
("artist.json", "get_artist", Artist),
@ -146,15 +141,6 @@ def mock_spotify() -> Generator[AsyncMock]:
client.get_followed_artists.return_value = ArtistResponse.from_json(
load_fixture("followed_artists.json", DOMAIN)
).artists.items
client.get_featured_playlists.return_value = FeaturedPlaylistResponse.from_json(
load_fixture("featured_playlists.json", DOMAIN)
).playlists.items
client.get_categories.return_value = CategoriesResponse.from_json(
load_fixture("categories.json", DOMAIN)
).categories.items
client.get_category_playlists.return_value = CategoryPlaylistResponse.from_json(
load_fixture("category_playlists.json", DOMAIN)
).playlists.items
client.get_new_releases.return_value = NewReleasesResponse.from_json(
load_fixture("new_releases.json", DOMAIN)
).albums.items

View File

@ -1,36 +0,0 @@
{
"categories": {
"href": "https://api.spotify.com/v1/browse/categories?offset=0&limit=20&locale=en-US,en;q%3D0.5",
"items": [
{
"href": "https://api.spotify.com/v1/browse/categories/0JQ5DAt0tbjZptfcdMSKl3",
"id": "0JQ5DAt0tbjZptfcdMSKl3",
"icons": [
{
"height": 274,
"url": "https://t.scdn.co/images/728ed47fc1674feb95f7ac20236eb6d7.jpeg",
"width": 274
}
],
"name": "Made For You"
},
{
"href": "https://api.spotify.com/v1/browse/categories/0JQ5DAqbMKFz6FAsUtgAab",
"id": "0JQ5DAqbMKFz6FAsUtgAab",
"icons": [
{
"height": 274,
"url": "https://t.scdn.co/images/728ed47fc1674feb95f7ac20236eb6d7.jpeg",
"width": 274
}
],
"name": "New Releases"
}
],
"limit": 20,
"next": "https://api.spotify.com/v1/browse/categories?offset=20&limit=20&locale=en-US,en;q%3D0.5",
"offset": 0,
"previous": null,
"total": 56
}
}

View File

@ -1,12 +0,0 @@
{
"href": "https://api.spotify.com/v1/browse/categories/0JQ5DAqbMKFRY5ok2pxXJ0",
"id": "0JQ5DAqbMKFRY5ok2pxXJ0",
"icons": [
{
"height": 274,
"url": "https://t.scdn.co/media/original/dinner_1b6506abba0ba52c54e6d695c8571078_274x274.jpg",
"width": 274
}
],
"name": "Cooking & Dining"
}

View File

@ -1,84 +0,0 @@
{
"playlists": {
"href": "https://api.spotify.com/v1/browse/categories/0JQ5DAqbMKFRY5ok2pxXJ0/playlists?country=NL&offset=0&limit=20",
"items": [
{
"collaborative": false,
"description": "Lekker eten en lang natafelen? Daar hoort muziek bij.",
"external_urls": {
"spotify": "https://open.spotify.com/playlist/37i9dQZF1DX7yhuKT9G4qk"
},
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DX7yhuKT9G4qk",
"id": "37i9dQZF1DX7yhuKT9G4qk",
"images": [
{
"height": null,
"url": "https://i.scdn.co/image/ab67706f0000000343319faa9428405f3312b588",
"width": null
}
],
"name": "eten met vrienden",
"owner": {
"display_name": "Spotify",
"external_urls": {
"spotify": "https://open.spotify.com/user/spotify"
},
"href": "https://api.spotify.com/v1/users/spotify",
"id": "spotify",
"type": "user",
"uri": "spotify:user:spotify"
},
"primary_color": null,
"public": null,
"snapshot_id": "MTcwMTY5Njk3NywwMDAwMDAwMDkyY2JjZDA1MjA2YTBmNzMxMmFlNGI0YzRhMjg0ZWZl",
"tracks": {
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DX7yhuKT9G4qk/tracks",
"total": 313
},
"type": "playlist",
"uri": "spotify:playlist:37i9dQZF1DX7yhuKT9G4qk"
},
{
"collaborative": false,
"description": "From new retro to classic country blues, honky tonk, rockabilly, and more.",
"external_urls": {
"spotify": "https://open.spotify.com/playlist/37i9dQZF1DXbvE0SE0Cczh"
},
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DXbvE0SE0Cczh",
"id": "37i9dQZF1DXbvE0SE0Cczh",
"images": [
{
"height": null,
"url": "https://i.scdn.co/image/ab67706f00000003b93c270883619dde61725fc8",
"width": null
}
],
"name": "Jukebox Joint",
"owner": {
"display_name": "Spotify",
"external_urls": {
"spotify": "https://open.spotify.com/user/spotify"
},
"href": "https://api.spotify.com/v1/users/spotify",
"id": "spotify",
"type": "user",
"uri": "spotify:user:spotify"
},
"primary_color": null,
"public": null,
"snapshot_id": "MTY4NjkxODgwMiwwMDAwMDAwMGUwNWRkNjY5N2UzM2Q4NzI4NzRiZmNhMGVmMzAyZTA5",
"tracks": {
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DXbvE0SE0Cczh/tracks",
"total": 60
},
"type": "playlist",
"uri": "spotify:playlist:37i9dQZF1DXbvE0SE0Cczh"
}
],
"limit": 20,
"next": "https://api.spotify.com/v1/browse/categories/0JQ5DAqbMKFRY5ok2pxXJ0/playlists?country=NL&offset=20&limit=20",
"offset": 0,
"previous": null,
"total": 46
}
}

View File

@ -1,85 +0,0 @@
{
"message": "Popular Playlists",
"playlists": {
"href": "https://api.spotify.com/v1/browse/featured-playlists?country=NL&timestamp=2023-12-18T18%3A35%3A35&offset=0&limit=20",
"items": [
{
"collaborative": false,
"description": "De ideale playlist voor het fijne kerstgevoel bij de boom!",
"external_urls": {
"spotify": "https://open.spotify.com/playlist/37i9dQZF1DX4dopZ9vOp1t"
},
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DX4dopZ9vOp1t",
"id": "37i9dQZF1DX4dopZ9vOp1t",
"images": [
{
"height": null,
"url": "https://i.scdn.co/image/ab67706f000000037d14c267b8ee5fea2246a8fe",
"width": null
}
],
"name": "Kerst Hits 2023",
"owner": {
"display_name": "Spotify",
"external_urls": {
"spotify": "https://open.spotify.com/user/spotify"
},
"href": "https://api.spotify.com/v1/users/spotify",
"id": "spotify",
"type": "user",
"uri": "spotify:user:spotify"
},
"primary_color": null,
"public": null,
"snapshot_id": "MTcwMjU2ODI4MSwwMDAwMDAwMDE1ZGRiNzI3OGY4OGU2MzA1MWNkZGMyNTdmNDUwMTc1",
"tracks": {
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DX4dopZ9vOp1t/tracks",
"total": 298
},
"type": "playlist",
"uri": "spotify:playlist:37i9dQZF1DX4dopZ9vOp1t"
},
{
"collaborative": false,
"description": "De 50 populairste hits van Nederland. Cover: Jack Harlow",
"external_urls": {
"spotify": "https://open.spotify.com/playlist/37i9dQZF1DWSBi5svWQ9Nk"
},
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DWSBi5svWQ9Nk",
"id": "37i9dQZF1DWSBi5svWQ9Nk",
"images": [
{
"height": null,
"url": "https://i.scdn.co/image/ab67706f00000003f7b99051789611a49101c1cf",
"width": null
}
],
"name": "Top Hits NL",
"owner": {
"display_name": "Spotify",
"external_urls": {
"spotify": "https://open.spotify.com/user/spotify"
},
"href": "https://api.spotify.com/v1/users/spotify",
"id": "spotify",
"type": "user",
"uri": "spotify:user:spotify"
},
"primary_color": null,
"public": null,
"snapshot_id": "MTcwMjU5NDgwMCwwMDAwMDAwMDU4NWY2MTE4NmU4NmIwMDdlMGE4ZGRkOTZkN2U2MzAx",
"tracks": {
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DWSBi5svWQ9Nk/tracks",
"total": 50
},
"type": "playlist",
"uri": "spotify:playlist:37i9dQZF1DWSBi5svWQ9Nk"
}
],
"limit": 20,
"next": "https://api.spotify.com/v1/browse/featured-playlists?country=NL&timestamp=2023-12-18T18%3A35%3A35&offset=20&limit=20",
"offset": 0,
"previous": null,
"total": 24
}
}

View File

@ -84,26 +84,6 @@
'thumbnail': None,
'title': 'Top Tracks',
}),
dict({
'can_expand': True,
'can_play': False,
'children_media_class': <MediaClass.GENRE: 'genre'>,
'media_class': <MediaClass.DIRECTORY: 'directory'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/categories',
'media_content_type': 'spotify://categories',
'thumbnail': None,
'title': 'Categories',
}),
dict({
'can_expand': True,
'can_play': False,
'children_media_class': <MediaClass.PLAYLIST: 'playlist'>,
'media_class': <MediaClass.DIRECTORY: 'directory'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/featured_playlists',
'media_content_type': 'spotify://featured_playlists',
'thumbnail': None,
'title': 'Featured Playlists',
}),
dict({
'can_expand': True,
'can_play': False,
@ -299,76 +279,6 @@
'title': 'Pitbull',
})
# ---
# name: test_browsing[categories-categories]
dict({
'can_expand': True,
'can_play': False,
'children': list([
dict({
'can_expand': True,
'can_play': False,
'children_media_class': <MediaClass.TRACK: 'track'>,
'media_class': <MediaClass.PLAYLIST: 'playlist'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/0JQ5DAt0tbjZptfcdMSKl3',
'media_content_type': 'spotify://category_playlists',
'thumbnail': 'https://t.scdn.co/images/728ed47fc1674feb95f7ac20236eb6d7.jpeg',
'title': 'Made For You',
}),
dict({
'can_expand': True,
'can_play': False,
'children_media_class': <MediaClass.TRACK: 'track'>,
'media_class': <MediaClass.PLAYLIST: 'playlist'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/0JQ5DAqbMKFz6FAsUtgAab',
'media_content_type': 'spotify://category_playlists',
'thumbnail': 'https://t.scdn.co/images/728ed47fc1674feb95f7ac20236eb6d7.jpeg',
'title': 'New Releases',
}),
]),
'children_media_class': <MediaClass.GENRE: 'genre'>,
'media_class': <MediaClass.DIRECTORY: 'directory'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/categories',
'media_content_type': 'spotify://categories',
'not_shown': 0,
'thumbnail': None,
'title': 'Categories',
})
# ---
# name: test_browsing[category_playlists-dinner]
dict({
'can_expand': True,
'can_play': False,
'children': list([
dict({
'can_expand': True,
'can_play': True,
'children_media_class': <MediaClass.TRACK: 'track'>,
'media_class': <MediaClass.PLAYLIST: 'playlist'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/spotify:playlist:37i9dQZF1DX7yhuKT9G4qk',
'media_content_type': 'spotify://playlist',
'thumbnail': 'https://i.scdn.co/image/ab67706f0000000343319faa9428405f3312b588',
'title': 'eten met vrienden',
}),
dict({
'can_expand': True,
'can_play': True,
'children_media_class': <MediaClass.TRACK: 'track'>,
'media_class': <MediaClass.PLAYLIST: 'playlist'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/spotify:playlist:37i9dQZF1DXbvE0SE0Cczh',
'media_content_type': 'spotify://playlist',
'thumbnail': 'https://i.scdn.co/image/ab67706f00000003b93c270883619dde61725fc8',
'title': 'Jukebox Joint',
}),
]),
'children_media_class': <MediaClass.PLAYLIST: 'playlist'>,
'media_class': <MediaClass.DIRECTORY: 'directory'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/dinner',
'media_content_type': 'spotify://category_playlists',
'not_shown': 0,
'thumbnail': 'https://t.scdn.co/media/original/dinner_1b6506abba0ba52c54e6d695c8571078_274x274.jpg',
'title': 'Cooking & Dining',
})
# ---
# name: test_browsing[current_user_followed_artists-current_user_followed_artists]
dict({
'can_expand': True,
@ -649,41 +559,6 @@
'title': 'Top Tracks',
})
# ---
# name: test_browsing[featured_playlists-featured_playlists]
dict({
'can_expand': True,
'can_play': False,
'children': list([
dict({
'can_expand': True,
'can_play': True,
'children_media_class': <MediaClass.TRACK: 'track'>,
'media_class': <MediaClass.PLAYLIST: 'playlist'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/spotify:playlist:37i9dQZF1DX4dopZ9vOp1t',
'media_content_type': 'spotify://playlist',
'thumbnail': 'https://i.scdn.co/image/ab67706f000000037d14c267b8ee5fea2246a8fe',
'title': 'Kerst Hits 2023',
}),
dict({
'can_expand': True,
'can_play': True,
'children_media_class': <MediaClass.TRACK: 'track'>,
'media_class': <MediaClass.PLAYLIST: 'playlist'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/spotify:playlist:37i9dQZF1DWSBi5svWQ9Nk',
'media_content_type': 'spotify://playlist',
'thumbnail': 'https://i.scdn.co/image/ab67706f00000003f7b99051789611a49101c1cf',
'title': 'Top Hits NL',
}),
]),
'children_media_class': <MediaClass.PLAYLIST: 'playlist'>,
'media_class': <MediaClass.DIRECTORY: 'directory'>,
'media_content_id': 'spotify://01j5tx5a0ff6g5v0qjx6hbc94t/featured_playlists',
'media_content_type': 'spotify://featured_playlists',
'not_shown': 0,
'thumbnail': None,
'title': 'Featured Playlists',
})
# ---
# name: test_browsing[new_releases-new_releases]
dict({
'can_expand': True,

View File

@ -112,9 +112,6 @@ async def test_browse_media_playlists(
("current_user_recently_played", "current_user_recently_played"),
("current_user_top_artists", "current_user_top_artists"),
("current_user_top_tracks", "current_user_top_tracks"),
("featured_playlists", "featured_playlists"),
("categories", "categories"),
("category_playlists", "dinner"),
("new_releases", "new_releases"),
("playlist", "spotify:playlist:3cEYpjA9oz9GiPac4AsH4n"),
("album", "spotify:album:3IqzqH6ShrRtie9Yd2ODyG"),