|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Blacklight\NNTP; |
|
6
|
|
|
use Blacklight\processing\PostProcess; |
|
7
|
|
|
use Illuminate\Console\Command; |
|
8
|
|
|
|
|
9
|
|
|
class UpdatePostProcess extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The name and signature of the console command. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $signature = 'update:postprocess |
|
17
|
|
|
{type : Type (all, nfo, movies, tv, music, console, games, book, anime, xxx, additional, amazon)} |
|
18
|
|
|
{echo? : Echo output (true/false, default: true)}'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description = 'Post-process releases by type'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Valid types and whether they require NNTP. |
|
29
|
|
|
*/ |
|
30
|
|
|
private array $validTypes = [ |
|
31
|
|
|
'additional' => false, |
|
32
|
|
|
'all' => true, |
|
33
|
|
|
'amazon' => false, // Alias for book, music, console, games, xxx |
|
34
|
|
|
'anime' => false, |
|
35
|
|
|
'book' => false, |
|
36
|
|
|
'console' => false, |
|
37
|
|
|
'games' => false, |
|
38
|
|
|
'movies' => false, |
|
39
|
|
|
'music' => false, |
|
40
|
|
|
'nfo' => true, |
|
41
|
|
|
'tv' => false, |
|
42
|
|
|
'xxx' => false, |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Execute the console command. |
|
47
|
|
|
*/ |
|
48
|
|
|
public function handle(): int |
|
49
|
|
|
{ |
|
50
|
|
|
$type = $this->argument('type'); |
|
51
|
|
|
$echoArg = $this->argument('echo'); |
|
52
|
|
|
$echo = ($echoArg === null || $echoArg === 'true'); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
if (! array_key_exists($type, $this->validTypes)) { |
|
|
|
|
|
|
55
|
|
|
$this->error("Invalid type: {$type}"); |
|
56
|
|
|
$this->showHelp(); |
|
57
|
|
|
|
|
58
|
|
|
return self::FAILURE; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
try { |
|
62
|
|
|
$nntp = $this->validTypes[$type] ? $this->getNntp() : null; |
|
63
|
|
|
$postProcess = new PostProcess; |
|
64
|
|
|
|
|
65
|
|
|
match ($type) { |
|
66
|
|
|
'all' => $postProcess->processAll($nntp), |
|
|
|
|
|
|
67
|
|
|
'amazon' => $this->processAmazon($postProcess), |
|
|
|
|
|
|
68
|
|
|
'nfo' => $postProcess->processNfos($nntp), |
|
|
|
|
|
|
69
|
|
|
'movies' => $postProcess->processMovies(), |
|
|
|
|
|
|
70
|
|
|
'music' => $postProcess->processMusic(), |
|
|
|
|
|
|
71
|
|
|
'console' => $postProcess->processConsoles(), |
|
|
|
|
|
|
72
|
|
|
'games' => $postProcess->processGames(), |
|
|
|
|
|
|
73
|
|
|
'book' => $postProcess->processBooks(), |
|
|
|
|
|
|
74
|
|
|
'anime' => $postProcess->processAnime(), |
|
|
|
|
|
|
75
|
|
|
'tv' => $postProcess->processTv(), |
|
|
|
|
|
|
76
|
|
|
'xxx' => $postProcess->processXXX(), |
|
|
|
|
|
|
77
|
|
|
'additional' => $postProcess->processAdditional(), |
|
|
|
|
|
|
78
|
|
|
default => throw new \Exception("Unhandled type: {$type}"), |
|
79
|
|
|
}; |
|
80
|
|
|
|
|
81
|
|
|
return self::SUCCESS; |
|
82
|
|
|
} catch (\Throwable $e) { |
|
83
|
|
|
$this->error($e->getMessage()); |
|
84
|
|
|
|
|
85
|
|
|
return self::FAILURE; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Show help text. |
|
91
|
|
|
*/ |
|
92
|
|
|
private function showHelp(): void |
|
93
|
|
|
{ |
|
94
|
|
|
$this->line(''); |
|
95
|
|
|
$this->line('Available types:'); |
|
96
|
|
|
$this->line(' all - Does all the types of post processing'); |
|
97
|
|
|
$this->line(' nfo - Processes NFO files'); |
|
98
|
|
|
$this->line(' movies - Processes movies'); |
|
99
|
|
|
$this->line(' music - Processes music'); |
|
100
|
|
|
$this->line(' console - Processes console games'); |
|
101
|
|
|
$this->line(' games - Processes games'); |
|
102
|
|
|
$this->line(' book - Processes books'); |
|
103
|
|
|
$this->line(' anime - Processes anime'); |
|
104
|
|
|
$this->line(' tv - Processes tv'); |
|
105
|
|
|
$this->line(' xxx - Processes xxx'); |
|
106
|
|
|
$this->line(' additional - Processes previews/mediainfo/etc...'); |
|
107
|
|
|
$this->line(' amazon - Processes books, music, console, games, and xxx'); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Process amazon types (books, music, console, games, xxx). |
|
112
|
|
|
*/ |
|
113
|
|
|
private function processAmazon(PostProcess $postProcess): void |
|
114
|
|
|
{ |
|
115
|
|
|
$postProcess->processBooks(); |
|
116
|
|
|
$postProcess->processMusic(); |
|
117
|
|
|
$postProcess->processConsoles(); |
|
118
|
|
|
$postProcess->processGames(); |
|
119
|
|
|
$postProcess->processXXX(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Get NNTP connection. |
|
124
|
|
|
*/ |
|
125
|
|
|
private function getNntp(): NNTP |
|
126
|
|
|
{ |
|
127
|
|
|
$nntp = new NNTP; |
|
128
|
|
|
|
|
129
|
|
|
if ((config('nntmux_nntp.use_alternate_nntp_server') === true |
|
130
|
|
|
? $nntp->doConnect(false, true) |
|
131
|
|
|
: $nntp->doConnect()) !== true) { |
|
132
|
|
|
throw new \Exception('Unable to connect to usenet.'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return $nntp; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|