1
+ mod payloads;
2
+
1
3
use crate :: scores:: Beatmapset ;
2
4
use anyhow:: { bail, Context , Result } ;
5
+ use payloads:: { SpotifyArtist , SpotifyData , SpotifySearchResult , SpotifyToken , SpotifyTrack } ;
3
6
use reqwest:: blocking:: Client ;
4
- use serde :: Deserialize ;
7
+
5
8
use serde_json:: json;
6
9
use std:: time:: { SystemTime , UNIX_EPOCH } ;
7
10
@@ -45,18 +48,13 @@ impl Spotify {
45
48
"searchTerm" : format!( "{} - {}" , beatmapset. artist_unicode, beatmapset. title_unicode) ,
46
49
"offset" : 0 ,
47
50
"limit" : 20 ,
48
- "numberOfTopResults" : 20 ,
49
- "includeAudiobooks" : false ,
50
- "includePreReleases" : false ,
51
51
} ) ;
52
-
53
52
let extensions = json ! ( {
54
53
"persistedQuery" : {
55
54
"version" : 1 ,
56
55
"sha256Hash" : "220d098228a4eaf216b39e8c147865244959c4cc6fd82d394d88afda0b710929" ,
57
56
} ,
58
57
} ) ;
59
-
60
58
let json = self
61
59
. client
62
60
. get ( "https://api-partner.spotify.com/pathfinder/v1/query" )
@@ -79,80 +77,12 @@ impl Spotify {
79
77
}
80
78
81
79
return Ok ( SpotifyTrack {
82
- artist : artist. profile . name . clone ( ) ,
83
- title : track. item . data . name . clone ( ) ,
84
- album : track. item . data . album_of_track . name . clone ( ) ,
80
+ artist : artist. profile . name ,
81
+ title : track. item . data . name ,
82
+ album : track. item . data . album_of_track . name ,
85
83
} ) ;
86
84
}
87
85
88
86
bail ! ( "Could not find track." ) ;
89
87
}
90
88
}
91
-
92
- #[ derive( Deserialize ) ]
93
- #[ serde( rename_all = "camelCase" ) ]
94
- pub struct SpotifyToken {
95
- pub access_token : String ,
96
- pub access_token_expiration_timestamp_ms : u128 ,
97
- }
98
-
99
- #[ derive( Deserialize ) ]
100
- pub struct SpotifyTrack {
101
- pub artist : String ,
102
- pub title : String ,
103
- pub album : String ,
104
- }
105
-
106
- // Generics
107
- #[ derive( Deserialize ) ]
108
- pub struct SpotifyData < T > {
109
- data : T ,
110
- }
111
-
112
- #[ derive( Deserialize ) ]
113
- pub struct SpotifyItems < T > {
114
- items : Vec < T > ,
115
- }
116
-
117
- #[ derive( Deserialize ) ]
118
- pub struct SpotifyItem < T > {
119
- item : T ,
120
- }
121
-
122
- // Search
123
- #[ derive( Deserialize ) ]
124
- #[ serde( rename_all = "camelCase" ) ]
125
- pub struct SpotifySearchResult {
126
- search_v2 : SpotifySearchV2 ,
127
- }
128
-
129
- #[ derive( Deserialize ) ]
130
- #[ serde( rename_all = "camelCase" ) ]
131
- pub struct SpotifySearchV2 {
132
- tracks_v2 : SpotifyItems < SpotifyItem < SpotifyData < SpotifyTrackItem > > > ,
133
- }
134
-
135
- #[ derive( Deserialize ) ]
136
- #[ serde( rename_all = "camelCase" ) ]
137
- pub struct SpotifyTrackItem {
138
- name : String ,
139
- album_of_track : SpotifyAlbum ,
140
- artists : SpotifyItems < SpotifyArtist > ,
141
- }
142
-
143
- // Album
144
- #[ derive( Deserialize ) ]
145
- pub struct SpotifyAlbum {
146
- name : String ,
147
- }
148
-
149
- // Artist
150
- #[ derive( Deserialize ) ]
151
- pub struct SpotifyArtist {
152
- profile : SpotifyArtistProfile ,
153
- }
154
-
155
- #[ derive( Deserialize ) ]
156
- pub struct SpotifyArtistProfile {
157
- name : String ,
158
- }
0 commit comments