VANA/VANA-php/app/Srgssr/Episode.php

67 lines
1.6 KiB
PHP

<?php
namespace App\Srgssr;
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
{
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
]
);
}
}
}
}