|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Component\SubSonic; |
|
6
|
|
|
|
|
7
|
|
|
use DateTimeInterface; |
|
8
|
|
|
use Usox\HyperSonic\FeatureSet\V1161\Contract\AlbumDataProviderInterface; |
|
9
|
|
|
use Uxmp\Core\Orm\Repository\AlbumRepositoryInterface; |
|
10
|
|
|
|
|
11
|
|
|
final readonly class AlbumDataProvider implements AlbumDataProviderInterface |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
2 |
|
public function __construct( |
|
14
|
|
|
private AlbumRepositoryInterface $albumRepository, |
|
15
|
|
|
) { |
|
16
|
2 |
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return null|array{ |
|
20
|
|
|
* id: string, |
|
21
|
|
|
* name: string, |
|
22
|
|
|
* coverArtId: string, |
|
23
|
|
|
* songCount: int, |
|
24
|
|
|
* createDate: DateTimeInterface, |
|
25
|
|
|
* duration: int, |
|
26
|
|
|
* artistName: string, |
|
27
|
|
|
* artistId: string, |
|
28
|
|
|
* songs: array<array{ |
|
29
|
|
|
* id: string, |
|
30
|
|
|
* isDir: bool, |
|
31
|
|
|
* name: string, |
|
32
|
|
|
* albumName: string, |
|
33
|
|
|
* artistName: string, |
|
34
|
|
|
* trackNumber: int, |
|
35
|
|
|
* coverArtId: string, |
|
36
|
|
|
* size: int, |
|
37
|
|
|
* contentType: string, |
|
38
|
|
|
* duration: int, |
|
39
|
|
|
* createDate: DateTimeInterface, |
|
40
|
|
|
* albumId: string, |
|
41
|
|
|
* artistId: string, |
|
42
|
|
|
* playCount: int, |
|
43
|
|
|
* }> |
|
44
|
|
|
* } |
|
45
|
|
|
*/ |
|
46
|
2 |
|
public function getAlbum(string $albumId): ?array |
|
47
|
|
|
{ |
|
48
|
2 |
|
$album = $this->albumRepository->find((int) $albumId); |
|
49
|
|
|
|
|
50
|
2 |
|
if ($album === null) { |
|
51
|
1 |
|
return null; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
$artist = $album->getArtist(); |
|
55
|
1 |
|
$artistName = (string) $artist->getTitle(); |
|
56
|
1 |
|
$artistId = (string) $artist->getId(); |
|
57
|
1 |
|
$albumName = (string) $album->getTitle(); |
|
58
|
1 |
|
$lastModified = $album->getLastModified(); |
|
59
|
|
|
|
|
60
|
1 |
|
$songs = []; |
|
61
|
|
|
|
|
62
|
1 |
|
foreach ($album->getDiscs() as $disc) { |
|
63
|
1 |
|
foreach ($disc->getSongs() as $song) { |
|
64
|
1 |
|
$songs[] = [ |
|
65
|
1 |
|
'id' => (string) $song->getId(), |
|
66
|
1 |
|
'isDir' => false, |
|
67
|
1 |
|
'name' => $song->getTitle(), |
|
68
|
1 |
|
'albumName' => $albumName, |
|
69
|
1 |
|
'artistName' => $artistName, |
|
70
|
1 |
|
'trackNumber' => $song->getTrackNumber(), |
|
71
|
1 |
|
'coverArtId' => sprintf('album-%d', $albumId), |
|
72
|
1 |
|
'size' => $song->getFileSize(), |
|
73
|
1 |
|
'contentType' => (string) $song->getMimeType(), |
|
74
|
1 |
|
'duration' => $song->getLength(), |
|
75
|
1 |
|
'createDate' => $lastModified, // @todo use album create date |
|
76
|
1 |
|
'albumId' => $albumId, |
|
77
|
1 |
|
'artistId' => $artistId, |
|
78
|
1 |
|
'playCount' => 0, // @todo retrieve playcount |
|
79
|
1 |
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
1 |
|
return [ |
|
84
|
1 |
|
'id' => $albumId, |
|
85
|
1 |
|
'name' => $albumName, |
|
86
|
1 |
|
'coverArtId' => sprintf('album-%d', $albumId), |
|
87
|
1 |
|
'songCount' => $album->getSongCount(), |
|
88
|
1 |
|
'createDate' => $lastModified, // @todo insert create date |
|
89
|
1 |
|
'duration' => $album->getLength(), |
|
90
|
1 |
|
'artistName' => $artistName, |
|
91
|
1 |
|
'artistId' => $artistId, |
|
92
|
1 |
|
'songs' => $songs, |
|
93
|
1 |
|
]; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|