Newer
Older

Yassine Doghri
committed
<?php
declare(strict_types=1);
/**
* @copyright 2021 Ad Aures

Yassine Doghri
committed
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace App\Libraries;
use App\Entities\Episode;

Yassine Doghri
committed
use Modules\Fediverse\Core\ObjectType;

Yassine Doghri
committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class PodcastEpisode extends ObjectType
{
protected string $type = 'PodcastEpisode';
protected string $attributedTo;
protected string $comments;
/**
* @var array<mixed>
*/
protected array $description = [];
/**
* @var array<string, string>
*/
protected array $image = [];
/**
* @var array<mixed>
*/
protected array $audio = [];
public function __construct(Episode $episode)
{
// TODO: clean things up with specified spec
$this->id = $episode->link;
$this->description = [
'type' => 'Note',
'mediaType' => 'text/markdown',
'content' => $episode->description_markdown,
'contentMap' => [
$episode->podcast->language_code => $episode->description_html,
],
];
$this->image = [
'type' => 'Image',
'mediaType' => $episode->cover->file_mimetype,

Yassine Doghri
committed
'url' => $episode->cover->feed_url,

Yassine Doghri
committed
];
// add audio file
$this->audio = [
'id' => $episode->audio->file_url,

Yassine Doghri
committed
'type' => 'Audio',

Yassine Doghri
committed
'name' => esc($episode->title),
'size' => $episode->audio->file_size,
'duration' => $episode->audio->duration,

Yassine Doghri
committed
'url' => [
'href' => $episode->audio->file_url,

Yassine Doghri
committed
'type' => 'Link',
'mediaType' => $episode->audio->file_mimetype,

Yassine Doghri
committed
],
];

Yassine Doghri
committed
if ($episode->transcript !== null) {
$this->audio['transcript'] = $episode->transcript->file_url;
}
if ($episode->chapters !== null) {
$this->audio['chapters'] = $episode->chapters->file_url;
}
$this->comments = url_to('episode-comments', $episode->podcast->handle, $episode->slug);

Yassine Doghri
committed
if ($episode->published_at !== null) {
$this->published = $episode->published_at->format(DATE_W3C);
}
if ($episode->podcast->actor !== null) {
$this->attributedTo = $episode->podcast->actor->uri;
if ($episode->podcast->actor->followers_url) {
$this->cc = [$episode->podcast->actor->followers_url];
}
}
}
}