NNTmux /
newznab-tmux
| 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, tv, anime, or books} |
||
| 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); |
||
|
0 ignored issues
–
show
|
|||
| 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 | case 'anime': |
||
| 74 | (new PostProcess)->processAnime('', $guid); |
||
| 75 | break; |
||
| 76 | |||
| 77 | case 'books': |
||
| 78 | (new PostProcess)->processBooks('', $guid); |
||
| 79 | break; |
||
| 80 | |||
| 81 | default: |
||
| 82 | $this->error('Invalid type. Must be: additional, nfo, movie, tv, anime, or books.'); |
||
| 83 | |||
| 84 | return self::FAILURE; |
||
| 85 | } |
||
| 86 | |||
| 87 | return self::SUCCESS; |
||
| 88 | } catch (\Throwable $e) { |
||
| 89 | Log::error($e->getTraceAsString()); |
||
| 90 | $this->error($e->getMessage()); |
||
| 91 | |||
| 92 | return self::FAILURE; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Check if the character contains a-f or 0-9. |
||
| 98 | */ |
||
| 99 | private function isValidChar(string $char): bool |
||
| 100 | { |
||
| 101 | return \in_array( |
||
| 102 | $char, |
||
| 103 | ['a', 'b', 'c', 'd', 'e', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], |
||
| 104 | true |
||
| 105 | ); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Get NNTP connection. |
||
| 110 | */ |
||
| 111 | private function getNntp(): NNTP |
||
| 112 | { |
||
| 113 | $nntp = new NNTP; |
||
| 114 | |||
| 115 | if ((config('nntmux_nntp.use_alternate_nntp_server') === true |
||
| 116 | ? $nntp->doConnect(false, true) |
||
| 117 | : $nntp->doConnect()) !== true) { |
||
| 118 | throw new \Exception('Unable to connect to usenet.'); |
||
| 119 | } |
||
| 120 | |||
| 121 | return $nntp; |
||
| 122 | } |
||
| 123 | } |
||
| 124 |
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.