Add missing informations
This commit is contained in:
parent
3ddf7bf7a0
commit
11026af80e
@ -19,6 +19,9 @@ use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction;
|
|||||||
* episodeImage: ?string,
|
* episodeImage: ?string,
|
||||||
* episodeDescription: ?string,
|
* episodeDescription: ?string,
|
||||||
* fetchedAtUnix: int,
|
* fetchedAtUnix: int,
|
||||||
|
* pubDate: ?\DateTime,
|
||||||
|
* filesize: ?int,
|
||||||
|
* duration: ?int,
|
||||||
* episodeAction: ?EpisodeActionType
|
* episodeAction: ?EpisodeActionType
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
@ -32,6 +35,9 @@ class EpisodeActionExtraData implements \JsonSerializable
|
|||||||
private ?string $episodeImage,
|
private ?string $episodeImage,
|
||||||
private ?string $episodeDescription,
|
private ?string $episodeDescription,
|
||||||
private int $fetchedAtUnix,
|
private int $fetchedAtUnix,
|
||||||
|
private ?\DateTime $pubDate,
|
||||||
|
private ?int $filesize,
|
||||||
|
private ?int $duration,
|
||||||
private ?EpisodeAction $episodeAction
|
private ?EpisodeAction $episodeAction
|
||||||
) {
|
) {
|
||||||
$this->episodeUrl = $episodeUrl;
|
$this->episodeUrl = $episodeUrl;
|
||||||
@ -41,6 +47,9 @@ class EpisodeActionExtraData implements \JsonSerializable
|
|||||||
$this->episodeImage = $episodeImage;
|
$this->episodeImage = $episodeImage;
|
||||||
$this->episodeDescription = $episodeDescription;
|
$this->episodeDescription = $episodeDescription;
|
||||||
$this->fetchedAtUnix = $fetchedAtUnix;
|
$this->fetchedAtUnix = $fetchedAtUnix;
|
||||||
|
$this->pubDate = $pubDate;
|
||||||
|
$this->filesize = $filesize;
|
||||||
|
$this->duration = $duration;
|
||||||
$this->episodeAction = $episodeAction;
|
$this->episodeAction = $episodeAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +58,21 @@ class EpisodeActionExtraData implements \JsonSerializable
|
|||||||
return $this->episodeUrl ?? '/no episodeUrl/';
|
return $this->episodeUrl ?? '/no episodeUrl/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPubDate(): ?\DateTime
|
||||||
|
{
|
||||||
|
return $this->pubDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFilesize(): ?int
|
||||||
|
{
|
||||||
|
return $this->filesize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDuration(): ?int
|
||||||
|
{
|
||||||
|
return $this->duration;
|
||||||
|
}
|
||||||
|
|
||||||
public function getEpisodeAction(): ?EpisodeAction
|
public function getEpisodeAction(): ?EpisodeAction
|
||||||
{
|
{
|
||||||
return $this->episodeAction;
|
return $this->episodeAction;
|
||||||
@ -73,6 +97,9 @@ class EpisodeActionExtraData implements \JsonSerializable
|
|||||||
'episodeImage' => $this->episodeImage,
|
'episodeImage' => $this->episodeImage,
|
||||||
'episodeDescription' => $this->episodeDescription,
|
'episodeDescription' => $this->episodeDescription,
|
||||||
'fetchedAtUnix' => $this->fetchedAtUnix,
|
'fetchedAtUnix' => $this->fetchedAtUnix,
|
||||||
|
'pubDate' => $this->pubDate,
|
||||||
|
'filesize' => $this->filesize,
|
||||||
|
'duration' => $this->duration,
|
||||||
'episodeAction' => $this->episodeAction ? $this->episodeAction->toArray() : null,
|
'episodeAction' => $this->episodeAction ? $this->episodeAction->toArray() : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,18 @@ class EpisodeActionReader extends GPodderSyncEpisodeActionReader
|
|||||||
$episodeLink = null;
|
$episodeLink = null;
|
||||||
$episodeImage = null;
|
$episodeImage = null;
|
||||||
$episodeDescription = null;
|
$episodeDescription = null;
|
||||||
|
$episodeFilesize = null;
|
||||||
|
$episodeDuration = null;
|
||||||
|
$episodePubDate = null;
|
||||||
|
|
||||||
// Find episode by url and add data for it
|
// Find episode by url and add data for it
|
||||||
/** @var \SimpleXMLElement $item */
|
/** @var \SimpleXMLElement $item */
|
||||||
foreach ($channel->item as $item) {
|
foreach ($channel->item as $item) {
|
||||||
$episodeUrl = (string) $item->enclosure['url'];
|
$episodeUrl = (string) $item->enclosure['url'];
|
||||||
|
|
||||||
|
// Get episode filesize
|
||||||
|
$episodeFilesize = (int) $item->enclosure['length'];
|
||||||
|
|
||||||
// Get episode action
|
// Get episode action
|
||||||
$episodeAction = $this->episodeActionRepository->findByEpisodeUrl($episodeUrl, $this->userService->getUserUID());
|
$episodeAction = $this->episodeActionRepository->findByEpisodeUrl($episodeUrl, $this->userService->getUserUID());
|
||||||
|
|
||||||
@ -46,12 +52,21 @@ class EpisodeActionReader extends GPodderSyncEpisodeActionReader
|
|||||||
$episodeLink = $this->stringOrNull($item->link);
|
$episodeLink = $this->stringOrNull($item->link);
|
||||||
|
|
||||||
// Get episode image
|
// Get episode image
|
||||||
$episodeImageChildren = $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
|
$episodeChildren = $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
|
||||||
if ($episodeImageChildren) {
|
if ($episodeChildren) {
|
||||||
$episodeImageAttributes = (array) $episodeImageChildren->image->attributes();
|
$episodeImageAttributes = (array) $episodeChildren->image->attributes();
|
||||||
$episodeImage = $this->stringOrNull(array_key_exists('href', $episodeImageAttributes) ? (string) $episodeImageAttributes['href'] : '');
|
$episodeImage = $this->stringOrNull(array_key_exists('href', $episodeImageAttributes) ? (string) $episodeImageAttributes['href'] : '');
|
||||||
$iTunesChildren = $item->children('itunes', true);
|
$iTunesChildren = $item->children('itunes', true);
|
||||||
|
|
||||||
|
// Get episode duration
|
||||||
|
if ($iTunesChildren) {
|
||||||
|
$rawDuration = $this->stringOrNull((string) $iTunesChildren->duration);
|
||||||
|
$splitDuration = array_reverse(explode(':', $rawDuration ?? ''));
|
||||||
|
$episodeDuration = (int) $splitDuration[0];
|
||||||
|
$episodeDuration += !empty($splitDuration[1]) ? (int) $splitDuration[1] * 60 : 0;
|
||||||
|
$episodeDuration += !empty($splitDuration[2]) ? (int) $splitDuration[2] * 60 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ($iTunesChildren && !$episodeImage) {
|
if ($iTunesChildren && !$episodeImage) {
|
||||||
$episodeImage = $this->stringOrNull((string) $iTunesChildren->image['href']);
|
$episodeImage = $this->stringOrNull((string) $iTunesChildren->image['href']);
|
||||||
}
|
}
|
||||||
@ -65,9 +80,9 @@ class EpisodeActionReader extends GPodderSyncEpisodeActionReader
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$episodeImage) {
|
if (!$episodeImage) {
|
||||||
$channelImageChildren = $channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
|
$channelChildren = $channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
|
||||||
if ($channelImageChildren) {
|
if ($channelChildren) {
|
||||||
$episodeImageAttributes = (array) $channelImageChildren->image->attributes();
|
$episodeImageAttributes = (array) $channelChildren->image->attributes();
|
||||||
$episodeImage = $this->stringOrNull(array_key_exists('href', $episodeImageAttributes) ? (string) $episodeImageAttributes['href'] : '');
|
$episodeImage = $this->stringOrNull(array_key_exists('href', $episodeImageAttributes) ? (string) $episodeImageAttributes['href'] : '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,6 +107,10 @@ class EpisodeActionReader extends GPodderSyncEpisodeActionReader
|
|||||||
// Open links in new browser window/tab
|
// Open links in new browser window/tab
|
||||||
$episodeDescription = str_replace('<a ', '<a class="description-link" target="_blank" ', $episodeDescription ?? '');
|
$episodeDescription = str_replace('<a ', '<a class="description-link" target="_blank" ', $episodeDescription ?? '');
|
||||||
|
|
||||||
|
// Get episode pubDate
|
||||||
|
$rawPubDate = $this->stringOrNull($item->pubDate);
|
||||||
|
$episodePubDate = $rawPubDate ? new \DateTime($rawPubDate) : null;
|
||||||
|
|
||||||
$episodes[] = new EpisodeActionExtraData(
|
$episodes[] = new EpisodeActionExtraData(
|
||||||
$episodeUrl,
|
$episodeUrl,
|
||||||
$this->stringOrNull($channel->title),
|
$this->stringOrNull($channel->title),
|
||||||
@ -100,6 +119,9 @@ class EpisodeActionReader extends GPodderSyncEpisodeActionReader
|
|||||||
$episodeImage,
|
$episodeImage,
|
||||||
$episodeDescription,
|
$episodeDescription,
|
||||||
$fetchedAtUnix ?? (new \DateTime())->getTimestamp(),
|
$fetchedAtUnix ?? (new \DateTime())->getTimestamp(),
|
||||||
|
$episodePubDate,
|
||||||
|
$episodeFilesize,
|
||||||
|
$episodeDuration,
|
||||||
$episodeAction
|
$episodeAction
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user