Skip to content

Commit

Permalink
feat: allow various audio formats
Browse files Browse the repository at this point in the history
- mp3
- m4a
- ogg
- wav
- flac
- aac

see #67
  • Loading branch information
mauricerenck committed Feb 27, 2024
1 parent c2c6eed commit 72b5f16
Show file tree
Hide file tree
Showing 19 changed files with 381 additions and 428 deletions.
7 changes: 6 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
/.github/ export-ignore
/content/ export-ignore
/site/ export-ignore
/src/ export-ignore
/media/ export-ignore
/tests/ export-ignore
/panel-src/ export-ignore

/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.htaccess export-ignore
/.nvmrc export-ignore
/.prettierrc export-ignore
/.releaserc export-ignore
/index.site.php export-ignore
/package.json export-ignore
/package-lock.json export-ignore
/package-lock.json export-ignore
17 changes: 6 additions & 11 deletions app/AudioTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

namespace mauricerenck\Podcaster;

use Couchbase\ViewMetaData;
use getID3;
use Kirby\Data\Yaml;
use Kirby\Exception\Exception;
use Kirby\Filesystem\File;

class AudioTools
{
public function parseAndWriteId3($audioFile, bool $updateEpisodePage): void
{

if ($audioFile->mime() !== 'audio/mpeg') {
if (strpos($audioFile->mime(), 'audio/') !== 0) {
return;
}

$id3Data = $this->getId3Data($audioFile);

$this->writeAudioFileMeta($id3Data, $audioFile);

if ($updateEpisodePage) {
Expand All @@ -43,10 +38,10 @@ public function writeAudioFileMeta($id3Data, $audioFile): void
$title = $this->getId3Tag('title', $id3Data);

$audioFile->update([
'episodeTitle' => $title,
'duration' => $duration,
'guid' => md5(time()),
]);
'episodeTitle' => $title,
'duration' => $duration,
'guid' => md5(time()),
]);
}

public function writeAudioMetaToPage($id3, $audioFile): void
Expand Down Expand Up @@ -101,4 +96,4 @@ public function getChapters($id3)
{
return (isset($id3['id3v2']['chapters'])) ? $id3['id3v2']['chapters'] : null;
}
}
}
8 changes: 5 additions & 3 deletions app/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public function getGuid($episode, $useUuid)

$audio = $this->getAudioFile($episode);

if(is_null($audio)) {
if (is_null($audio)) {
return '';
}

return $audio->guid()->value();
}

Expand All @@ -72,6 +72,7 @@ public function getAudioEnclosures($episode, $audio): array
'download'
) . '/' . $audio->filename(),
'length' => $audio->size(),
'type' => $audio->mime(),
];
}

Expand Down Expand Up @@ -116,7 +117,8 @@ public function getChapters($episode, $returnEmptyFields = false, $milliseconds
return $chapterList;
}

public function getTranscript($episode) {
public function getTranscript($episode)
{
if ($episode->podcasterTranscript()->isEmpty()) {
return [];
}
Expand Down
14 changes: 9 additions & 5 deletions app/FileTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

return [
'vtt' => [
'mime' => 'text/vtt',
'type' => 'document',
'mime' => 'text/vtt',
'type' => 'document',
],
'srt' => [
'mime' => 'application/srt',
'type' => 'document',
'mime' => 'application/srt',
'type' => 'document',
],
];
'ogg' => [
'mime' => 'audio/ogg',
'type' => 'audio',
],
];
26 changes: 16 additions & 10 deletions blueprints/files/podcaster-episode.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
title: Podcaster Audiofile

accept:
extension: mp3
extension:
- mp3
- m4a
- ogg
- wav
- flac
- aac

fields:
episodeTitle:
label: Audio Id3 Title
type: text
width: 1/2
duration:
label: Duration
type: text
disabled: true
width: 1/2
episodeTitle:
label: Audio Id3 Title
type: text
width: 1/2
duration:
label: Duration
type: text
disabled: true
width: 1/2
Loading

0 comments on commit 72b5f16

Please sign in to comment.