2024-10-11 08:02:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Srgssr;
|
|
|
|
|
|
|
|
use HttpRequest;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use App\Srgssr\Api;
|
|
|
|
use App\Models\Episode;
|
|
|
|
|
|
|
|
class Subtitles extends Api
|
|
|
|
{
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->endpoint = 'https://api.srgssr.ch/srgssr-play-subtitles/v2/';
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUrl(string $urn): string
|
|
|
|
{
|
2025-01-16 22:18:12 +01:00
|
|
|
|
2024-10-11 08:02:45 +02:00
|
|
|
$response = Http::withHeaders($this->headers)->withQueryParameters([
|
|
|
|
'episode' => $urn,
|
|
|
|
])->get($this->endpoint.'subtitles');
|
|
|
|
|
2025-01-16 22:18:12 +01:00
|
|
|
if($response->ok() && !empty($response[0]['url'])){
|
|
|
|
return $response[0]['url'];
|
2024-10-11 08:02:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-10-11 11:20:39 +02:00
|
|
|
public function getWebVTT(string $urn): ?string
|
2024-10-11 08:02:45 +02:00
|
|
|
{
|
|
|
|
$url = $this->getUrl($urn);
|
2025-01-16 22:18:12 +01:00
|
|
|
$response = null;
|
|
|
|
|
|
|
|
if($url){
|
|
|
|
$response = Http::get($url);
|
|
|
|
} else {
|
|
|
|
$altUrn = explode(":", $urn)[4];
|
|
|
|
$response = Http::get("https://subtitles.eai-general.aws.srf.ch/srf/{$altUrn}/episode/de/vod/vod.vtt");
|
|
|
|
}
|
2024-10-11 08:02:45 +02:00
|
|
|
|
2025-01-16 22:18:12 +01:00
|
|
|
if($response && $response->successful()){
|
2024-10-11 11:20:39 +02:00
|
|
|
return $response->body();
|
|
|
|
}
|
2024-10-11 08:02:45 +02:00
|
|
|
|
2024-10-11 11:20:39 +02:00
|
|
|
return false;
|
2024-10-11 08:02:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|