-
app/Jobs/ImportYoutubeChannelStreamsJob.php
Open in GitHubuse App\Facades\Youtube; use App\Models\Stream; use App\Services\Youtube\StreamData; class ImportYoutubeChannelStreamsJob { public function __construct(public string $youtubeChannelId, public string $languageCode = 'en') {} public function handle(): void { $streams = Youtube::upcomingStreams($this->youtubeChannelId); $streams->map(function(StreamData $streamData) { Stream::updateOrCreate(['youtube_id' => $streamData->videoId], [ 'youtube_id' => $streamData->videoId, 'title' => $streamData->title, 'description' => $streamData->description, 'channel_title' => $streamData->channelTitle, 'thumbnail_url' => $streamData->thumbnailUrl, 'scheduled_start_time' => $streamData->plannedStart, 'language_code' => $this->languageCode, 'status' => $streamData->status, ]); }); } }
-
app/Console/Commands/ImportChannelStreamsCommand.php
Open in GitHubuse App\Jobs\ImportYoutubeChannelStreamsJob; use App\Models\Channel; use Illuminate\Console\Command; class ImportChannelStreamsCommand extends Command { public function handle(): int { Channel::all()->each(function(Channel $channel) { dispatch(new ImportYoutubeChannelStreamsJob($channel->platform_id, $channel->language_code)); }); } }