diff --git a/app/Controllers/Admin/PodcastImport.php b/app/Controllers/Admin/PodcastImport.php
index 05625077..cfea7a43 100644
--- a/app/Controllers/Admin/PodcastImport.php
+++ b/app/Controllers/Admin/PodcastImport.php
@@ -76,6 +76,7 @@ class PodcastImport extends BaseController
->with('errors', $this->validator->getErrors());
}
try {
+ ini_set('user_agent', 'Castopod/' . CP_VERSION);
$feed = simplexml_load_file(
$this->request->getPost('imported_feed_url')
);
@@ -98,6 +99,9 @@ class PodcastImport extends BaseController
$nsPodcast = $feed->channel[0]->children(
'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md'
);
+ $nsContent = $feed->channel[0]->children(
+ 'http://purl.org/rss/1.0/modules/content/'
+ );
if ((string) $nsPodcast->locked === 'yes') {
return redirect()
@@ -313,6 +317,9 @@ class PodcastImport extends BaseController
$nsPodcast = $item->children(
'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md'
);
+ $nsContent = $item->children(
+ 'http://purl.org/rss/1.0/modules/content/'
+ );
$slug = slugify(
$this->request->getPost('slug_field') === 'title'
@@ -328,13 +335,21 @@ class PodcastImport extends BaseController
}
$slugs[] = $slug;
- $itemDescriptionHtml =
- $this->request->getPost('description_field') === 'summary'
- ? $nsItunes->summary
- : ($this->request->getPost('description_field') ===
- 'subtitle_summary'
- ? $nsItunes->subtitle . '
' . $nsItunes->summary
- : $item->description);
+ $itemDescriptionHtml = null;
+ switch ($this->request->getPost('description_field')) {
+ case 'content':
+ $itemDescriptionHtml = $nsContent->encoded;
+ break;
+ case 'summary':
+ $itemDescriptionHtml = $nsItunes->summary;
+ break;
+ case 'subtitle_summary':
+ $itemDescriptionHtml =
+ $nsItunes->subtitle . '
' . $nsItunes->summary;
+ break;
+ default:
+ $itemDescriptionHtml = $item->description;
+ }
$newEpisode = new \App\Entities\Episode([
'podcast_id' => $newPodcastId,
diff --git a/app/Helpers/media_helper.php b/app/Helpers/media_helper.php
index 77d77478..e512a289 100644
--- a/app/Helpers/media_helper.php
+++ b/app/Helpers/media_helper.php
@@ -6,6 +6,8 @@
* @link https://castopod.org/
*/
+use CodeIgniter\HTTP\ResponseInterface;
+
/**
* Saves a file to the corresponding podcast folder in `public/media`
*
@@ -34,14 +36,50 @@ function save_podcast_media($file, $podcast_name, $media_name)
function download_file($fileUrl)
{
+ $client = \Config\Services::curlrequest();
+ $uri = new \CodeIgniter\HTTP\URI($fileUrl);
+
+ $response = $client->get($uri, [
+ 'headers' => [
+ 'User-Agent' => 'Castopod/' . CP_VERSION,
+ ],
+ ]);
+
+ // redirect to new file location
+ $newFileUrl = $fileUrl;
+ while (
+ in_array(
+ $response->getStatusCode(),
+ [
+ ResponseInterface::HTTP_MOVED_PERMANENTLY,
+ ResponseInterface::HTTP_FOUND,
+ ResponseInterface::HTTP_SEE_OTHER,
+ ResponseInterface::HTTP_NOT_MODIFIED,
+ ResponseInterface::HTTP_TEMPORARY_REDIRECT,
+ ResponseInterface::HTTP_PERMANENT_REDIRECT,
+ ],
+ true
+ )
+ ) {
+ $newFileUrl = (string) trim(
+ $response->getHeader('location')->getValue()
+ );
+ $newLocation = new \CodeIgniter\HTTP\URI($newFileUrl);
+ $response = $client->get($newLocation, [
+ 'headers' => [
+ 'User-Agent' => 'Castopod/' . CP_VERSION,
+ ],
+ 'http_errors' => false,
+ ]);
+ }
$tmpFilename =
time() .
'_' .
bin2hex(random_bytes(10)) .
'.' .
- pathinfo($fileUrl, PATHINFO_EXTENSION);
+ pathinfo($newFileUrl, PATHINFO_EXTENSION);
$tmpFilePath = WRITEPATH . 'uploads/' . $tmpFilename;
- file_put_contents($tmpFilePath, file_get_contents($fileUrl));
+ file_put_contents($tmpFilePath, $response->getBody());
return new \CodeIgniter\Files\File($tmpFilePath);
}
diff --git a/app/Language/en/PodcastImport.php b/app/Language/en/PodcastImport.php
index 5660a280..1ce609d3 100644
--- a/app/Language/en/PodcastImport.php
+++ b/app/Language/en/PodcastImport.php
@@ -25,13 +25,8 @@ return [
'link' => '<link>',
'title' => '<title>',
],
- 'description_field' => [
- 'label' => 'Source field used for episode description / show notes',
- 'description' => '<description>',
- 'summary' => '<itunes:summary>',
- 'subtitle_summary' =>
- '<itunes:subtitle> + <itunes:summary>',
- ],
+ 'description_field' =>
+ 'Source field used for episode description / show notes',
'force_renumber' => 'Force episodes renumbering',
'force_renumber_hint' =>
'Use this if your podcast does not have episode numbers but wish to set them during import.',
diff --git a/app/Language/fr/PodcastImport.php b/app/Language/fr/PodcastImport.php
index 539d0609..371185a1 100644
--- a/app/Language/fr/PodcastImport.php
+++ b/app/Language/fr/PodcastImport.php
@@ -26,13 +26,7 @@ return [
'link' => '<link> (adresse)',
'title' => '<title> (titre)',
],
- 'description_field' => [
- 'label' => 'Champs pour la description des épisodes',
- 'description' => '<description>',
- 'summary' => '<itunes:summary>',
- 'subtitle_summary' =>
- '<itunes:subtitle> + <itunes:summary>',
- ],
+ 'description_field' => 'Champs pour la description des épisodes',
'force_renumber' => 'Forcer la re-numérotation des épisodes',
'force_renumber_hint' =>
'Utilisez ceci si le podcast à importer ne contient pas de numéros d’épisodes mais que vous souhaitez en ajouter pendant l’import.',
diff --git a/app/Views/admin/podcast/import.php b/app/Views/admin/podcast/import.php
index 4d4f1f13..e6f484c8 100644
--- a/app/Views/admin/podcast/import.php
+++ b/app/Views/admin/podcast/import.php
@@ -111,7 +111,7 @@
= form_fieldset_close() ?>
= form_fieldset('', ['class' => 'flex flex-col mb-4']) ?>
-
+
+
= form_fieldset_close() ?>