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 Pauli Järvinen <[email protected]> |
10
|
|
|
* @copyright Pauli Järvinen 2021 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace OCA\Music\Db; |
14
|
|
|
|
15
|
|
|
use \OCP\AppFramework\Db\Entity; |
16
|
|
|
use \OCA\Music\Utility\Util; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @method string getUserId() |
20
|
|
|
* @method void setUserId(string $userId) |
21
|
|
|
* @method string getRssUrl() |
22
|
|
|
* @method void setRssUrl(string $url) |
23
|
|
|
* @method string getRssHash() |
24
|
|
|
* @method void setRssHash(string $hash) |
25
|
|
|
* @method string getContentHash() |
26
|
|
|
* @method void setContentHash(string $hash) |
27
|
|
|
* @method string getUpdateChecked() |
28
|
|
|
* @method void setUpdateChecked(string $timestamp) |
29
|
|
|
* @method string getPublished() |
30
|
|
|
* @method void setPublished(string $timestamp) |
31
|
|
|
* @method string getTitle() |
32
|
|
|
* @method void setTitle(string $title) |
33
|
|
|
* @method string getLinkUrl() |
34
|
|
|
* @method void setLinkUrl(string $url) |
35
|
|
|
* @method string getLanguage() |
36
|
|
|
* @method void setLanguage(string $language) |
37
|
|
|
* @method string getCopyright() |
38
|
|
|
* @method void setCopyright(string $copyright) |
39
|
|
|
* @method string getAuthor() |
40
|
|
|
* @method void setAuthor(string $author) |
41
|
|
|
* @method string getDescription() |
42
|
|
|
* @method void setDescription(string $description) |
43
|
|
|
* @method string getImageUrl() |
44
|
|
|
* @method void setImageUrl(string $url) |
45
|
|
|
* @method string getCategory() |
46
|
|
|
* @method void setCategory(string $category) |
47
|
|
|
* @method string getCreated() |
48
|
|
|
* @method void setCreated(string $timestamp) |
49
|
|
|
* @method string getUpdated() |
50
|
|
|
* @method void setUpdated(string $timestamp) |
51
|
|
|
* @method PodcastEpisode[] getEpisodes() |
52
|
|
|
* @method void setEpisodes(PodcastEpisode[] $episodes) |
53
|
|
|
*/ |
54
|
|
|
class PodcastChannel extends Entity { |
55
|
|
|
public $userId; |
56
|
|
|
public $rssUrl; |
57
|
|
|
public $rssHash; |
58
|
|
|
public $contentHash; |
59
|
|
|
public $updateChecked; |
60
|
|
|
public $published; |
61
|
|
|
public $title; |
62
|
|
|
public $linkUrl; |
63
|
|
|
public $language; |
64
|
|
|
public $copyright; |
65
|
|
|
public $author; |
66
|
|
|
public $description; |
67
|
|
|
public $imageUrl; |
68
|
|
|
public $category; |
69
|
|
|
public $created; |
70
|
|
|
public $updated; |
71
|
|
|
|
72
|
|
|
// not part of the default content, may be injected separately |
73
|
|
|
public $episodes; |
74
|
|
|
|
75
|
|
|
public function toApi() : array { |
76
|
|
|
$result = [ |
77
|
|
|
'id' => $this->getId(), |
78
|
|
|
'title' => $this->getTitle(), |
79
|
|
|
'image' => $this->getImageUrl(), |
80
|
|
|
'hash' => $this->getContentHash() |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
if ($this->episodes !== null) { |
84
|
|
|
$result['episodes'] = Util::arrayMapMethod($this->episodes, 'toApi'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $result; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function toAmpacheApi() : array { |
91
|
|
|
$result = [ |
92
|
|
|
'id' => (string)$this->getId(), |
93
|
|
|
'name' => $this->getTitle(), |
94
|
|
|
'description' => $this->getDescription(), |
95
|
|
|
'language' => $this->getLanguage(), |
96
|
|
|
'copyright' => $this->getCopyright(), |
97
|
|
|
'feed_url' => $this->getRssUrl(), |
98
|
|
|
'build_date' => $this->getPublished(), // TODO: not actually the lastBuildDate...; should we format this? |
99
|
|
|
'sync_date' => $this->getUpdateChecked(), // TODO: should we format this? |
100
|
|
|
'public_url' => $this->getLinkUrl(), |
101
|
|
|
'website' => $this->getLinkUrl(), |
102
|
|
|
'art' => $this->imageUrl |
103
|
|
|
]; |
104
|
|
|
|
105
|
|
|
if ($this->episodes !== null) { |
106
|
|
|
$result['podcast_episode'] = Util::arrayMapMethod($this->episodes, 'toAmpacheApi'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $result; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function toSubsonicApi() : array { |
113
|
|
|
$result = [ |
114
|
|
|
'id' => 'podcast_channel-' . $this->getId(), |
115
|
|
|
'url' => $this->getRssUrl(), |
116
|
|
|
'title' => $this->getTitle(), |
117
|
|
|
'description' => $this->getDescription(), |
118
|
|
|
'coverArt' => 'podcast_channel-' . $this->getId(), |
119
|
|
|
'originalImageUrl' => $this->getImageUrl(), |
120
|
|
|
'status' => 'completed' |
121
|
|
|
]; |
122
|
|
|
|
123
|
|
|
if ($this->getEpisodes() !== null) { |
|
|
|
|
124
|
|
|
$result['episode'] = Util::arrayMapMethod($this->episodes, 'toSubsonicApi'); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $result; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|