|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ownCloud - Music app |
|
5
|
|
|
* |
|
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
7
|
|
|
* later. See the COPYING file. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Morris Jobke <[email protected]> |
|
10
|
|
|
* @author Pauli Järvinen <[email protected]> |
|
11
|
|
|
* @copyright Morris Jobke 2013, 2014 |
|
12
|
|
|
* @copyright Pauli Järvinen 2017 - 2025 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace OCA\Music\Db; |
|
16
|
|
|
|
|
17
|
|
|
use OCP\IL10N; |
|
18
|
|
|
use OCP\IURLGenerator; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @method ?string getName() |
|
22
|
|
|
* @method void setName(?string $name) |
|
23
|
|
|
* @method ?int getCoverFileId() |
|
24
|
|
|
* @method void setCoverFileId(?int $coverFileId) |
|
25
|
|
|
* @method ?string getMbid() |
|
26
|
|
|
* @method void setMbid(?string $mbid) |
|
27
|
|
|
* @method string getHash() |
|
28
|
|
|
* @method void setHash(string $hash) |
|
29
|
|
|
* @method ?string getStarred() |
|
30
|
|
|
* @method void setStarred(?string $timestamp) |
|
31
|
|
|
* @method ?int getRating() |
|
32
|
|
|
* @method setRating(?int $rating) |
|
33
|
|
|
*/ |
|
34
|
|
|
class Artist extends Entity { |
|
35
|
|
|
public $name; |
|
36
|
|
|
public $coverFileId; |
|
37
|
|
|
public $mbid; |
|
38
|
|
|
public $hash; |
|
39
|
|
|
public $starred; |
|
40
|
|
|
public $rating; |
|
41
|
|
|
|
|
42
|
|
|
// not part of the standard content, injected separately when needed |
|
43
|
|
|
private ?string $lastfmUrl = null; |
|
44
|
|
|
private ?array $albums = null; |
|
45
|
|
|
private ?array $tracks = null; |
|
46
|
|
|
|
|
47
|
|
|
public function __construct() { |
|
48
|
|
|
$this->addType('coverFileId', 'int'); |
|
49
|
|
|
$this->addType('rating', 'int'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getLastfmUrl() : ?string { |
|
53
|
|
|
return $this->lastfmUrl; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function setLastfmUrl(?string $lastfmUrl) : void { |
|
57
|
|
|
$this->lastfmUrl = $lastfmUrl; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return ?Album[] |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getAlbums() : ?array { |
|
64
|
|
|
return $this->albums; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param Album[] $albums |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setAlbums(array $albums) : void { |
|
71
|
|
|
$this->albums = $albums; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return ?Track[] |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getTracks() : ?array { |
|
78
|
|
|
return $this->tracks; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param Track[] $tracks |
|
83
|
|
|
*/ |
|
84
|
|
|
public function setTracks(array $tracks) : void { |
|
85
|
|
|
$this->tracks = $tracks; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getUri(IURLGenerator $urlGenerator) : string { |
|
89
|
|
|
return $urlGenerator->linkToRoute( |
|
90
|
|
|
'music.shivaApi.artist', |
|
91
|
|
|
['id' => $this->id] |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function getNameString(IL10N $l10n) : string { |
|
96
|
|
|
return $this->getName() ?: self::unknownNameString($l10n); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Return the cover URL to be used in the API |
|
101
|
|
|
*/ |
|
102
|
|
|
public function coverToAPI(IURLGenerator $urlGenerator) : ?string { |
|
103
|
|
|
$coverUrl = null; |
|
104
|
|
|
if ($this->getCoverFileId() > 0) { |
|
105
|
|
|
$coverUrl = $urlGenerator->linkToRoute('music.coverApi.artistCover', |
|
106
|
|
|
['artistId' => $this->getId()]); |
|
107
|
|
|
} |
|
108
|
|
|
return $coverUrl; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param array $albums in the "toCollection" format |
|
113
|
|
|
*/ |
|
114
|
|
|
public function toCollection(IURLGenerator $urlGenerator, IL10N $l10n, array $albums) : array { |
|
115
|
|
|
return [ |
|
116
|
|
|
'id' => $this->getId(), |
|
117
|
|
|
'name' => $this->getNameString($l10n), |
|
118
|
|
|
'albums' => $albums, |
|
119
|
|
|
'cover' => $this->coverToAPI($urlGenerator) |
|
120
|
|
|
]; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function toShivaApi(IURLGenerator $urlGenerator, IL10N $l10n) : array { |
|
124
|
|
|
return [ |
|
125
|
|
|
'id' => $this->getId(), |
|
126
|
|
|
'name' => $this->getNameString($l10n), |
|
127
|
|
|
'image' => $this->coverToAPI($urlGenerator), |
|
128
|
|
|
'slug' => $this->slugify('name'), |
|
129
|
|
|
'uri' => $this->getUri($urlGenerator) |
|
130
|
|
|
]; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public static function unknownNameString(IL10N $l10n) : string { |
|
134
|
|
|
return (string) $l10n->t('Unknown artist'); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|