readd sub action
This commit is contained in:
parent
9e9e9e2bbe
commit
ab406786c7
@ -4,10 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace OCA\RePod\Controller;
|
||||
|
||||
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
|
||||
use OCA\RePod\AppInfo\Application;
|
||||
use OCA\RePod\Core\EpisodeAction\EpisodeActionReader;
|
||||
use OCA\RePod\Service\UserService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
@ -19,9 +17,7 @@ class EpisodesController extends Controller
|
||||
public function __construct(
|
||||
IRequest $request,
|
||||
private IClientService $clientService,
|
||||
private EpisodeActionReader $episodeActionReader,
|
||||
private EpisodeActionRepository $episodeActionRepository,
|
||||
private UserService $userService
|
||||
private EpisodeActionReader $episodeActionReader
|
||||
) {
|
||||
parent::__construct(Application::APP_ID, $request);
|
||||
}
|
||||
@ -36,7 +32,7 @@ class EpisodesController extends Controller
|
||||
|
||||
public function action(string $url): JSONResponse
|
||||
{
|
||||
$action = $this->episodeActionRepository->findByEpisodeUrl($url, $this->userService->getUserUID());
|
||||
$action = $this->episodeActionReader->findByEpisodeUrl($url);
|
||||
|
||||
if ($action) {
|
||||
return new JSONResponse($action->toArray());
|
||||
|
@ -22,7 +22,8 @@ use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction;
|
||||
* episodeGuid: string,
|
||||
* episodePubDate: ?\DateTime,
|
||||
* episodeFilesize: ?int,
|
||||
* episodeDuration: ?int
|
||||
* episodeDuration: ?int,
|
||||
* episodeAction: ?EpisodeActionType
|
||||
* }
|
||||
*/
|
||||
class EpisodeActionExtraData implements \JsonSerializable
|
||||
@ -38,7 +39,8 @@ class EpisodeActionExtraData implements \JsonSerializable
|
||||
private string $episodeGuid,
|
||||
private ?\DateTime $episodePubDate,
|
||||
private ?int $episodeFilesize,
|
||||
private ?int $episodeDuration
|
||||
private ?int $episodeDuration,
|
||||
private ?EpisodeAction $episodeAction
|
||||
) {
|
||||
$this->episodeUrl = $episodeUrl;
|
||||
$this->podcastName = $podcastName;
|
||||
@ -51,6 +53,7 @@ class EpisodeActionExtraData implements \JsonSerializable
|
||||
$this->episodePubDate = $episodePubDate;
|
||||
$this->episodeFilesize = $episodeFilesize;
|
||||
$this->episodeDuration = $episodeDuration;
|
||||
$this->episodeAction = $episodeAction;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
@ -78,6 +81,11 @@ class EpisodeActionExtraData implements \JsonSerializable
|
||||
return $this->episodeDuration;
|
||||
}
|
||||
|
||||
public function getEpisodeAction(): ?EpisodeAction
|
||||
{
|
||||
return $this->episodeAction;
|
||||
}
|
||||
|
||||
public function getEpisodeUrl(): ?string
|
||||
{
|
||||
return $this->episodeUrl;
|
||||
@ -101,6 +109,7 @@ class EpisodeActionExtraData implements \JsonSerializable
|
||||
'episodePubDate' => $this->episodePubDate,
|
||||
'episodeFilesize' => $this->episodeFilesize,
|
||||
'episodeDuration' => $this->episodeDuration,
|
||||
'episodeAction' => $this->episodeAction ? $this->episodeAction->toArray() : null,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,23 @@ declare(strict_types=1);
|
||||
|
||||
namespace OCA\RePod\Core\EpisodeAction;
|
||||
|
||||
use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction;
|
||||
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
|
||||
use OCA\RePod\Service\UserService;
|
||||
|
||||
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.
|
||||
*
|
||||
@ -16,14 +31,6 @@ class EpisodeActionReader
|
||||
$episodes = [];
|
||||
$xml = new \SimpleXMLElement($xmlString);
|
||||
$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
|
||||
/** @var \SimpleXMLElement $item */
|
||||
@ -36,6 +43,9 @@ class EpisodeActionReader
|
||||
// Get episode filesize
|
||||
$episodeFilesize = (int) $item->enclosure['length'];
|
||||
|
||||
// Get episode action
|
||||
$episodeAction = $this->episodeActionRepository->findByEpisodeUrl($episodeUrl, $this->userService->getUserUID());
|
||||
|
||||
// Get episode name
|
||||
$episodeName = $this->stringOrNull($item->title);
|
||||
|
||||
@ -43,6 +53,8 @@ class EpisodeActionReader
|
||||
$episodeLink = $this->stringOrNull($item->link);
|
||||
|
||||
// Get episode image
|
||||
$episodeImage = $this->stringOrNull($channel->image->url);
|
||||
|
||||
$episodeChildren = $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
|
||||
if ($episodeChildren) {
|
||||
$episodeImageAttributes = (array) $episodeChildren->image->attributes();
|
||||
@ -62,10 +74,6 @@ class EpisodeActionReader
|
||||
$episodeImage = $this->stringOrNull((string) $iTunesChildren->image['href']);
|
||||
}
|
||||
|
||||
if (!$episodeImage) {
|
||||
$episodeImage = $this->stringOrNull($channel->image->url);
|
||||
}
|
||||
|
||||
if ($iTunesChildren && !$episodeImage) {
|
||||
$episodeImage = $this->stringOrNull((string) $iTunesChildren->image['href']);
|
||||
}
|
||||
@ -85,16 +93,13 @@ class EpisodeActionReader
|
||||
}
|
||||
|
||||
// Get episode description
|
||||
$episodeContentChildren = $item->children('content', true);
|
||||
$episodeDescription = $this->stringOrNull($item->description);
|
||||
|
||||
$episodeContentChildren = $item->children('content', true);
|
||||
if ($episodeContentChildren) {
|
||||
$episodeDescription = $this->stringOrNull($episodeContentChildren->encoded);
|
||||
}
|
||||
|
||||
if (!$episodeDescription) {
|
||||
$episodeDescription = $this->stringOrNull($item->description);
|
||||
}
|
||||
|
||||
// Remove tags
|
||||
$episodeDescription = strip_tags($episodeDescription ?? '');
|
||||
|
||||
@ -113,7 +118,8 @@ class EpisodeActionReader
|
||||
$episodeGuid,
|
||||
$episodePubDate,
|
||||
$episodeFilesize,
|
||||
$episodeDuration
|
||||
$episodeDuration ?? null,
|
||||
$episodeAction
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user