🚧 Submit export shows to trakt
Still very messy
This commit is contained in:
parent
f33031ed8b
commit
50c49cd0ef
8 changed files with 1615 additions and 68 deletions
26
app/Data/DataPipes/ReadExportFile.php
Normal file
26
app/Data/DataPipes/ReadExportFile.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Data\DataPipes;
|
||||
|
||||
use App\Data\FileData;
|
||||
use Illuminate\Support\Collection;
|
||||
use Spatie\LaravelData\DataPipes\DataPipe;
|
||||
use Spatie\LaravelData\Lazy;
|
||||
use Spatie\LaravelData\Optional;
|
||||
use Spatie\LaravelData\Support\DataClass;
|
||||
use Spatie\LaravelData\Support\DataConfig;
|
||||
use Spatie\LaravelData\Support\DataProperty;
|
||||
|
||||
class ReadExportFile implements DataPipe
|
||||
{
|
||||
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
||||
{
|
||||
if (!$properties->has('path')) {
|
||||
return $properties;
|
||||
}
|
||||
|
||||
$properties['rawData'] = json_decode(file_get_contents($properties->get('path')), true) ?? [];
|
||||
|
||||
return $properties;
|
||||
}
|
||||
}
|
||||
31
app/Data/DataPipes/ReadExportFiles.php
Normal file
31
app/Data/DataPipes/ReadExportFiles.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Data\DataPipes;
|
||||
|
||||
use App\Data\FileData;
|
||||
use Illuminate\Support\Collection;
|
||||
use Spatie\LaravelData\DataPipes\DataPipe;
|
||||
use Spatie\LaravelData\Lazy;
|
||||
use Spatie\LaravelData\Optional;
|
||||
use Spatie\LaravelData\Support\DataClass;
|
||||
use Spatie\LaravelData\Support\DataConfig;
|
||||
use Spatie\LaravelData\Support\DataProperty;
|
||||
|
||||
class ReadExportFiles implements DataPipe
|
||||
{
|
||||
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
||||
{
|
||||
if (!$properties->has('files') || !$properties->get('files')->count()) {
|
||||
return $properties;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
foreach ($properties->get('files') as $file)
|
||||
{
|
||||
$data[] = $file->rawData;
|
||||
}
|
||||
$properties['rawData'] = $data;
|
||||
|
||||
return $properties;
|
||||
}
|
||||
}
|
||||
55
app/Data/DataPipes/StructureData.php
Normal file
55
app/Data/DataPipes/StructureData.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Data\DataPipes;
|
||||
|
||||
use App\Data\FileData;
|
||||
use Illuminate\Support\Collection;
|
||||
use Spatie\LaravelData\DataPipes\DataPipe;
|
||||
use Spatie\LaravelData\Lazy;
|
||||
use Spatie\LaravelData\Optional;
|
||||
use Spatie\LaravelData\Support\DataClass;
|
||||
use Spatie\LaravelData\Support\DataConfig;
|
||||
use Spatie\LaravelData\Support\DataProperty;
|
||||
|
||||
class StructureData implements DataPipe
|
||||
{
|
||||
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
||||
{
|
||||
if (!$properties->has('rawData') || !count($properties->get('rawData'))) {
|
||||
return $properties;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
foreach ($properties->get('rawData') as $watch) {
|
||||
$showTmdb = $watch['showTmdb'];
|
||||
$season = $watch['season'];
|
||||
$episode = $watch['episode'];
|
||||
$watched = $watch['watched'];
|
||||
if (!array_key_exists($showTmdb, $data)) {
|
||||
$data[$showTmdb] = [];
|
||||
$data[$showTmdb]['ids'] = ['tmdb' => $showTmdb];
|
||||
$data[$showTmdb]['seasons'] = [];
|
||||
}
|
||||
|
||||
if (!array_key_exists($season, $data[$showTmdb]['seasons'])) {
|
||||
$data[$showTmdb]['seasons'][$season] = [];
|
||||
$data[$showTmdb]['seasons'][$season]['number'] = $season;
|
||||
$data[$showTmdb]['seasons'][$season]['episodes'] = [];
|
||||
}
|
||||
|
||||
$data[$showTmdb]['seasons'][$season]['episodes'][] = [
|
||||
'number' => $episode,
|
||||
'watched_at' => $watched,
|
||||
];
|
||||
}
|
||||
|
||||
$flat = [];
|
||||
foreach ($data as $show) {
|
||||
$show['seasons'] = array_values($show['seasons']);
|
||||
$flat[] = $show;
|
||||
}
|
||||
$properties['structuredData'] = ['shows' => $flat];
|
||||
|
||||
return $properties;
|
||||
}
|
||||
}
|
||||
24
app/Data/WatchData.php
Normal file
24
app/Data/WatchData.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use App\Exceptions\Quit;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
use Spatie\LaravelData\DataPipeline;
|
||||
|
||||
class WatchData extends Data
|
||||
{
|
||||
#[DataCollectionOf(WatchExport::class)]
|
||||
public DataCollection $files;
|
||||
public array $rawData = [];
|
||||
public array $structuredData = [];
|
||||
|
||||
public static function pipeline(): DataPipeline
|
||||
{
|
||||
return parent::pipeline()
|
||||
->through(DataPipes\ReadExportFiles::class)
|
||||
->through(DataPipes\StructureData::class)
|
||||
;
|
||||
}
|
||||
}
|
||||
17
app/Data/WatchExport.php
Normal file
17
app/Data/WatchExport.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use Spatie\LaravelData\DataPipeline;
|
||||
|
||||
class WatchExport extends FileData
|
||||
{
|
||||
public array $rawData = [];
|
||||
|
||||
public static function pipeline(): DataPipeline
|
||||
{
|
||||
return parent::pipeline()
|
||||
->through(DataPipes\ReadExportFile::class)
|
||||
;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue