endpoint = 'https://api.srgssr.ch/videometadata/v2/'; parent::__construct(); } public function latestArenaEpisodes() { $response = Http::withHeaders($this->headers)->withQueryParameters([ 'bu' => 'srf', ])->get($this->endpoint.'latest_episodes/shows/09784065-687b-4b60-bd23-9ed0d2d43cdc'); if($response->successful()){ return $response->json(); } return false; } /** * Retrieve 10 latest episodes and save to db. */ public function saveLatestArenaEpisodes() { $latestEps = $this->latestArenaEpisodes(); if($latestEps){ forEach($latestEps['episodeList'] as $ep){ $videoId = $ep['mediaList'][0]['id']; $video = new Video; $mediaComp = $video->mediaComposition($videoId); $subtitles = new Subtitles; $subs = $subtitles->getWebVTT('urn:srf:episode:tv:'.$ep['id']); $test = EpisodeModel::firstOrCreate( [ 'urn' => $ep['fullLengthUrn'] ], [ 'title' => $ep['title'], 'mediacomposition' => json_encode($mediaComp), 'subtitles' => $subs ] ); } } } }