48 lines
		
	
	
		
			893 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			893 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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
 | 
						|
    {
 | 
						|
        $response = Http::withHeaders($this->headers)->withQueryParameters([
 | 
						|
            'episode' => $urn,
 | 
						|
        ])->get($this->endpoint.'subtitles');
 | 
						|
 | 
						|
 | 
						|
        if($response->ok()){
 | 
						|
            return $response->json()[0]['url'];
 | 
						|
        }
 | 
						|
 | 
						|
        return false;
 | 
						|
 | 
						|
    }
 | 
						|
 | 
						|
    public function getWebVTT(string $urn): ?string
 | 
						|
    {
 | 
						|
        $url = $this->getUrl($urn);
 | 
						|
        $response = Http::get($url);
 | 
						|
 | 
						|
        if($response->successful()){
 | 
						|
            return $response->body();
 | 
						|
        }
 | 
						|
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
}
 |