From: Daniel Karbach Date: Sun, 17 Nov 2024 13:01:57 +0000 (+0100) Subject: add clip command X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=b22c9010876eb9b004c6ea2930e90c1a1a711f48;p=alttp.git add clip command --- diff --git a/app/Console/Commands/TwitchChannelClips.php b/app/Console/Commands/TwitchChannelClips.php new file mode 100644 index 0000000..be9de00 --- /dev/null +++ b/app/Console/Commands/TwitchChannelClips.php @@ -0,0 +1,65 @@ +token = TwitchToken::firstWhere('nick', 'localhorsttv'); + if (!$this->token) { + $this->line('please acquire a token for localhorsttv first'); + return 1; + } + if ($this->token->hasExpired()) { + $this->line('access token has expired, refreshing'); + $this->token->refresh(); + } + $channel = Channel::where('title', '=', $this->argument('name'))->firstOrFail(); + $clips = $this->fetchClips($channel); + foreach ($clips as $clip) { + var_dump($clip); + } + return Command::SUCCESS; + } + + private function fetchClips(Channel $channel) { + $this->line($channel->twitch_chat); + $rsp = $this->token->request() + ->get('/clips', Query::build([ + 'first' => 100, + 'broadcaster_id' => $channel->twitch_id, + ])) + ->throw(); + return $rsp['data']; + } + + private $token; + +}