Skip to content

Commit 455c37d

Browse files
committed
refactor(deezer): address final review comments
- Move constants to dedicated constants.py module - Remove hasattr check for raw_episodes (type is known) - Remove internal-workings docstring lines per MA convention
1 parent 98eb844 commit 455c37d

5 files changed

Lines changed: 50 additions & 37 deletions

File tree

music_assistant/providers/deezer/browse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from music_assistant.controllers.cache import use_cache
3131

32-
from .helpers import (
32+
from .constants import (
3333
BROWSE_AUDIOBOOKS,
3434
BROWSE_EXPLORE,
3535
BROWSE_GENRES,
@@ -52,6 +52,8 @@
5252
SMART_TRACKLIST_PREFIX,
5353
TOP_CHARTS_PLAYLIST_ID,
5454
USER_TOP_TRACKS_PLAYLIST_ID,
55+
)
56+
from .helpers import (
5557
create_virtual_playlist,
5658
)
5759
from .parsers import (
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Constants for the Deezer provider."""
2+
3+
# -- Virtual playlist IDs --
4+
5+
FLOW_PLAYLIST_ID = "flow"
6+
FLOW_CONFIG_PREFIX = "flow_config_"
7+
SMART_TRACKLIST_PREFIX = "smart_tracklist_"
8+
RECOMMENDED_TRACKS_PLAYLIST_ID = "recommended_tracks"
9+
TOP_CHARTS_PLAYLIST_ID = "top_charts"
10+
USER_TOP_TRACKS_PLAYLIST_ID = "user_top_tracks"
11+
SHAKER_PREFIX = "shaker_"
12+
SHAKER_CURATED_PREFIX = "shaker_curated_"
13+
PERSONAL_SONGS_PLAYLIST_ID = "personal_songs"
14+
SHAKER_MIX_COVER = "https://cdn-assets.dzcdn.net/shaker/_next/static/media/group_mix.d986951b.svg"
15+
16+
# -- Browse folder names (used as path segments for routing) --
17+
18+
BROWSE_MADE_FOR_YOU = "Made For You"
19+
BROWSE_EXPLORE = "Explore"
20+
BROWSE_RECENTLY_PLAYED = "Recently Played"
21+
BROWSE_SHAKER = "Shaker"
22+
BROWSE_AUDIOBOOKS = "Discover Audiobooks"
23+
BROWSE_MOODS = "Moods"
24+
BROWSE_GENRES = "Genres"
25+
BROWSE_YOUR_TOP_ARTISTS = "Your Top Artists"
26+
BROWSE_YOUR_TOP_ALBUMS = "Your Top Albums"
27+
BROWSE_RECOMMENDED_PLAYLISTS = "Recommended Playlists"
28+
BROWSE_RECOMMENDED_ARTIST_PLAYLISTS = "Recommended Artist Playlists"
29+
BROWSE_PERSONALIZED_PLAYLISTS = "Personalized Playlists"

music_assistant/providers/deezer/helpers.py

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
UniqueList,
1919
)
2020

21+
from .constants import (
22+
FLOW_CONFIG_PREFIX,
23+
FLOW_PLAYLIST_ID,
24+
PERSONAL_SONGS_PLAYLIST_ID,
25+
RECOMMENDED_TRACKS_PLAYLIST_ID,
26+
SHAKER_CURATED_PREFIX,
27+
SHAKER_PREFIX,
28+
SMART_TRACKLIST_PREFIX,
29+
TOP_CHARTS_PLAYLIST_ID,
30+
USER_TOP_TRACKS_PLAYLIST_ID,
31+
)
32+
2133
if TYPE_CHECKING:
2234
from deezer_python_gql import DeezerGQLClient
2335
from deezer_python_gql.generated.get_audiobook import (
@@ -27,34 +39,6 @@
2739

2840
from .provider import DeezerProvider
2941

30-
# -- Virtual playlist IDs --
31-
32-
FLOW_PLAYLIST_ID = "flow"
33-
FLOW_CONFIG_PREFIX = "flow_config_"
34-
SMART_TRACKLIST_PREFIX = "smart_tracklist_"
35-
RECOMMENDED_TRACKS_PLAYLIST_ID = "recommended_tracks"
36-
TOP_CHARTS_PLAYLIST_ID = "top_charts"
37-
USER_TOP_TRACKS_PLAYLIST_ID = "user_top_tracks"
38-
SHAKER_PREFIX = "shaker_"
39-
SHAKER_CURATED_PREFIX = "shaker_curated_"
40-
PERSONAL_SONGS_PLAYLIST_ID = "personal_songs"
41-
SHAKER_MIX_COVER = "https://cdn-assets.dzcdn.net/shaker/_next/static/media/group_mix.d986951b.svg"
42-
43-
# -- Browse folder names (used as path segments for routing) --
44-
45-
BROWSE_MADE_FOR_YOU = "Made For You"
46-
BROWSE_EXPLORE = "Explore"
47-
BROWSE_RECENTLY_PLAYED = "Recently Played"
48-
BROWSE_SHAKER = "Shaker"
49-
BROWSE_AUDIOBOOKS = "Discover Audiobooks"
50-
BROWSE_MOODS = "Moods"
51-
BROWSE_GENRES = "Genres"
52-
BROWSE_YOUR_TOP_ARTISTS = "Your Top Artists"
53-
BROWSE_YOUR_TOP_ALBUMS = "Your Top Albums"
54-
BROWSE_RECOMMENDED_PLAYLISTS = "Recommended Playlists"
55-
BROWSE_RECOMMENDED_ARTIST_PLAYLISTS = "Recommended Artist Playlists"
56-
BROWSE_PERSONALIZED_PLAYLISTS = "Personalized Playlists"
57-
5842

5943
@dataclass(frozen=True)
6044
class VirtualPlaylistMeta:

music_assistant/providers/deezer/media.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,7 @@ async def get_podcast(self, prov_podcast_id: str) -> Podcast:
497497
if result is None:
498498
raise MediaNotFoundError(f"Podcast {prov_podcast_id} not found on Deezer")
499499
podcast = parse_podcast(self.provider, result)
500-
if hasattr(result, "raw_episodes"):
501-
podcast.total_episodes = len(result.raw_episodes)
500+
podcast.total_episodes = len(result.raw_episodes)
502501
return podcast
503502

504503
@use_cache(3600 * 24 * 30, allow_expired_cache=True)

music_assistant/providers/deezer/parsers.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
GetRecentlyPlayedMeRecentlyPlayedEdgesNodePlaylist,
2424
GetRecentlyPlayedMeRecentlyPlayedEdgesNodeSmartTracklist,
2525
)
26+
from deezer_python_gql.generated.get_track import GetTrackTrack
2627
from music_assistant_models.enums import (
2728
AlbumType,
2829
ExternalID,
@@ -49,10 +50,12 @@
4950

5051
from music_assistant.helpers.util import infer_album_type, parse_title_and_version
5152

52-
from .helpers import (
53+
from .constants import (
5354
FLOW_CONFIG_PREFIX,
5455
FLOW_PLAYLIST_ID,
5556
SMART_TRACKLIST_PREFIX,
57+
)
58+
from .helpers import (
5659
create_virtual_playlist,
5760
)
5861

@@ -77,7 +80,6 @@
7780
GetFlowConfigsMeFlowConfigsGenresEdgesNode,
7881
GetFlowConfigsMeFlowConfigsMoodsEdgesNode,
7982
)
80-
from deezer_python_gql.generated.get_track import GetTrackTrack
8183
from deezer_python_gql.generated.search import (
8284
SearchSearchResultsAlbumsEdgesNode,
8385
SearchSearchResultsArtistsEdgesNode,
@@ -262,7 +264,7 @@ def _parse_track_metadata(
262264
if img := _cover_image(provider, track.album.cover):
263265
metadata.add_image(img)
264266
# Lyrics (only present on GetTrackTrack, not on fragment-based models)
265-
if hasattr(track, "lyrics") and track.lyrics is not None:
267+
if isinstance(track, GetTrackTrack) and track.lyrics is not None:
266268
if track.lyrics.text:
267269
metadata.lyrics = track.lyrics.text
268270
if track.lyrics.synchronized_lines:
@@ -550,9 +552,6 @@ def parse_audiobook_from_album(
550552
"""
551553
Create an Audiobook from an AlbumFields result (search context).
552554
553-
Used when an album search result is identified as an audiobook via
554-
check_audiobook_ids. Provides basic metadata from the album fields.
555-
556555
:param provider: The Deezer provider instance.
557556
:param album: A GQL album model (fragment-based or slim search result).
558557
"""

0 commit comments

Comments
 (0)