2024-10-11 08:02:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Srgssr;
|
|
|
|
|
2024-10-11 11:20:39 +02:00
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use App\Srgssr\Api;
|
|
|
|
use App\Srgssr\Video;
|
|
|
|
use App\Srgssr\Subtitles;
|
|
|
|
use App\Models\Episode as EpisodeModel;
|
|
|
|
|
|
|
|
class Episode extends Api
|
2024-10-11 08:02:45 +02:00
|
|
|
{
|
|
|
|
|
2024-10-11 11:20:39 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->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
|
|
|
|
]
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-10-11 08:02:45 +02:00
|
|
|
}
|