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