Files
einundzwanzig-portal/app/Console/Commands/Feed/ReadAndSyncEinundzwanzigPodcastFeed.php
Benjamin Takats 660c7da394 podcasts added
2022-12-06 18:17:05 +01:00

56 lines
1.9 KiB
PHP

<?php
namespace App\Console\Commands\Feed;
use App\Models\Episode;
use App\Models\Podcast;
use Illuminate\Console\Command;
class ReadAndSyncEinundzwanzigPodcastFeed extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'feed:sync';
/**
* The console command description.
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
* @return int
*/
public function handle()
{
$client = new \PodcastIndex\Client([
'app' => 'Einundzwanzig School',
'key' => config('feeds.services.podcastindex-org.key'),
'secret' => config('feeds.services.podcastindex-org.secret'),
]);
$podcast = $client->podcasts->byFeedUrl('https://einundzwanzig.space/feed.xml')
->json();
$einundzwanzigPodcast = Podcast::query()
->updateOrCreate(['guid' => $podcast->feed->podcastGuid], [
'title' => $podcast->feed->title,
'link' => $podcast->feed->link,
'language_code' => $podcast->feed->language,
'data' => $podcast->feed,
]);
$episodes = $client->episodes->byFeedUrl('https://einundzwanzig.space/feed.xml')
->json();
foreach ($episodes->items as $item) {
Episode::query()
->updateOrCreate(['guid' => $item->guid], [
'podcast_id' => $einundzwanzigPodcast->id,
'data' => $item,
]);
}
return Command::SUCCESS;
}
}