mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-14 03:57:45 +02:00
feat: support VTT transcript file format in addition to SRT
closes #433
This commit is contained in:
parent
d02ac93867
commit
7071b4b6f4
5 changed files with 123 additions and 9 deletions
|
|
@ -76,16 +76,25 @@ class Transcript extends BaseMedia
|
|||
|
||||
private function saveJsonTranscript(): void
|
||||
{
|
||||
$srtContent = file_get_contents($this->file->getRealPath());
|
||||
$transcriptContent = file_get_contents($this->file->getRealPath());
|
||||
|
||||
$transcriptParser = new TranscriptParser();
|
||||
|
||||
if ($srtContent === false) {
|
||||
if ($transcriptContent === false) {
|
||||
throw new Exception('Could not read transcript file at ' . $this->file->getRealPath());
|
||||
}
|
||||
|
||||
$transcriptJson = $transcriptParser->loadString($srtContent)
|
||||
->parseSrt();
|
||||
$transcript_format = $this->file->getExtension();
|
||||
switch ($transcript_format) {
|
||||
case 'vtt':
|
||||
$transcriptJson = $transcriptParser->loadString($transcriptContent)
|
||||
->parseVtt();
|
||||
break;
|
||||
case 'srt':
|
||||
default:
|
||||
$transcriptJson = $transcriptParser->loadString($transcriptContent)
|
||||
->parseSrt();
|
||||
}
|
||||
|
||||
$tempFilePath = WRITEPATH . 'uploads/' . $this->file->getRandomName();
|
||||
file_put_contents($tempFilePath, $transcriptJson);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue