Import films

This commit is contained in:
Dan Jones 2023-10-08 23:30:41 -05:00
commit bc3a42b501

View file

@ -1,7 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Data\DataPipes;
use App\Data\Enums\Type;
use App\Data\FileData;
use Illuminate\Support\Collection;
use Spatie\LaravelData\DataPipes\DataPipe;
@ -20,7 +23,30 @@ class StructureData implements DataPipe
}
$data = [];
$films = [];
foreach ($properties->get('rawData') as $watch) {
switch ($watch['type']) {
case (Type::Episode->value):
$data = $this->getEp($data, $watch);
break;
case (Type::Movie->value):
$films[] = $this->getFilm($watch);
break;
}
}
$flat = [];
foreach ($data as $show) {
$show['seasons'] = array_values($show['seasons']);
$flat[] = $show;
}
$properties['structuredData'] = ['shows' => $flat, 'movies' => $films];
return $properties;
}
protected function getEp(array $data, array $watch): array
{
$showTmdb = $watch['showTmdb'];
$season = $watch['season'];
$episode = $watch['episode'];
@ -41,15 +67,24 @@ class StructureData implements DataPipe
'number' => $episode,
'watched_at' => $watched,
];
return $data;
}
$flat = [];
foreach ($data as $show) {
$show['seasons'] = array_values($show['seasons']);
$flat[] = $show;
}
$properties['structuredData'] = ['shows' => $flat];
protected function getFilm(array $watch): array
{
$filmTmdb = $watch['movieTmdb'];
$filmYear = $watch['movieYear'];
$title = $watch['showTitle'];
$watched = $watch['watched'];
return $properties;
return [
'watched_at' => $watched,
'title' => $title,
'year' => $filmYear,
'ids' => [
'tmdb' => $filmTmdb,
],
];
}
}