fix(import): use <image><url> tag when no <itunes:image> is present

This commit is contained in:
Benjamin Bellamy 2020-11-23 20:55:50 +01:00 committed by Yassine Doghri
parent dbba8dc581
commit 20e607afb7

View File

@ -107,9 +107,12 @@ class PodcastImport extends BaseController
$channelDescriptionHtml = $feed->channel[0]->description;
try {
$podcast = new \App\Entities\Podcast([
'name' => $this->request->getPost('name'),
'imported_feed_url' => $this->request->getPost('imported_feed_url'),
'imported_feed_url' => $this->request->getPost(
'imported_feed_url'
),
'new_feed_url' => base_url(
route_to('podcast_feed', $this->request->getPost('name'))
),
@ -118,7 +121,11 @@ class PodcastImport extends BaseController
$channelDescriptionHtml
),
'description_html' => $channelDescriptionHtml,
'image' => download_file($nsItunes->image->attributes()),
'image' => $nsItunes->image && !empty($nsItunes->image->attributes())
? download_file($nsItunes->image->attributes())
: ($feed->channel[0]->image && !empty($feed->channel[0]->image->url)
? download_file($feed->channel[0]->image->url)
: null),
'language_code' => $this->request->getPost('language'),
'category_id' => $this->request->getPost('category'),
'parental_advisory' => empty($nsItunes->explicit)
@ -142,6 +149,19 @@ class PodcastImport extends BaseController
'created_by' => user(),
'updated_by' => user(),
]);
} catch (\ErrorException $ex) {
return redirect()
->back()
->withInput()
->with('errors', [
$ex->getMessage() .
': <a href="' .
$this->request->getPost('imported_feed_url') .
'" rel="noreferrer noopener" target="_blank">' .
$this->request->getPost('imported_feed_url') .
' ⎋</a>',
]);
}
$podcastModel = new PodcastModel();
$db = \Config\Database::connect();
@ -200,10 +220,12 @@ class PodcastImport extends BaseController
'is_visible' => false,
]);
}
if (count($podcastsPlatformsData) > 1) {
$platformModel->createPodcastPlatforms(
$newPodcastId,
$podcastsPlatformsData
);
}
$numberItems = $feed->channel[0]->item->count();
$lastItem =