Compare commits
No commits in common. "6d807f59c095728396129e4700d88e156ffaa646" and "bc3a42b5019142594499b45fc8ac34fab9c7c63d" have entirely different histories.
6d807f59c0
...
bc3a42b501
5 changed files with 1261 additions and 1764 deletions
|
|
@ -1,55 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Commands;
|
|
||||||
|
|
||||||
use App\Services\Trakt;
|
|
||||||
|
|
||||||
class TraktLogin extends Command
|
|
||||||
{
|
|
||||||
protected $signature = 'trakt:login';
|
|
||||||
protected $description = 'Login and get new token.';
|
|
||||||
|
|
||||||
public function handle(Trakt $trakt): int
|
|
||||||
{
|
|
||||||
$data = [
|
|
||||||
'client_id' => env('TRAKT_APP_ID'),
|
|
||||||
];
|
|
||||||
|
|
||||||
$resp = $trakt->requestNoAuth()->post('/oauth/device/code', $data);
|
|
||||||
if (!$resp->ok()) {
|
|
||||||
$this->line('Failed to get device code: ' . $resp->status());
|
|
||||||
$this->line($resp->body());
|
|
||||||
return static::FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
$body = $resp->json();
|
|
||||||
$this->line("Visit {$body['verification_url']} and enter the code {$body['user_code']}");
|
|
||||||
if (!$this->confirm('Ready to continue?')) {
|
|
||||||
return static::FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->line("TRAKT_DEVICE_RESP='" . json_encode($body) . "'");
|
|
||||||
|
|
||||||
$data = [
|
|
||||||
'client_id' => env('TRAKT_APP_ID'),
|
|
||||||
'client_secret' => env('TRAKT_APP_SECRET'),
|
|
||||||
'code' => $body['device_code'],
|
|
||||||
];
|
|
||||||
|
|
||||||
$resp = $trakt->requestNoAuth()->post('/oauth/device/token', $data);
|
|
||||||
|
|
||||||
if (!$resp->ok()) {
|
|
||||||
$this->line('Failed to get new token');
|
|
||||||
return static::FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
$body = $resp->json();
|
|
||||||
$this->line("TRAKT_OAUTH_RESP='" . json_encode($body) . "'");
|
|
||||||
$this->line('TRAKT_OAUTH_TOKEN=' . $body['access_token']);
|
|
||||||
|
|
||||||
return static::SUCCESS;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Commands;
|
|
||||||
|
|
||||||
use App\Services\Trakt;
|
|
||||||
|
|
||||||
class TraktRefreshLogin extends Command
|
|
||||||
{
|
|
||||||
protected $signature = 'trakt:refresh';
|
|
||||||
protected $description = 'Refresh access token.';
|
|
||||||
|
|
||||||
public function handle(Trakt $trakt): int
|
|
||||||
{
|
|
||||||
$oauth_resp = json_decode(env('TRAKT_OAUTH_RESP'), true);
|
|
||||||
if (empty($oauth_resp)) {
|
|
||||||
$this->line("Failed to get OAuth response");
|
|
||||||
return static::FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = [
|
|
||||||
'refresh_token' => $oauth_resp['refresh_token'],
|
|
||||||
'client_id' => env('TRAKT_APP_ID'),
|
|
||||||
'client_secret' => env('TRAKT_APP_SECRET'),
|
|
||||||
'redirect_uri' => env('TRAKT_REDIRECT_URI'),
|
|
||||||
'grant_type' => 'refresh_token',
|
|
||||||
];
|
|
||||||
|
|
||||||
$resp = $trakt->request()->post('/oauth/token', $data);
|
|
||||||
|
|
||||||
if (!$resp->ok()) {
|
|
||||||
$this->line('Failed to get new token');
|
|
||||||
return static::FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// $this->line(json_encode($resp->body()));
|
|
||||||
// $body = $json->body();
|
|
||||||
$body = $resp->json();
|
|
||||||
$this->line("TRAKT_OAUTH_RESP='" . json_encode($body) . "'");
|
|
||||||
$this->line('TRAKT_OAUTH_TOKEN=' . $body['access_token']);
|
|
||||||
|
|
||||||
return static::SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -20,21 +20,18 @@ class ParseWatchFile implements DataPipe
|
||||||
{
|
{
|
||||||
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
||||||
{
|
{
|
||||||
$n = now()->format('U');
|
|
||||||
$properties['watched'] = Carbon::now();
|
$properties['watched'] = Carbon::now();
|
||||||
$properties['output'] = match ($properties['type']) {
|
$properties['output'] = match ($properties['type']) {
|
||||||
Type::Movie => sprintf(
|
Type::Movie => sprintf(
|
||||||
'%s-%d-%s.json',
|
'%s-%d.json',
|
||||||
Str::slug($properties['showTitle'] ?? uniqid()),
|
Str::slug($properties['showTitle'] ?? uniqid()),
|
||||||
$properties['movieYear'],
|
$properties['movieYear'],
|
||||||
$n,
|
|
||||||
),
|
),
|
||||||
default => sprintf(
|
default => sprintf(
|
||||||
'%s-%dx%02d-%s.json',
|
'%s-%dx%02d.json',
|
||||||
Str::slug($properties['showTitle'] ?? uniqid()),
|
Str::slug($properties['showTitle'] ?? uniqid()),
|
||||||
$properties['season'],
|
$properties['season'],
|
||||||
$properties['episode'],
|
$properties['episode']
|
||||||
$n,
|
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,7 @@ class Trakt
|
||||||
return Http::withHeaders($this->headers + $headers)->baseUrl('https://api.trakt.tv');
|
return Http::withHeaders($this->headers + $headers)->baseUrl('https://api.trakt.tv');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requestNoAuth(array $headers = []): PendingRequest
|
public function syncHistory(WatchData $data, OutputInterface $output = null): Response
|
||||||
{
|
|
||||||
return Http::withHeaders(['trakt-api-version' => 2] + $headers)->baseUrl('https://api.trakt.tv');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function syncHistory(WatchData $data, ?OutputInterface $output = null): Response
|
|
||||||
{
|
{
|
||||||
$output?->writeln(sprintf('Submitting %s to trakt with headers %s', json_encode($data->structuredData), json_encode($this->headers)));
|
$output?->writeln(sprintf('Submitting %s to trakt with headers %s', json_encode($data->structuredData), json_encode($this->headers)));
|
||||||
|
|
||||||
|
|
|
||||||
2909
composer.lock
generated
2909
composer.lock
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue