readd sub action
All checks were successful
repod / nextcloud (push) Successful in 50s
repod / nodejs (push) Successful in 1m30s

This commit is contained in:
Michel Roux 2023-08-29 12:04:14 +02:00
parent 9e9e9e2bbe
commit ab406786c7
3 changed files with 37 additions and 26 deletions

View File

@ -4,10 +4,8 @@ declare(strict_types=1);
namespace OCA\RePod\Controller; namespace OCA\RePod\Controller;
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
use OCA\RePod\AppInfo\Application; use OCA\RePod\AppInfo\Application;
use OCA\RePod\Core\EpisodeAction\EpisodeActionReader; use OCA\RePod\Core\EpisodeAction\EpisodeActionReader;
use OCA\RePod\Service\UserService;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
@ -19,9 +17,7 @@ class EpisodesController extends Controller
public function __construct( public function __construct(
IRequest $request, IRequest $request,
private IClientService $clientService, private IClientService $clientService,
private EpisodeActionReader $episodeActionReader, private EpisodeActionReader $episodeActionReader
private EpisodeActionRepository $episodeActionRepository,
private UserService $userService
) { ) {
parent::__construct(Application::APP_ID, $request); parent::__construct(Application::APP_ID, $request);
} }
@ -36,7 +32,7 @@ class EpisodesController extends Controller
public function action(string $url): JSONResponse public function action(string $url): JSONResponse
{ {
$action = $this->episodeActionRepository->findByEpisodeUrl($url, $this->userService->getUserUID()); $action = $this->episodeActionReader->findByEpisodeUrl($url);
if ($action) { if ($action) {
return new JSONResponse($action->toArray()); return new JSONResponse($action->toArray());

View File

@ -22,7 +22,8 @@ use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction;
* episodeGuid: string, * episodeGuid: string,
* episodePubDate: ?\DateTime, * episodePubDate: ?\DateTime,
* episodeFilesize: ?int, * episodeFilesize: ?int,
* episodeDuration: ?int * episodeDuration: ?int,
* episodeAction: ?EpisodeActionType
* } * }
*/ */
class EpisodeActionExtraData implements \JsonSerializable class EpisodeActionExtraData implements \JsonSerializable
@ -38,7 +39,8 @@ class EpisodeActionExtraData implements \JsonSerializable
private string $episodeGuid, private string $episodeGuid,
private ?\DateTime $episodePubDate, private ?\DateTime $episodePubDate,
private ?int $episodeFilesize, private ?int $episodeFilesize,
private ?int $episodeDuration private ?int $episodeDuration,
private ?EpisodeAction $episodeAction
) { ) {
$this->episodeUrl = $episodeUrl; $this->episodeUrl = $episodeUrl;
$this->podcastName = $podcastName; $this->podcastName = $podcastName;
@ -51,6 +53,7 @@ class EpisodeActionExtraData implements \JsonSerializable
$this->episodePubDate = $episodePubDate; $this->episodePubDate = $episodePubDate;
$this->episodeFilesize = $episodeFilesize; $this->episodeFilesize = $episodeFilesize;
$this->episodeDuration = $episodeDuration; $this->episodeDuration = $episodeDuration;
$this->episodeAction = $episodeAction;
} }
public function __toString(): string public function __toString(): string
@ -78,6 +81,11 @@ class EpisodeActionExtraData implements \JsonSerializable
return $this->episodeDuration; return $this->episodeDuration;
} }
public function getEpisodeAction(): ?EpisodeAction
{
return $this->episodeAction;
}
public function getEpisodeUrl(): ?string public function getEpisodeUrl(): ?string
{ {
return $this->episodeUrl; return $this->episodeUrl;
@ -101,6 +109,7 @@ class EpisodeActionExtraData implements \JsonSerializable
'episodePubDate' => $this->episodePubDate, 'episodePubDate' => $this->episodePubDate,
'episodeFilesize' => $this->episodeFilesize, 'episodeFilesize' => $this->episodeFilesize,
'episodeDuration' => $this->episodeDuration, 'episodeDuration' => $this->episodeDuration,
'episodeAction' => $this->episodeAction ? $this->episodeAction->toArray() : null,
]; ];
} }

View File

@ -4,8 +4,23 @@ declare(strict_types=1);
namespace OCA\RePod\Core\EpisodeAction; namespace OCA\RePod\Core\EpisodeAction;
use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction;
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
use OCA\RePod\Service\UserService;
class EpisodeActionReader class EpisodeActionReader
{ {
public function __construct(
private EpisodeActionRepository $episodeActionRepository,
private UserService $userService
) {
}
public function findByEpisodeUrl(string $episodeUrl): ?EpisodeAction
{
return $this->episodeActionRepository->findByEpisodeUrl($episodeUrl, $this->userService->getUserUID());
}
/** /**
* https://github.com/pbek/nextcloud-nextpod/blob/main/lib/Core/EpisodeAction/EpisodeActionExtraData.php#L119. * https://github.com/pbek/nextcloud-nextpod/blob/main/lib/Core/EpisodeAction/EpisodeActionExtraData.php#L119.
* *
@ -16,14 +31,6 @@ class EpisodeActionReader
$episodes = []; $episodes = [];
$xml = new \SimpleXMLElement($xmlString); $xml = new \SimpleXMLElement($xmlString);
$channel = $xml->channel; $channel = $xml->channel;
$episodeName = null;
$episodeLink = null;
$episodeImage = null;
$episodeDescription = null;
$episodeGuid = 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 */
@ -36,6 +43,9 @@ class EpisodeActionReader
// Get episode filesize // Get episode filesize
$episodeFilesize = (int) $item->enclosure['length']; $episodeFilesize = (int) $item->enclosure['length'];
// Get episode action
$episodeAction = $this->episodeActionRepository->findByEpisodeUrl($episodeUrl, $this->userService->getUserUID());
// Get episode name // Get episode name
$episodeName = $this->stringOrNull($item->title); $episodeName = $this->stringOrNull($item->title);
@ -43,6 +53,8 @@ class EpisodeActionReader
$episodeLink = $this->stringOrNull($item->link); $episodeLink = $this->stringOrNull($item->link);
// Get episode image // Get episode image
$episodeImage = $this->stringOrNull($channel->image->url);
$episodeChildren = $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd'); $episodeChildren = $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
if ($episodeChildren) { if ($episodeChildren) {
$episodeImageAttributes = (array) $episodeChildren->image->attributes(); $episodeImageAttributes = (array) $episodeChildren->image->attributes();
@ -62,10 +74,6 @@ class EpisodeActionReader
$episodeImage = $this->stringOrNull((string) $iTunesChildren->image['href']); $episodeImage = $this->stringOrNull((string) $iTunesChildren->image['href']);
} }
if (!$episodeImage) {
$episodeImage = $this->stringOrNull($channel->image->url);
}
if ($iTunesChildren && !$episodeImage) { if ($iTunesChildren && !$episodeImage) {
$episodeImage = $this->stringOrNull((string) $iTunesChildren->image['href']); $episodeImage = $this->stringOrNull((string) $iTunesChildren->image['href']);
} }
@ -85,16 +93,13 @@ class EpisodeActionReader
} }
// Get episode description // Get episode description
$episodeContentChildren = $item->children('content', true); $episodeDescription = $this->stringOrNull($item->description);
$episodeContentChildren = $item->children('content', true);
if ($episodeContentChildren) { if ($episodeContentChildren) {
$episodeDescription = $this->stringOrNull($episodeContentChildren->encoded); $episodeDescription = $this->stringOrNull($episodeContentChildren->encoded);
} }
if (!$episodeDescription) {
$episodeDescription = $this->stringOrNull($item->description);
}
// Remove tags // Remove tags
$episodeDescription = strip_tags($episodeDescription ?? ''); $episodeDescription = strip_tags($episodeDescription ?? '');
@ -113,7 +118,8 @@ class EpisodeActionReader
$episodeGuid, $episodeGuid,
$episodePubDate, $episodePubDate,
$episodeFilesize, $episodeFilesize,
$episodeDuration $episodeDuration ?? null,
$episodeAction
); );
} }