diff --git a/VANA-php/app/Console/Commands/SrgssrSaveLatestArenaEpisodes.php b/VANA-php/app/Console/Commands/SrgssrSaveLatestArenaEpisodes.php new file mode 100644 index 0000000..5e65cb4 --- /dev/null +++ b/VANA-php/app/Console/Commands/SrgssrSaveLatestArenaEpisodes.php @@ -0,0 +1,33 @@ +saveLatestArenaEpisodes(); + $this->info('Aggregation completed!'); + } +} diff --git a/VANA-php/app/Jobs/SrgssrAggregateLatestEpisodes.php b/VANA-php/app/Jobs/SrgssrAggregateLatestEpisodes.php new file mode 100644 index 0000000..b7215bf --- /dev/null +++ b/VANA-php/app/Jobs/SrgssrAggregateLatestEpisodes.php @@ -0,0 +1,29 @@ +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; + + } + + + /** + * Save Episode to db. + */ + public function saveEpisode(string $urn){ + + $response = Http::withHeaders($this->headers)->withQueryParameters([ + 'bu' => 'srf', + ])->get($this->endpoint.'latest_episodes/shows/09784065-687b-4b60-bd23-9ed0d2d43cdc'); + } + + /** + * 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 + ] + + ); + + } + } + + } diff --git a/VANA-php/app/Srgssr/Subtitles.php b/VANA-php/app/Srgssr/Subtitles.php index 6c84953..a8a1289 100644 --- a/VANA-php/app/Srgssr/Subtitles.php +++ b/VANA-php/app/Srgssr/Subtitles.php @@ -22,25 +22,25 @@ class Subtitles extends Api 'episode' => $urn, ])->get($this->endpoint.'subtitles'); + if($response->ok()){ return $response->json()[0]['url']; } - return false; } - public function save(string $urn): void + public function getWebVTT(string $urn): ?string { $url = $this->getUrl($urn); $response = Http::get($url); - Episode::updateOrCreate( - ['urn' => $urn], - ['subtitles' => $response->body()] - ); + if($response->successful()){ + return $response->body(); + } + return false; } diff --git a/VANA-php/app/Srgssr/Video.php b/VANA-php/app/Srgssr/Video.php index 993ab08..b0a87f1 100644 --- a/VANA-php/app/Srgssr/Video.php +++ b/VANA-php/app/Srgssr/Video.php @@ -4,6 +4,7 @@ namespace App\Srgssr; use Illuminate\Support\Facades\Http; use App\Srgssr\Api; +use App\Models\Episode as EpisodeModel; class Video extends Api { @@ -14,23 +15,33 @@ class Video extends Api parent::__construct(); } - public function latestArenaEpisodes() + public function mediaComposition(string $videoId) { - $response = Http::withHeaders($this->headers)->withQueryParameters([ - 'bu' => 'srf', - ])->get($this->endpoint.'latest_episodes/shows/09784065-687b-4b60-bd23-9ed0d2d43cdc'); - - return $response->json(); - - } - - public function mediaComposition(string $videoId){ $response = Http::withHeaders($this->headers)->withQueryParameters([ 'bu' => 'srf', ])->get($this->endpoint.$videoId.'/mediaComposition'); - return $response->json(); + + if($response->successful()){ + return $response->json(); + } + + return false; + + } + + public function savemediaComposition(string $videoId) + { + + $mediaComposition = $this->mediaComposition($videoId); + if($mediaComposition){ + + $episode = new EpisodeModel; + $episode->urn = $mediaComposition['episode']['id']; + + } + } diff --git a/VANA-php/database.sqlite b/VANA-php/database.sqlite index 5e5c8ad..5b0b82e 100644 Binary files a/VANA-php/database.sqlite and b/VANA-php/database.sqlite differ diff --git a/VANA-php/database/migrations/2024_09_28_084341_create_srgssr_settings_table.php b/VANA-php/database/migrations/2024_09_28_084341_create_srgssr_settings_table.php deleted file mode 100644 index c747460..0000000 --- a/VANA-php/database/migrations/2024_09_28_084341_create_srgssr_settings_table.php +++ /dev/null @@ -1,29 +0,0 @@ -id(); - $table->string('api'); - $table->json('settings'); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('srgssr_settings'); - } -}; diff --git a/VANA-php/routes/web.php b/VANA-php/routes/web.php index ed3fb91..e11a1c4 100644 --- a/VANA-php/routes/web.php +++ b/VANA-php/routes/web.php @@ -1,29 +1,14 @@ latestArenaEpisodes(); - dump($setting); - -*/ - - - $video = new Subtitles; - $resp = $video->save('urn:srf:episode:tv:fb946f9c-3176-4eb0-a55a-9019245a7046'); - dump($resp); - -/* - $test = Auth::token("https://api.srgssr.ch/srgssr-play-subtitles/v2/"); - dump($test);*/ - - });