Skip to content

Commit

Permalink
fix: transscripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricerenck committed Mar 6, 2024
1 parent 3538b22 commit b5b3402
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 127 deletions.
101 changes: 60 additions & 41 deletions app/Podcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function getPageFromSlug(string $slug)
{
if ($slug == '') {
$page = page(site()->homePageId());
} elseif (!$page = page($slug)) {
} elseif (!($page = page($slug))) {
$page = page(kirby()->router()->call($slug));

if ($page->isHomeOrErrorPage()) {
Expand All @@ -32,10 +32,13 @@ public function getPageFromSlug(string $slug)

public function getPodcastFromId(string $id)
{
$pages = site()->index()->filterBy('template', 'podcasterfeed')->filter(function ($child) use ($id) {
return $child->podcastId()->value() === $id;
})->first();

$pages = site()
->index()
->filterBy('template', 'podcasterfeed')
->filter(function ($child) use ($id) {
return $child->podcastId()->value() === $id;
})
->first();

if (is_null($pages)) {
return false;
Expand Down Expand Up @@ -68,7 +71,8 @@ public function getFeedOfEpisode($episode)

public function getEpisodes($rssFeed)
{
return $rssFeed->podcasterSource()
return $rssFeed
->podcasterSource()
->toPages()
->children()
->listed()
Expand All @@ -77,7 +81,8 @@ public function getEpisodes($rssFeed)
})
->filter(function ($child) {
return $child->hasAudio();
})->sortBy('date', 'desc');
})
->sortBy('date', 'desc');
}

public function getAudioFile($episode)
Expand Down Expand Up @@ -137,7 +142,7 @@ public function getPodloveRoles($episodeSlug)
[
'id' => '1',
'title' => 'Team',
]
],
];
}

Expand All @@ -147,7 +152,7 @@ public function getPodloveRoles($episodeSlug)
[
'id' => '1',
'title' => 'Team',
]
],
];
}

Expand All @@ -156,7 +161,7 @@ public function getPodloveRoles($episodeSlug)
[
'id' => '1',
'title' => 'Team',
]
],
];
}

Expand All @@ -165,7 +170,7 @@ public function getPodloveRoles($episodeSlug)

foreach ($podloveRoles as $role) {
$roles[] = [
'id' => (string)$role->roleId()->value(),
'id' => (string) $role->roleId()->value(),
'title' => $role->roleTitle()->value(),
];
}
Expand All @@ -181,7 +186,7 @@ public function getPodloveGroups($episodeSlug)
[
'id' => '1',
'title' => 'Team',
]
],
];
}

Expand All @@ -192,7 +197,7 @@ public function getPodloveGroups($episodeSlug)
[
'id' => '1',
'title' => 'Team',
]
],
];
}

Expand All @@ -201,7 +206,7 @@ public function getPodloveGroups($episodeSlug)
[
'id' => '1',
'title' => 'Team',
]
],
];
}

Expand All @@ -210,7 +215,7 @@ public function getPodloveGroups($episodeSlug)

foreach ($podloveRoles as $role) {
$roles[] = [
'id' => (string)$role->roleId()->value(),
'id' => (string) $role->roleId()->value(),
'title' => $role->roleTitle()->value(),
];
}
Expand Down Expand Up @@ -263,6 +268,30 @@ public function getPodloveContributors($contributorsField, $contributorRoles, $c
return $contributors;
}

public function getPodloveTranscripts($episode)
{
if ($episode->podcasterTranscript()->isEmpty()) {
return null;
}

$transcripts = $episode->podcasterTranscript()->toStructure();
$podloveTranscripts = [];
foreach ($transcripts as $transcript) {
$podloveTranscript = [
'language' => $transcript->podcasterTranscriptLanguage()->value(),
'url' => $transcript->podcasterTranscriptFile()->toFile()->url(),
];

$podloveTranscripts[] = $podloveTranscript;
}

if (is_null($podloveTranscripts[0])) {
return null;
}

return $podloveTranscripts[0]['url'];
}

public function getPodloveFonts($feed)
{
if ($feed->podcasterPodloveFonts()->isEmpty()) {
Expand Down Expand Up @@ -361,16 +390,20 @@ public function getPodloveEpisodeJson($episode)
$enclosure = $feedUtils->getAudioEnclosures($episode, $audio);
$audioDuration = $feedUtils->getAudioDuration($audio);
$chapters = $feedUtils->getChapters($episode, true, true);
$contributors = $this->getPodloveContributors($episode->podcasterContributors(), $feed->podcasterPodloveRoles(), $feed->podcasterPodloveGroups());

$contributors = $this->getPodloveContributors(
$episode->podcasterContributors(),
$feed->podcasterPodloveRoles(),
$feed->podcasterPodloveGroups()
);
$transcript = $this->getPodloveTranscripts($episode);
return [
'version' => 5,
'show' => [
'title' => $feed->podcasterTitle()->value(),
'subtitle' => $feed->podcasterSubtitle()->value(),
'summary' => $feed->podcasterDescription()->value(),
'poster' => $feed->podcasterCover()->toFile()->url(),
'link' => $feed->podcasterLink()->value()
'link' => $feed->podcasterLink()->value(),
],
'title' => $episode->podcasterTitle()->value(),
'subtitle' => $episode->podcasterSubtitle()->value(),
Expand All @@ -383,36 +416,22 @@ public function getPodloveEpisodeJson($episode)
[
'url' => $enclosure['url'],
'size' => $enclosure['length'],
'title' => "MP3 Audio",
'mimeType' => "audio/mpeg"
]
'title' => 'MP3 Audio',
'mimeType' => 'audio/mpeg',
],
],
'files' => [
[
'url' => $enclosure['url'],
'size' => $enclosure['length'],
'title' => "MP3 Audio",
'mimeType' => "audio/mpeg"
]
'title' => 'MP3 Audio',
'mimeType' => 'audio/mpeg',
],
],
'chapters' => $chapters,
'contributors' => $contributors,
'transcripts' => $transcript,
];
/*
// TODO
"transcripts" => [
[
"start" => "00:00:00.005",
"start_ms" => 5,
"end" => "00:00:09.458",
"end_ms" => 9458,
"speaker" => "3",
"voice" => "Eric",
"text" => "Dann sage ich einfach mal: Hallo und willkommen zu Episode drei des Podlovers Podcasts. Heute das erste Mal mit Gast. Hallo Simon."
],
]
];
*/
}

public function getPodloveConfigJson($episode)
Expand All @@ -428,7 +447,7 @@ public function getPodloveConfigJson($episode)
'base' => 'player/',
'activeTab' => $feed->podcasterPodloveActiveTab()->value(),
'subscribe-button' => [
'feed' => $feed->url()
'feed' => $feed->url(),
],
];

Expand Down Expand Up @@ -461,7 +480,7 @@ public function getAppleMetadata($endpoint)

if (option('mauricerenck.podcaster.useApi', true)) {
$apiCache = kirby()->cache('mauricerenck.podcaster');
$jsonString = $apiCache->get($endpoint);
$jsonString = $apiCache->get($endpoint);

if ($jsonString === null) {
$response = new Remote('https://api.podcaster-plugin.com/' . $endpoint);
Expand Down
8 changes: 4 additions & 4 deletions snippets/frontend/podlove-player.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
namespace mauricerenck\Podcaster;
$podcast = new Podcast();

$episode = (isset($episode)) ? $episode : $page;
$episode = isset($episode) ? $episode : $page;
?>

<div id="podlovePlayerContainer"></div>

<script src="https://cdn.podlove.org/web-player/5.x/embed.js"></script>
<script>
const config = <?= json_encode($podcast->getPodloveConfigJson($episode));?>;
const episode = <?= json_encode($podcast->getPodloveEpisodeJson($episode));?>;
const config = <?= json_encode($podcast->getPodloveConfigJson($episode)) ?>;
const episode = <?= json_encode($podcast->getPodloveEpisodeJson($episode)) ?>;
window
.podlovePlayer("#podlovePlayerContainer", episode, config)

</script>
</script>
Loading

0 comments on commit b5b3402

Please sign in to comment.