new podcasts

This commit is contained in:
Benjamin Takats
2023-01-18 17:38:42 +01:00
parent 702057650e
commit 96b1658e69
4 changed files with 73 additions and 64 deletions

View File

@@ -1,60 +0,0 @@
<?php
namespace App\Console\Commands\Feed;
use App\Models\Episode;
use App\Models\Podcast;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
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,
'created_by' => 1,
]);
$episodes = $client->episodes->withParameters(['max' => 1000])
->byFeedId(185230)
->json();
foreach ($episodes->items as $item) {
Episode::query()
->updateOrCreate(['guid' => $item->guid], [
'podcast_id' => $einundzwanzigPodcast->id,
'data' => $item,
'created_by' => 1,
'created_at' => Carbon::parse($item->datePublished),
]);
}
return Command::SUCCESS;
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Console\Commands\Feed;
use App\Models\Episode;
use App\Models\Podcast;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
class ReadAndSyncPodcastFeeds 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'),
]);
$feedIds = [
185230, // Einundzwanzig, der Bitcoin Podcast
4627128, // Nodesignal - Deine Bitcoin-Frequenz
4426306, // Pleb's Taverne
4409506, // Sound Money Bitcoin Podcast
];
foreach ($feedIds as $feedId) {
$podcast = $client->podcasts->byFeedId($feedId)
->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,
'created_by' => 1,
]);
$episodes = $client->episodes->withParameters(['max' => 10000])
->byFeedId($feedId)
->json();
foreach ($episodes->items as $item) {
Episode::query()
->updateOrCreate(['guid' => $item->guid], [
'podcast_id' => $einundzwanzigPodcast->id,
'data' => $item,
'created_by' => 1,
'created_at' => Carbon::parse($item->datePublished),
]);
}
}
return Command::SUCCESS;
}
}

View File

@@ -2,7 +2,7 @@
namespace App\Console; namespace App\Console;
use App\Console\Commands\Feed\ReadAndSyncEinundzwanzigPodcastFeed; use App\Console\Commands\Feed\ReadAndSyncPodcastFeeds;
use App\Console\Commands\OpenBooks\SyncOpenBooks; use App\Console\Commands\OpenBooks\SyncOpenBooks;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -23,7 +23,7 @@ class Kernel extends ConsoleKernel
->daily(); ->daily();
$schedule->call(SyncOpenBooks::class) $schedule->call(SyncOpenBooks::class)
->dailyAt('23:00'); ->dailyAt('23:00');
$schedule->call(ReadAndSyncEinundzwanzigPodcastFeed::class) $schedule->call(ReadAndSyncPodcastFeeds::class)
->dailyAt('23:30'); ->dailyAt('23:30');
} }

View File

@@ -4,7 +4,7 @@ namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents; // use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Console\Commands\Database\CreateTags; use App\Console\Commands\Database\CreateTags;
use App\Console\Commands\Feed\ReadAndSyncEinundzwanzigPodcastFeed; use App\Console\Commands\Feed\ReadAndSyncPodcastFeeds;
use App\Console\Commands\OpenBooks\SyncOpenBooks; use App\Console\Commands\OpenBooks\SyncOpenBooks;
use App\Models\BitcoinEvent; use App\Models\BitcoinEvent;
use App\Models\Category; use App\Models\Category;
@@ -373,7 +373,7 @@ Deshalb werden Sie von mir in diesem Kurs leicht verständlich an das Thema hera
$libraryItem->syncTagsWithType(['Präsentationen'], 'library_item'); $libraryItem->syncTagsWithType(['Präsentationen'], 'library_item');
$nonPublicLibrary->libraryItems() $nonPublicLibrary->libraryItems()
->attach($libraryItem); ->attach($libraryItem);
Artisan::call(ReadAndSyncEinundzwanzigPodcastFeed::class); Artisan::call(ReadAndSyncPodcastFeeds::class);
Artisan::call(SyncOpenBooks::class); Artisan::call(SyncOpenBooks::class);
Meetup::create([ Meetup::create([
'city_id' => 1, 'city_id' => 1,