Skip to content

Commit

Permalink
Improve Podcast rss import
Browse files Browse the repository at this point in the history
Some Audio files may have the application/octet-stream' mimetype which wasn't being captured before.
It is possible that PDFs might also have this mime type but it is unlikely to come up (there haven't been any pdf transcript attachments in any test cases yet)
  • Loading branch information
andrew-gardener committed Jun 5, 2024
1 parent 8dc5068 commit b7543a7
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/Command/ImportPodcastCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,25 +574,6 @@ private function processMedia() : void {
$this->em->persist($image);
$this->em->flush();
}
} elseif (str_starts_with($mimetype, 'audio/') && $entity instanceof Episode) {
$audio = $entity->getAudioByChecksum($checksum);
if (null === $audio) {
$audio = new Audio();
$audio->setFile($upload);
$audio->setEntity($entity);
$audio->setDescription('');
$audio->setSourceUrl($url);
$audio->prePersist();

$this->em->persist($audio);
$entity->addAudio($audio);
$entity->updateStatus();
$this->em->flush();
} elseif (null === $audio->getSourceUrl()) {
$audio->setSourceUrl($url);
$this->em->persist($audio);
$this->em->flush();
}
} elseif ('application/pdf' === $mimetype && $entity instanceof Episode) {
$pdf = $entity->getPdfByChecksum($checksum);
if (null === $pdf) {
Expand All @@ -612,6 +593,28 @@ private function processMedia() : void {
$this->em->persist($pdf);
$this->em->flush();
}
// some audio files are application/octet-stream for whatever reason
} elseif ((str_starts_with($mimetype, 'audio/') || 'application/octet-stream' === $mimetype) && $entity instanceof Episode) {
$audio = $entity->getAudioByChecksum($checksum);
if (null === $audio) {
$audio = new Audio();
$audio->setFile($upload);
$audio->setEntity($entity);
$audio->setDescription('');
$audio->setSourceUrl($url);
$audio->prePersist();

$this->em->persist($audio);
$entity->addAudio($audio);
$entity->updateStatus();
$this->em->flush();
} elseif (null === $audio->getSourceUrl()) {
$audio->setSourceUrl($url);
$this->em->persist($audio);
$this->em->flush();
}
} else {
$this->output->writeln("Invalid Mimetype for mimetype: {$mimetype} filename: {$filename}");
}
}
$this->output->writeln("Finished server side processing of {$url}");
Expand Down

0 comments on commit b7543a7

Please sign in to comment.