|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Component\SubSonic; |
|
6
|
|
|
|
|
7
|
|
|
use DateTimeInterface; |
|
8
|
|
|
use Traversable; |
|
9
|
|
|
use Usox\HyperSonic\FeatureSet\V1161\Contract\AlbumList2DataProviderInterface; |
|
10
|
|
|
use Uxmp\Core\Component\SubSonic\AlbumList\AlbumListRetrieverInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Provides custom ordered album lists for the subsonic api |
|
14
|
|
|
*/ |
|
15
|
|
|
final class AlbumListDataProvider implements AlbumList2DataProviderInterface |
|
16
|
|
|
{ |
|
17
|
1 |
|
public function __construct( |
|
18
|
|
|
private readonly AlbumListRetrieverInterface $albumListRetriever, |
|
19
|
|
|
) { |
|
20
|
1 |
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* If $orderType is `byGenre` or `byYear`, the optional values from $orderParameter MUST be considered |
|
24
|
|
|
* |
|
25
|
|
|
* @param array{ |
|
26
|
|
|
* year?: array{from: int, to: int}, |
|
27
|
|
|
* genre?: string |
|
28
|
|
|
* } $orderParameter |
|
29
|
|
|
* |
|
30
|
|
|
* @return Traversable<array{ |
|
31
|
|
|
* id: string, |
|
32
|
|
|
* name: string, |
|
33
|
|
|
* coverArtId: string, |
|
34
|
|
|
* songCount: int, |
|
35
|
|
|
* createDate: DateTimeInterface, |
|
36
|
|
|
* duration: int, |
|
37
|
|
|
* artistName: string, |
|
38
|
|
|
* artistId: string, |
|
39
|
|
|
* }> |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function getAlbums( |
|
42
|
|
|
string $orderType, |
|
43
|
|
|
int $limit, |
|
44
|
|
|
int $offset, |
|
45
|
|
|
array $orderParameter, |
|
46
|
|
|
?string $musicFolderId |
|
47
|
|
|
): Traversable { |
|
48
|
1 |
|
if ($musicFolderId !== null) { |
|
49
|
1 |
|
$musicFolderId = (int) $musicFolderId; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
foreach ($this->albumListRetriever->retrieve($orderType, $limit, $offset, $orderParameter, $musicFolderId) as $album) { |
|
53
|
1 |
|
$artist = $album->getArtist(); |
|
54
|
1 |
|
$albumId = (string) $album->getId(); |
|
55
|
|
|
|
|
56
|
1 |
|
yield [ |
|
57
|
1 |
|
'id' => $albumId, |
|
58
|
1 |
|
'name' => (string) $album->getTitle(), |
|
59
|
1 |
|
'coverArtId' => sprintf('album-%d', $albumId), |
|
60
|
1 |
|
'songCount' => $album->getSongCount(), |
|
61
|
1 |
|
'createDate' => $album->getLastModified(), // @todo add create date, |
|
62
|
1 |
|
'duration' => $album->getLength(), |
|
63
|
1 |
|
'artistName' => (string) $artist->getTitle(), |
|
64
|
1 |
|
'artistId' => (string) $artist->getId(), |
|
65
|
1 |
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|