Aggregate 10 latest episodes.
parent
2bed0d655f
commit
4f8dc1d9e7
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use App\Srgssr\Episode;
|
||||||
|
|
||||||
|
class SrgssrSaveLatestArenaEpisodes extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'srgssr:save-latest';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Get and save the 10 latest Episodes.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$ep = new Episode;
|
||||||
|
$ep->saveLatestArenaEpisodes();
|
||||||
|
$this->info('Aggregation completed!');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Queue\Queueable;
|
||||||
|
use App\Models\Episode as EpisodeModel;
|
||||||
|
use App\Srgssr\Episode;
|
||||||
|
|
||||||
|
class SrgssrAggregateLatestEpisodes implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ class Episode extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
protected $table = 'episodes';
|
protected $table = 'episodes';
|
||||||
protected $fillable = ['urn', 'subtitles'];
|
protected $fillable = ['urn', 'subtitles', 'title', 'mediacomposition'];
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,78 @@
|
||||||
|
|
||||||
namespace App\Srgssr;
|
namespace App\Srgssr;
|
||||||
|
|
||||||
class Episode
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
]
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,25 +22,25 @@ class Subtitles extends Api
|
||||||
'episode' => $urn,
|
'episode' => $urn,
|
||||||
])->get($this->endpoint.'subtitles');
|
])->get($this->endpoint.'subtitles');
|
||||||
|
|
||||||
|
|
||||||
if($response->ok()){
|
if($response->ok()){
|
||||||
return $response->json()[0]['url'];
|
return $response->json()[0]['url'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save(string $urn): void
|
public function getWebVTT(string $urn): ?string
|
||||||
{
|
{
|
||||||
$url = $this->getUrl($urn);
|
$url = $this->getUrl($urn);
|
||||||
$response = Http::get($url);
|
$response = Http::get($url);
|
||||||
|
|
||||||
Episode::updateOrCreate(
|
if($response->successful()){
|
||||||
['urn' => $urn],
|
return $response->body();
|
||||||
['subtitles' => $response->body()]
|
}
|
||||||
);
|
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Srgssr;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use App\Srgssr\Api;
|
use App\Srgssr\Api;
|
||||||
|
use App\Models\Episode as EpisodeModel;
|
||||||
|
|
||||||
class Video extends Api
|
class Video extends Api
|
||||||
{
|
{
|
||||||
|
@ -14,23 +15,33 @@ class Video extends Api
|
||||||
parent::__construct();
|
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([
|
$response = Http::withHeaders($this->headers)->withQueryParameters([
|
||||||
'bu' => 'srf',
|
'bu' => 'srf',
|
||||||
])->get($this->endpoint.$videoId.'/mediaComposition');
|
])->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'];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -1,29 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::create('srgssr_settings', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
$table->string('api');
|
|
||||||
$table->json('settings');
|
|
||||||
$table->timestamps();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('srgssr_settings');
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,29 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Episode as EpisodeModel;
|
||||||
use App\Subtitles as AppSubtitles;
|
use App\Subtitles as AppSubtitles;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use App\Srgssr\Episode;
|
||||||
use App\Srgssr\Video;
|
use App\Srgssr\Video;
|
||||||
use App\Srgssr\Subtitles;
|
use App\Srgssr\Subtitles;
|
||||||
use App\Srgssr\Auth;
|
use App\Srgssr\Auth;
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
|
|
||||||
/*
|
|
||||||
$vid = new Video;
|
|
||||||
$setting = $vid->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);*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue