|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Release; |
|
6
|
|
|
use App\Services\TvProcessing\TvProcessingPipeline; |
|
7
|
|
|
use Blacklight\ColorCLI; |
|
8
|
|
|
use Illuminate\Console\Command; |
|
9
|
|
|
use Illuminate\Support\Facades\Log; |
|
10
|
|
|
|
|
11
|
|
|
class ReprocessTvRelease extends Command |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The name and signature of the console command. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $signature = 'tv:reprocess |
|
19
|
|
|
{guid : The release GUID to reprocess} |
|
20
|
|
|
{--reset : Reset the release video/episode IDs before reprocessing} |
|
21
|
|
|
{--debug : Show detailed debug information}'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The console command description. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $description = 'Reprocess a specific TV release by GUID to rematch it against TV databases'; |
|
29
|
|
|
|
|
30
|
|
|
protected ColorCLI $colorCli; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct(); |
|
35
|
|
|
$this->colorCli = new ColorCLI(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Execute the console command. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function handle(): int |
|
42
|
|
|
{ |
|
43
|
|
|
$guid = $this->argument('guid'); |
|
44
|
|
|
$reset = $this->option('reset'); |
|
45
|
|
|
$debug = $this->option('debug'); |
|
46
|
|
|
|
|
47
|
|
|
// Find the release by GUID |
|
48
|
|
|
$release = Release::query()->where('guid', $guid)->first(); |
|
49
|
|
|
|
|
50
|
|
|
if ($release === null) { |
|
51
|
|
|
$this->error("Release with GUID '{$guid}' not found."); |
|
52
|
|
|
return self::FAILURE; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$this->info('Found release:'); |
|
56
|
|
|
$this->table( |
|
57
|
|
|
['ID', 'GUID', 'Search Name', 'Videos ID', 'Episode ID', 'Category'], |
|
58
|
|
|
[[ |
|
59
|
|
|
$release->id, |
|
60
|
|
|
$release->guid, |
|
|
|
|
|
|
61
|
|
|
mb_substr($release->searchname, 0, 60) . (strlen($release->searchname) > 60 ? '...' : ''), |
|
|
|
|
|
|
62
|
|
|
$release->videos_id, |
|
|
|
|
|
|
63
|
|
|
$release->tv_episodes_id, |
|
|
|
|
|
|
64
|
|
|
$release->categories_id, |
|
|
|
|
|
|
65
|
|
|
]] |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
if ($reset) { |
|
69
|
|
|
$this->warn('Resetting videos_id and tv_episodes_id to 0...'); |
|
70
|
|
|
$release->update([ |
|
71
|
|
|
'videos_id' => 0, |
|
72
|
|
|
'tv_episodes_id' => 0, |
|
73
|
|
|
]); |
|
74
|
|
|
$release->refresh(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$this->info('Processing release through TV pipeline...'); |
|
78
|
|
|
$this->newLine(); |
|
79
|
|
|
|
|
80
|
|
|
try { |
|
81
|
|
|
$pipeline = TvProcessingPipeline::createDefault(echoOutput: true); |
|
82
|
|
|
$result = $pipeline->processRelease($release, $debug); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
$this->newLine(); |
|
85
|
|
|
|
|
86
|
|
|
if ($result['matched']) { |
|
87
|
|
|
$this->colorCli->primary('Successfully matched!'); |
|
88
|
|
|
$this->info('Provider: ' . ($result['provider'] ?? 'Unknown')); |
|
89
|
|
|
$this->info('Video ID: ' . ($result['video_id'] ?? 'N/A')); |
|
90
|
|
|
$this->info('Episode ID: ' . ($result['episode_id'] ?? 'N/A')); |
|
91
|
|
|
} else { |
|
92
|
|
|
$this->colorCli->warning('No match found.'); |
|
93
|
|
|
$this->info('Status: ' . ($result['status'] ?? 'Unknown')); |
|
94
|
|
|
if (isset($result['provider'])) { |
|
95
|
|
|
$this->info('Last provider tried: ' . $result['provider']); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if ($debug && isset($result['debug'])) { |
|
100
|
|
|
$this->newLine(); |
|
101
|
|
|
$this->info('Debug Information:'); |
|
102
|
|
|
$this->line(json_encode($result['debug'], JSON_PRETTY_PRINT)); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
// Show final state of the release |
|
106
|
|
|
$release->refresh(); |
|
107
|
|
|
$this->newLine(); |
|
108
|
|
|
$this->info('Final release state:'); |
|
109
|
|
|
$this->table( |
|
110
|
|
|
['Videos ID', 'Episode ID'], |
|
111
|
|
|
[[$release->videos_id, $release->tv_episodes_id]] |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
|
|
return self::SUCCESS; |
|
115
|
|
|
} catch (\Throwable $e) { |
|
116
|
|
|
Log::error($e->getTraceAsString()); |
|
117
|
|
|
$this->error('Error processing release: ' . $e->getMessage()); |
|
118
|
|
|
if ($debug) { |
|
119
|
|
|
$this->error($e->getTraceAsString()); |
|
120
|
|
|
} |
|
121
|
|
|
return self::FAILURE; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.