Passed
Pull Request — master (#875)
by Pauli
04:17 queued 01:56
created

PodcastChannel   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 56
dl 0
loc 80
rs 10
c 2
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toApi() 0 13 2
A toSubsonicApi() 0 20 3
A toAmpacheApi() 0 21 3
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 getStarred()
48
 * @method void setStarred(string $timestamp)
49
 * @method string getCreated()
50
 * @method void setCreated(string $timestamp)
51
 * @method string getUpdated()
52
 * @method void setUpdated(string $timestamp)
53
 * @method PodcastEpisode[] getEpisodes()
54
 * @method void setEpisodes(PodcastEpisode[] $episodes)
55
 */
56
class PodcastChannel extends Entity {
57
	public $userId;
58
	public $rssUrl;
59
	public $rssHash;
60
	public $contentHash;
61
	public $updateChecked;
62
	public $published;
63
	public $title;
64
	public $linkUrl;
65
	public $language;
66
	public $copyright;
67
	public $author;
68
	public $description;
69
	public $imageUrl;
70
	public $category;
71
	public $starred;
72
	public $created;
73
	public $updated;
74
75
	// not part of the default content, may be injected separately
76
	public $episodes;
77
78
	public function toApi() : array {
79
		$result = [
80
			'id' => $this->getId(),
81
			'title' => $this->getTitle(),
82
			'image' => $this->getImageUrl(),
83
			'hash' => $this->getContentHash()
84
		];
85
86
		if ($this->episodes !== null) {
87
			$result['episodes'] = Util::arrayMapMethod($this->episodes, 'toApi');
88
		}
89
90
		return $result;
91
	}
92
93
	public function toAmpacheApi() : array {
94
		$result = [
95
			'id' => (string)$this->getId(),
96
			'name' => $this->getTitle(),
97
			'description' => $this->getDescription(),
98
			'language' => $this->getLanguage(),
99
			'copyright' => $this->getCopyright(),
100
			'feed_url' => $this->getRssUrl(),
101
			'build_date' => $this->getPublished(), // TODO: not actually the lastBuildDate...; should we format this?
102
			'sync_date' => $this->getUpdateChecked(), // TODO: should we format this?
103
			'public_url' => $this->getLinkUrl(),
104
			'website' => $this->getLinkUrl(),
105
			'art' => $this->getImageUrl(),
106
			'flag' => empty($this->getStarred()) ? 0 : 1,
107
		];
108
109
		if ($this->episodes !== null) {
110
			$result['podcast_episode'] = Util::arrayMapMethod($this->episodes, 'toAmpacheApi');
111
		}
112
113
		return $result;
114
	}
115
116
	public function toSubsonicApi() : array {
117
		$result = [
118
			'id' => 'podcast_channel-' . $this->getId(),
119
			'url' => $this->getRssUrl(),
120
			'title' => $this->getTitle(),
121
			'description' => $this->getDescription(),
122
			'coverArt' => 'podcast_channel-' . $this->getId(),
123
			'originalImageUrl' => $this->getImageUrl(),
124
			'status' => 'completed'
125
		];
126
127
		if (!empty($this->starred)) {
128
			$result['starred'] = Util::formatZuluDateTime($this->starred);
129
		}
130
131
		if ($this->episodes !== null) {
132
			$result['episode'] = Util::arrayMapMethod($this->episodes, 'toSubsonicApi');
133
		}
134
135
		return $result;
136
	}
137
}
138