✨ Watch episode directly
This commit is contained in:
parent
50c49cd0ef
commit
b5e70aec2e
2 changed files with 41 additions and 1 deletions
34
app/Commands/TraktWatch.php
Normal file
34
app/Commands/TraktWatch.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Commands;
|
||||||
|
|
||||||
|
use App\Data\WatchFile;
|
||||||
|
use App\Data\WatchData;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
class TraktWatch extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'show:watch {file : File to watch}';
|
||||||
|
protected $description = 'Mark a show as watched right now on Trakt';
|
||||||
|
|
||||||
|
public function handle(): int
|
||||||
|
{
|
||||||
|
$file = WatchFile::from($this->argument('file'));
|
||||||
|
|
||||||
|
$watchData = WatchData::from(['rawData' => [$file->toArray()]]);
|
||||||
|
$data = $watchData->structuredData;
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
'trakt-api-version' => 2,
|
||||||
|
'trakt-api-key' => env('TRAKT_APP_ID'),
|
||||||
|
'Authorization' => 'Bearer ' . env('TRAKT_OAUTH_TOKEN'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->info(sprintf('Submitting %s to trakt with headers %s', json_encode($data), json_encode($headers)));
|
||||||
|
$response = Http::withHeaders($headers)->post('https://api.trakt.tv/sync/history', $data);
|
||||||
|
|
||||||
|
$this->line('Response: ' . PHP_EOL . json_encode($response->json(), JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
return static::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,9 @@
|
||||||
namespace App\Data\DataPipes;
|
namespace App\Data\DataPipes;
|
||||||
|
|
||||||
use App\Data\FileData;
|
use App\Data\FileData;
|
||||||
|
use App\Data\WatchExport;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Spatie\LaravelData\DataCollection;
|
||||||
use Spatie\LaravelData\DataPipes\DataPipe;
|
use Spatie\LaravelData\DataPipes\DataPipe;
|
||||||
use Spatie\LaravelData\Lazy;
|
use Spatie\LaravelData\Lazy;
|
||||||
use Spatie\LaravelData\Optional;
|
use Spatie\LaravelData\Optional;
|
||||||
|
|
@ -15,7 +17,11 @@ class ReadExportFiles implements DataPipe
|
||||||
{
|
{
|
||||||
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
||||||
{
|
{
|
||||||
if (!$properties->has('files') || !$properties->get('files')->count()) {
|
if (!$properties->has('files')) {
|
||||||
|
$properties['files'] = new DataCollection(WatchExport::class, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$properties->get('files')->count()) {
|
||||||
return $properties;
|
return $properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue