Skip to content

Commit ca79ccd

Browse files
committed
feat: add get_similar_artists query and remove deprecated bio.summary
- Add GetSimilarArtists query using Artist.relatedArtist with ArtistFields fragment - Remove deprecated 'summary' field from ArtistBiography (use 'full' instead) - Add smoke test and fixture for similar artists - Update existing fixtures to remove summary field
1 parent ada2353 commit ca79ccd

10 files changed

Lines changed: 199 additions & 11 deletions

File tree

deezer_python_gql/generated/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@
423423
GetRecommendationsMeRecommendationsPlaylistsEdgesNode,
424424
GetRecommendationsMeRecommendationsPlaylistsPageInfo,
425425
)
426+
from .get_similar_artists import (
427+
GetSimilarArtists,
428+
GetSimilarArtistsArtist,
429+
GetSimilarArtistsArtistRelatedArtist,
430+
GetSimilarArtistsArtistRelatedArtistEdges,
431+
GetSimilarArtistsArtistRelatedArtistEdgesNode,
432+
GetSimilarArtistsArtistRelatedArtistPageInfo,
433+
)
426434
from .get_similar_tracks import (
427435
GetSimilarTracks,
428436
GetSimilarTracksTrack,
@@ -945,6 +953,12 @@
945953
"GetRecommendationsMeRecommendationsPlaylistsEdges",
946954
"GetRecommendationsMeRecommendationsPlaylistsEdgesNode",
947955
"GetRecommendationsMeRecommendationsPlaylistsPageInfo",
956+
"GetSimilarArtists",
957+
"GetSimilarArtistsArtist",
958+
"GetSimilarArtistsArtistRelatedArtist",
959+
"GetSimilarArtistsArtistRelatedArtistEdges",
960+
"GetSimilarArtistsArtistRelatedArtistEdgesNode",
961+
"GetSimilarArtistsArtistRelatedArtistPageInfo",
948962
"GetSimilarTracks",
949963
"GetSimilarTracksTrack",
950964
"GetSimilarTracksTrackRecommendedTracks",

deezer_python_gql/generated/client.py

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
)
9191
from .get_recently_played import GetRecentlyPlayed, GetRecentlyPlayedMe
9292
from .get_recommendations import GetRecommendations, GetRecommendationsMe
93+
from .get_similar_artists import GetSimilarArtists, GetSimilarArtistsArtist
9394
from .get_similar_tracks import GetSimilarTracks, GetSimilarTracksTrack
9495
from .get_smart_tracklist import GetSmartTracklist, GetSmartTracklistSmartTracklist
9596
from .get_track import GetTrack, GetTrackTrack
@@ -755,7 +756,6 @@ async def get_artist(
755756
fansCount
756757
isFavorite
757758
bio {
758-
summary
759759
full
760760
}
761761
}
@@ -1146,7 +1146,6 @@ async def get_charts(
11461146
fansCount
11471147
isFavorite
11481148
bio {
1149-
summary
11501149
full
11511150
}
11521151
}
@@ -1322,7 +1321,6 @@ async def get_favorite_artists(
13221321
fansCount
13231322
isFavorite
13241323
bio {
1325-
summary
13261324
full
13271325
}
13281326
}
@@ -1978,7 +1976,6 @@ async def get_music_together_affinity(
19781976
fansCount
19791977
isFavorite
19801978
bio {
1981-
summary
19821979
full
19831980
}
19841981
}
@@ -2773,7 +2770,6 @@ async def get_recently_played(
27732770
fansCount
27742771
isFavorite
27752772
bio {
2776-
summary
27772773
full
27782774
}
27792775
}
@@ -2910,7 +2906,6 @@ async def get_recommendations(
29102906
fansCount
29112907
isFavorite
29122908
bio {
2913-
summary
29142909
full
29152910
}
29162911
}
@@ -2986,6 +2981,57 @@ async def get_recommendations(
29862981
data = self.get_data(response)
29872982
return GetRecommendations.model_validate(data).me
29882983

2984+
async def get_similar_artists(
2985+
self,
2986+
artist_id: str,
2987+
first: Union[Optional[int], UnsetType] = UNSET,
2988+
**kwargs: Any,
2989+
) -> Optional[GetSimilarArtistsArtist]:
2990+
query = gql("""
2991+
query GetSimilarArtists($artistId: String!, $first: Int = 25) {
2992+
artist(artistId: $artistId) {
2993+
relatedArtist(first: $first) {
2994+
edges {
2995+
node {
2996+
...ArtistFields
2997+
}
2998+
}
2999+
pageInfo {
3000+
...PageInfoFields
3001+
}
3002+
}
3003+
}
3004+
}
3005+
3006+
fragment ArtistFields on Artist {
3007+
id
3008+
name
3009+
picture {
3010+
id
3011+
urls(pictureRequest: {width: 264, height: 264})
3012+
}
3013+
fansCount
3014+
isFavorite
3015+
bio {
3016+
full
3017+
}
3018+
}
3019+
3020+
fragment PageInfoFields on PageInfo {
3021+
hasNextPage
3022+
endCursor
3023+
}
3024+
""")
3025+
variables: dict[str, object] = {"artistId": artist_id, "first": first}
3026+
response = await self.execute(
3027+
query=query,
3028+
operation_name="GetSimilarArtists",
3029+
variables=variables,
3030+
**kwargs,
3031+
)
3032+
data = self.get_data(response)
3033+
return GetSimilarArtists.model_validate(data).artist
3034+
29893035
async def get_similar_tracks(
29903036
self, track_id: str, nb: Union[Optional[int], UnsetType] = UNSET, **kwargs: Any
29913037
) -> Optional[GetSimilarTracksTrack]:
@@ -3357,7 +3403,6 @@ async def get_user_charts(
33573403
fansCount
33583404
isFavorite
33593405
bio {
3360-
summary
33613406
full
33623407
}
33633408
}

deezer_python_gql/generated/fragments.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class ArtistFieldsPicture(BaseModel):
6464

6565

6666
class ArtistFieldsBio(BaseModel):
67-
summary: Optional[str]
6867
full: str
6968

7069

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Generated by ariadne-codegen
2+
# Source: queries
3+
4+
from typing import Optional
5+
6+
from pydantic import Field
7+
8+
from .base_model import BaseModel
9+
from .fragments import ArtistFields, PageInfoFields
10+
11+
12+
class GetSimilarArtists(BaseModel):
13+
artist: Optional["GetSimilarArtistsArtist"]
14+
15+
16+
class GetSimilarArtistsArtist(BaseModel):
17+
related_artist: Optional["GetSimilarArtistsArtistRelatedArtist"] = Field(
18+
alias="relatedArtist"
19+
)
20+
21+
22+
class GetSimilarArtistsArtistRelatedArtist(BaseModel):
23+
edges: list["GetSimilarArtistsArtistRelatedArtistEdges"]
24+
page_info: "GetSimilarArtistsArtistRelatedArtistPageInfo" = Field(alias="pageInfo")
25+
26+
27+
class GetSimilarArtistsArtistRelatedArtistEdges(BaseModel):
28+
node: Optional["GetSimilarArtistsArtistRelatedArtistEdgesNode"]
29+
30+
31+
class GetSimilarArtistsArtistRelatedArtistEdgesNode(ArtistFields):
32+
pass
33+
34+
35+
class GetSimilarArtistsArtistRelatedArtistPageInfo(PageInfoFields):
36+
pass
37+
38+
39+
GetSimilarArtists.model_rebuild()
40+
GetSimilarArtistsArtist.model_rebuild()
41+
GetSimilarArtistsArtistRelatedArtist.model_rebuild()
42+
GetSimilarArtistsArtistRelatedArtistEdges.model_rebuild()

queries/fragments.graphql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ fragment ArtistFields on Artist {
5151
fansCount
5252
isFavorite
5353
bio {
54-
summary
5554
full
5655
}
5756
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Get artists related/similar to a given artist.
2+
3+
query GetSimilarArtists($artistId: String!, $first: Int = 25) {
4+
artist(artistId: $artistId) {
5+
relatedArtist(first: $first) {
6+
edges {
7+
node {
8+
...ArtistFields
9+
}
10+
}
11+
pageInfo {
12+
...PageInfoFields
13+
}
14+
}
15+
}
16+
}

tests/fixtures/get_artist.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
]
1111
},
1212
"bio": {
13-
"summary": "Schoolmates Thomas and Guy-Manuel began their career in 1992 with the indie rock trio Darlin' (named after The Beach Boys song) but were scathingly dismissed by Melody Maker magazine as \"daft punk.\" Turning to house-inspired electronica, they used the put down as a name for their DJ-ing partnership and became a hugely successful and influential dance act. First major single “Da Funk” was accompanied by a Spike Jonze-directed video and more success followed with global dance floor anthem “Around the World,” “One More Time,” and “Harder, Faster, Better, Stronger” - which was sampled by Kanye West for his hit “Stronger.” Albums Homework (1997), Discovery (2001) and Human After All (2005) all made the UK Top 10 establishing a style of simple, Chicago house-inspired grooves exploding into a robotic, rave sound. Disguising their faces with masks, crash helmets and robot heads, the duo cultivated an air of mystique, but they've been sampled by Janet Jackson, appeared in TV commercials, and performed at the 2008 Grammy Awards. In the following years, they appeared alongside Kanye West at the 50th Grammy Awards and then pivoted to film music, composing the entire soundtrack of the sci-fi movie Tron: Legacy (2010), which spawned a collection of remixes under the name Tron: Legacy Reconfigured in 2011. The disco and funk-oriented Random Access Memories, their fourth full-length, arrived in 2013 and soon Daft Punk found themselves reaping the fruits of their labor, winning a Grammy for Best Dance/Electronica Album and Best Pop Duo/Group Performance for the Number 1 hit single “Get Lucky,” featuring Pharrell Williams and Chic’s Nile Rodgers. Despite not releasing any new material of their own, Daft Punk continued to collaborate with some of the biggest stars in pop music, scoring production credits on Kanye West’s Yeezus (2013) and an appearance on The Weeknd’s Starboy (2016). After years of radio silence, the duo announced their breakup in 2021 through their video streaming channel.",
1413
"full": "<p>Schoolmates Thomas and Guy-Manuel began their career in 1992 with the indie rock trio Darlin' (named after The Beach Boys song) but were scathingly dismissed by Melody Maker magazine as \"daft punk.\" Turning to house-inspired electronica, they used the put down as a name for their DJ-ing partnership and became a hugely successful and influential dance act. First major single <em>“Da Funk”</em> was accompanied by a Spike Jonze-directed video and more success followed with global dance floor anthem <em>“Around the World,” “One More Time,”</em> and <em>“Harder, Faster, Better, Stronger”</em> - which was sampled by Kanye West for his hit <em>“Stronger.”</em> Albums <em>Homework</em> (1997), <em>Discovery</em> (2001) and <em>Human After All</em> (2005) all made the UK Top 10 establishing a style of simple, Chicago house-inspired grooves exploding into a robotic, rave sound. Disguising their faces with masks, crash helmets and robot heads, the duo cultivated an air of mystique, but they've been sampled by Janet Jackson, appeared in TV commercials, and performed at the 2008 Grammy Awards. In the following years, they appeared alongside Kanye West at the 50th Grammy Awards and then pivoted to film music, composing the entire soundtrack of the sci-fi movie <em>Tron: Legacy</em> (2010), which spawned a collection of remixes under the name <em>Tron: Legacy Reconfigured</em> in 2011. The disco and funk-oriented <em>Random Access Memories</em>, their fourth full-length, arrived in 2013 and soon Daft Punk found themselves reaping the fruits of their labor, winning a Grammy for Best Dance/Electronica Album and Best Pop Duo/Group Performance for the Number 1 hit single <em>“Get Lucky,”</em> featuring Pharrell Williams and Chic’s Nile Rodgers. Despite not releasing any new material of their own, Daft Punk continued to collaborate with some of the biggest stars in pop music, scoring production credits on Kanye West’s <em>Yeezus</em> (2013) and an appearance on The Weeknd’s <em>Starboy</em> (2016). After years of radio silence, the duo announced their breakup in 2021 through their video streaming channel.</p>"
1514
},
1615
"fansCount": 5114536,

tests/fixtures/get_music_together_affinity.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
"fansCount": 5000000,
6666
"isFavorite": true,
6767
"bio": {
68-
"summary": "French electronic music duo.",
6968
"full": "Daft Punk was a French electronic music duo..."
7069
}
7170
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"data": {
3+
"artist": {
4+
"relatedArtist": {
5+
"edges": [
6+
{
7+
"node": {
8+
"__typename": "Artist",
9+
"id": "101",
10+
"name": "Related Artist One",
11+
"picture": {
12+
"id": "pic_101",
13+
"urls": ["https://cdn.deezer.com/artist/101/264x264.jpg"]
14+
},
15+
"fansCount": 500000,
16+
"isFavorite": false,
17+
"bio": {
18+
"full": "Full biography of Related Artist One"
19+
}
20+
}
21+
},
22+
{
23+
"node": {
24+
"__typename": "Artist",
25+
"id": "102",
26+
"name": "Related Artist Two",
27+
"picture": null,
28+
"fansCount": 250000,
29+
"isFavorite": true,
30+
"bio": null
31+
}
32+
},
33+
{
34+
"node": {
35+
"__typename": "Artist",
36+
"id": "103",
37+
"name": "Related Artist Three",
38+
"picture": {
39+
"id": "pic_103",
40+
"urls": ["https://cdn.deezer.com/artist/103/264x264.jpg"]
41+
},
42+
"fansCount": 100000,
43+
"isFavorite": false,
44+
"bio": {
45+
"full": "Full bio text here"
46+
}
47+
}
48+
}
49+
],
50+
"pageInfo": {
51+
"hasNextPage": false,
52+
"endCursor": "cursor_3"
53+
}
54+
}
55+
}
56+
}
57+
}

tests/test_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
)
7474
from deezer_python_gql.generated.get_recently_played import GetRecentlyPlayed
7575
from deezer_python_gql.generated.get_recommendations import GetRecommendations
76+
from deezer_python_gql.generated.get_similar_artists import GetSimilarArtists
7677
from deezer_python_gql.generated.get_similar_tracks import GetSimilarTracks
7778
from deezer_python_gql.generated.get_smart_tracklist import GetSmartTracklist
7879
from deezer_python_gql.generated.get_track import GetTrack
@@ -226,6 +227,7 @@ def test_client_has_generated_methods() -> None:
226227
"get_artist_mix",
227228
"get_track_mix",
228229
"get_similar_tracks",
230+
"get_similar_artists",
229231
"get_audiobook",
230232
"get_audiobook_chapter",
231233
"get_favorite_audiobooks",
@@ -1290,6 +1292,22 @@ def test_smoke_get_similar_tracks() -> None:
12901292
assert recs[2].contributors.edges[0].node.name == "Third Artist"
12911293

12921294

1295+
def test_smoke_get_similar_artists() -> None:
1296+
"""Verify GetSimilarArtists fixture parses with ArtistFields."""
1297+
data = _load_fixture("get_similar_artists.json")
1298+
artist = GetSimilarArtists.model_validate(data).artist
1299+
assert artist is not None
1300+
assert artist.related_artist is not None
1301+
nodes = [e.node for e in artist.related_artist.edges if e.node is not None]
1302+
assert len(nodes) == 3
1303+
assert nodes[0].id == "101"
1304+
assert nodes[0].name == "Related Artist One"
1305+
assert nodes[0].fans_count == 500000
1306+
assert nodes[1].is_favorite is True
1307+
assert nodes[2].bio is not None
1308+
assert nodes[2].bio.full == "Full bio text here"
1309+
1310+
12931311
def test_smoke_get_favorite_audiobooks() -> None:
12941312
"""Verify GetFavoriteAudiobooks fixture parses with raw audiobook IDs."""
12951313
data = _load_fixture("get_favorite_audiobooks.json")

0 commit comments

Comments
 (0)