1 | <?php |
||
7 | class LastfmService extends ApiClient implements ApiConsumerInterface |
||
8 | { |
||
9 | /** |
||
10 | * Specify the response format, since Last.fm only returns XML. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $responseFormat = 'xml'; |
||
15 | |||
16 | /** |
||
17 | * Override the key param, since, again, Lastfm wants to be different. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $keyParam = 'api_key'; |
||
22 | |||
23 | /** |
||
24 | * Determine if our application is using Last.fm. |
||
25 | */ |
||
26 | public function used(): bool |
||
30 | |||
31 | /** |
||
32 | * Determine if Last.fm integration is enabled. |
||
33 | */ |
||
34 | public function enabled(): bool |
||
38 | |||
39 | 5 | /** |
|
40 | * Get information about an artist. |
||
41 | 5 | * |
|
42 | * @param string $name Name of the artist |
||
43 | * |
||
44 | * @return mixed[]|null |
||
45 | */ |
||
46 | public function getArtistInformation(string $name): ?array |
||
77 | |||
78 | /** |
||
79 | * Build a Koel-usable array of artist information using the data from Last.fm. |
||
80 | * |
||
81 | * @param mixed[] $artistData |
||
82 | * |
||
83 | * @return mixed[] |
||
84 | */ |
||
85 | private function buildArtistInformation(array $artistData): array |
||
96 | |||
97 | 1 | /** |
|
98 | 1 | * Get information about an album. |
|
99 | * |
||
100 | * @return mixed[]|null |
||
101 | */ |
||
102 | public function getAlbumInformation(string $albumName, string $artistName): ?array |
||
136 | |||
137 | 1 | /** |
|
138 | * Build a Koel-usable array of album information using the data from Last.fm. |
||
139 | * |
||
140 | * @param mixed[] $albumData |
||
141 | * |
||
142 | * @return mixed[] |
||
143 | */ |
||
144 | private function buildAlbumInformation(array $albumData): array |
||
162 | |||
163 | 1 | /** |
|
164 | 1 | * Get Last.fm's session key for the authenticated user using a token. |
|
165 | 1 | * |
|
166 | * @param string $token The token after successfully connecting to Last.fm |
||
167 | 1 | * |
|
168 | * @link http://www.last.fm/api/webauth#4 |
||
169 | */ |
||
170 | public function getSessionKey(string $token): ?string |
||
185 | 1 | ||
186 | /** |
||
187 | * Scrobble a song. |
||
188 | 1 | * |
|
189 | * @param string $artist The artist name |
||
190 | * @param string $track The track name |
||
191 | * @param string|int $timestamp The UNIX timestamp |
||
192 | * @param string $album The album name |
||
193 | * @param string $sk The session key |
||
194 | */ |
||
195 | public function scrobble(string $artist, string $track, $timestamp, string $album, string $sk): void |
||
211 | |||
212 | /** |
||
213 | * Love or unlove a track on Last.fm. |
||
214 | * |
||
215 | * @param string $track The track name |
||
216 | * @param string $artist The artist's name |
||
217 | * @param string $sk The session key |
||
218 | * @param bool $love Whether to love or unlove. Such cheesy terms... urrgggh |
||
219 | */ |
||
220 | public function toggleLoveTrack(string $track, string $artist, string $sk, ?bool $love = true): void |
||
231 | |||
232 | /** |
||
233 | * Update a track's "now playing" on Last.fm. |
||
234 | * |
||
235 | * @param string $artist Name of the artist |
||
236 | * @param string $track Name of the track |
||
237 | * @param string $album Name of the album |
||
238 | * @param int|float $duration Duration of the track, in seconds |
||
239 | * @param string $sk The session key |
||
240 | */ |
||
241 | public function updateNowPlaying(string $artist, string $track, string $album, $duration, string $sk): void |
||
256 | |||
257 | /** |
||
258 | * Build the parameters to use for _authenticated_ Last.fm API calls. |
||
259 | * Such calls require: |
||
260 | * - The API key (api_key) |
||
261 | * - The API signature (api_sig). |
||
262 | * |
||
263 | * @link http://www.last.fm/api/webauth#5 |
||
264 | * |
||
265 | * @param array $params The array of parameters. |
||
266 | * @param bool $toString Whether to turn the array into a query string |
||
267 | * |
||
268 | * @return array|string |
||
269 | */ |
||
270 | public function buildAuthCallParams(array $params, bool $toString = false) |
||
297 | |||
298 | /** |
||
299 | 2 | * Correctly format a value returned by Last.fm. |
|
300 | 2 | * |
|
301 | 2 | * @param string|array $value |
|
302 | */ |
||
303 | 2 | protected function formatText($value): string |
|
311 | 2 | ||
312 | 2 | public function getKey(): ?string |
|
316 | |||
317 | public function getEndpoint(): ?string |
||
321 | |||
322 | public function getSecret(): ?string |
||
326 | } |
||
327 |
This check looks for function calls that miss required arguments.