vid-queue/app/Commands/TraktWatch.php

35 lines
1 KiB
PHP
Raw Normal View History

2022-10-29 12:33:22 -05:00
<?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;
}
}