|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Settings; |
|
6
|
|
|
use Blacklight\Nfo; |
|
7
|
|
|
use Blacklight\NNTP; |
|
8
|
|
|
use Blacklight\processing\post\ProcessAdditional; |
|
9
|
|
|
use Blacklight\processing\PostProcess; |
|
10
|
|
|
use Illuminate\Console\Command; |
|
11
|
|
|
use Illuminate\Support\Facades\Log; |
|
12
|
|
|
|
|
13
|
|
|
class PostProcessGuid extends Command |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* The name and signature of the console command. |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $signature = 'postprocess:guid |
|
21
|
|
|
{type : Type: additional, nfo, movie, or tv} |
|
22
|
|
|
{guid : First character of release guid (a-f, 0-9)} |
|
23
|
|
|
{renamed? : For movie/tv: process renamed only (optional)}'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The console command description. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $description = 'Post process releases by GUID character'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Execute the console command. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function handle(): int |
|
36
|
|
|
{ |
|
37
|
|
|
$type = $this->argument('type'); |
|
38
|
|
|
$guid = $this->argument('guid'); |
|
39
|
|
|
$renamed = $this->argument('renamed') ?? ''; |
|
40
|
|
|
|
|
41
|
|
|
if (! $this->isValidChar($guid)) { |
|
42
|
|
|
$this->error('GUID character must be a-f or 0-9.'); |
|
43
|
|
|
|
|
44
|
|
|
return self::FAILURE; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
try { |
|
48
|
|
|
switch ($type) { |
|
49
|
|
|
case 'additional': |
|
50
|
|
|
$nntp = $this->getNntp(); |
|
51
|
|
|
(new ProcessAdditional(['Echo' => true, 'NNTP' => $nntp]))->start('', $guid); |
|
|
|
|
|
|
52
|
|
|
break; |
|
53
|
|
|
|
|
54
|
|
|
case 'nfo': |
|
55
|
|
|
$nntp = $this->getNntp(); |
|
56
|
|
|
(new Nfo)->processNfoFiles( |
|
57
|
|
|
$nntp, |
|
58
|
|
|
'', |
|
59
|
|
|
$guid, |
|
60
|
|
|
(int) Settings::settingValue('lookupimdb'), |
|
61
|
|
|
(int) Settings::settingValue('lookuptv') |
|
62
|
|
|
); |
|
63
|
|
|
break; |
|
64
|
|
|
|
|
65
|
|
|
case 'movie': |
|
66
|
|
|
(new PostProcess)->processMovies('', $guid, $renamed); |
|
67
|
|
|
break; |
|
68
|
|
|
|
|
69
|
|
|
case 'tv': |
|
70
|
|
|
(new PostProcess)->processTv('', $guid, $renamed); |
|
71
|
|
|
break; |
|
72
|
|
|
|
|
73
|
|
|
default: |
|
74
|
|
|
$this->error('Invalid type. Must be: additional, nfo, movie, or tv.'); |
|
75
|
|
|
|
|
76
|
|
|
return self::FAILURE; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return self::SUCCESS; |
|
80
|
|
|
} catch (\Throwable $e) { |
|
81
|
|
|
Log::error($e->getTraceAsString()); |
|
82
|
|
|
$this->error($e->getMessage()); |
|
83
|
|
|
|
|
84
|
|
|
return self::FAILURE; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Check if the character contains a-f or 0-9. |
|
90
|
|
|
*/ |
|
91
|
|
|
private function isValidChar(string $char): bool |
|
92
|
|
|
{ |
|
93
|
|
|
return \in_array( |
|
94
|
|
|
$char, |
|
95
|
|
|
['a', 'b', 'c', 'd', 'e', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], |
|
96
|
|
|
true |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get NNTP connection. |
|
102
|
|
|
*/ |
|
103
|
|
|
private function getNntp(): NNTP |
|
104
|
|
|
{ |
|
105
|
|
|
$nntp = new NNTP; |
|
106
|
|
|
|
|
107
|
|
|
if ((config('nntmux_nntp.use_alternate_nntp_server') === true |
|
108
|
|
|
? $nntp->doConnect(false, true) |
|
109
|
|
|
: $nntp->doConnect()) !== true) { |
|
110
|
|
|
throw new \Exception('Unable to connect to usenet.'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $nntp; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.