Skip to content

Commit

Permalink
fix: empty webvtt transcripts
Browse files Browse the repository at this point in the history
For some reason vtt were not using the same rendering logic as all the other formats. Specifically, rendering _all_ entries when _no_ voices are assigned to contrubutors.

issue #1529
  • Loading branch information
eteubert committed Nov 17, 2024
1 parent 07f45a8 commit 97ab01c
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions lib/modules/transcripts/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,28 @@ public function as_webvtt()
$contributors_map[$voice->voice] = Contributor::find_by_id($voice->contributor_id);
}

$transcript = Transcript::get_transcript($this->episode->id);
$transcript = array_map(function ($t) use ($contributors_map) {
if (!$t->voice) {
return null;
}
$pretty_voice = function ($voice) use ($contributors_map) {
$contributor = $contributors_map[$voice];
$voice_title = ($contributor && $contributor->getName()) ? $contributor->getName() : $voice;

$contributor = $contributors_map[$t->voice];
if ($voice_title) {
return "<v {$voice_title}>";
}

if (!$contributor) {
return null;
if ($voice) {
return "<v {$voice}>";
}

$voice_title = ($contributor && $contributor->getName()) ? $contributor->getName() : $t->voice;
$voice = $t->voice ? "<v {$voice_title}>" : '';

return sprintf(
"%s --> %s\n%s%s",
self::format_time($t->start),
self::format_time($t->end),
$voice,
$t->content
);
}, $transcript);
return '';
};

$transcript = array_map(fn ($entry) => sprintf(
"%s --> %s\n%s%s",
$entry['start'],
$entry['end'],
$pretty_voice($entry['voice']),
$entry['text']
), $this->get_data());

$transcript = array_filter($transcript);

Expand Down

0 comments on commit 97ab01c

Please sign in to comment.