Passed
Push — master ( 5c4032...8afd6e )
by Darko
08:12
created

FixReleaseNames::showHelp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 30
rs 9.472
cc 1
nc 1
nop 0
1
<?php
2
3
     namespace App\Console\Commands;
4
5
     use Blacklight\NameFixer;
6
     use Blacklight\NNTP;
7
     use Illuminate\Console\Command;
8
9
     class FixReleaseNames extends Command
10
     {
11
         /**
12
          * The name and signature of the console command.
13
          *
14
          * @var string
15
          */
16
         protected $signature = 'releases:fix-names
17
                                 {method : The method number (3-20) to use for fixing names}
18
                                 {--update : Actually update the names, otherwise just display results}
19
                                 {--category=other : Category to process: "other", "all", or "predb_id"}
20
                                 {--set-status : Set releases as checked after processing}
21
                                 {--show : Display detailed release changes rather than just counters}';
22
23
         /**
24
          * The console command description.
25
          *
26
          * @var string
27
          */
28
         protected $description = 'Fix release names using various methods (NFO, file name, Par2, etc.)';
29
30
         /**
31
          * Execute the console command.
32
          */
33
         public function handle(NameFixer $nameFixer, NNTP $nntp): int
34
         {
35
             $method = $this->argument('method');
36
             $update = $this->option('update');
37
             $setStatus = $this->option('set-status');
38
             $show = $this->option('show') ? 1 : 2;
39
40
             // Set category option
41
             $categoryOption = $this->option('category');
42
             $other = 1;
43
             if ($categoryOption === 'all') {
44
                 $other = 2;
45
             } elseif ($categoryOption === 'predb_id') {
46
                 $other = 3;
47
             }
48
49
             // Connect to NNTP if method requires it
50
             if ($method === '7' || $method === '8') {
51
                 $compressedHeaders = config('nntmux_nntp.compressed_headers');
52
                 if ((config('nntmux_nntp.use_alternate_nntp_server') === true ?
53
                     $nntp->doConnect($compressedHeaders, true) :
54
                     $nntp->doConnect()) !== true) {
55
                     $this->error('Unable to connect to usenet.');
56
                     return 1;
57
                 }
58
             }
59
60
             switch ($method) {
61
                 case '3':
62
                     $nameFixer->fixNamesWithNfo(1, $update, $other, $setStatus, $show);
63
                     break;
64
                 case '4':
65
                     $nameFixer->fixNamesWithNfo(2, $update, $other, $setStatus, $show);
66
                     break;
67
                 case '5':
68
                     $nameFixer->fixNamesWithFiles(1, $update, $other, $setStatus, $show);
69
                     break;
70
                 case '6':
71
                     $nameFixer->fixNamesWithFiles(2, $update, $other, $setStatus, $show);
72
                     break;
73
                 case '7':
74
                     $nameFixer->fixNamesWithPar2(1, $update, $other, $setStatus, $show, $nntp);
75
                     break;
76
                 case '8':
77
                     $nameFixer->fixNamesWithPar2(2, $update, $other, $setStatus, $show, $nntp);
78
                     break;
79
                 case '9':
80
                     $nameFixer->fixNamesWithMedia(1, $update, $other, $setStatus, $show);
81
                     break;
82
                 case '10':
83
                     $nameFixer->fixNamesWithMedia(2, $update, $other, $setStatus, $show);
84
                     break;
85
                 case '11':
86
                     $nameFixer->fixXXXNamesWithFiles(1, $update, $other, $setStatus, $show);
87
                     break;
88
                 case '12':
89
                     $nameFixer->fixXXXNamesWithFiles(2, $update, $other, $setStatus, $show);
90
                     break;
91
                 case '13':
92
                     $nameFixer->fixNamesWithSrr(1, $update, $other, $setStatus, $show);
93
                     break;
94
                 case '14':
95
                     $nameFixer->fixNamesWithSrr(2, $update, $other, $setStatus, $show);
96
                     break;
97
                 case '15':
98
                     $nameFixer->fixNamesWithParHash(1, $update, $other, $setStatus, $show);
99
                     break;
100
                 case '16':
101
                     $nameFixer->fixNamesWithParHash(2, $update, $other, $setStatus, $show);
102
                     break;
103
                 case '17':
104
                     $nameFixer->fixNamesWithMediaMovieName(1, $update, $other, $setStatus, $show);
105
                     break;
106
                 case '18':
107
                     $nameFixer->fixNamesWithMediaMovieName(2, $update, $other, $setStatus, $show);
108
                     break;
109
                 case '19':
110
                     $nameFixer->fixNamesWithCrc(1, $update, $other, $setStatus, $show);
111
                     break;
112
                 case '20':
113
                     $nameFixer->fixNamesWithCrc(2, $update, $other, $setStatus, $show);
114
                     break;
115
                 default:
116
                     $this->showHelp();
117
                     return 1;
118
             }
119
120
             return 0;
121
         }
122
123
         /**
124
          * Display detailed help information.
125
          */
126
         protected function showHelp(): void
127
         {
128
             $this->info('');
129
             $this->info('Usage Examples:');
130
             $this->info('');
131
             $this->info('php artisan releases:fix-names 3 : Fix release names using NFO in the past 6 hours.');
132
             $this->info('php artisan releases:fix-names 4 : Fix release names using NFO.');
133
             $this->info('php artisan releases:fix-names 5 : Fix release names in misc categories using File Name in the past 6 hours.');
134
             $this->info('php artisan releases:fix-names 6 : Fix release names in misc categories using File Name.');
135
             $this->info('php artisan releases:fix-names 7 : Fix release names in misc categories using Par2 Files in the past 6 hours.');
136
             $this->info('php artisan releases:fix-names 8 : Fix release names in misc categories using Par2 Files.');
137
             $this->info('php artisan releases:fix-names 9 : Fix release names in misc categories using UID in the past 6 hours.');
138
             $this->info('php artisan releases:fix-names 10 : Fix release names in misc categories using UID.');
139
             $this->info('php artisan releases:fix-names 11 : Fix SDPORN XXX release names using specific File Name in the past 6 hours.');
140
             $this->info('php artisan releases:fix-names 12 : Fix SDPORN XXX release names using specific File Name.');
141
             $this->info('php artisan releases:fix-names 13 : Fix release names using SRR files in the past 6 hours.');
142
             $this->info('php artisan releases:fix-names 14 : Fix release names using SRR files.');
143
             $this->info('php artisan releases:fix-names 15 : Fix release names using PAR2 hash_16K block in the past 6 hours.');
144
             $this->info('php artisan releases:fix-names 16 : Fix release names using PAR2 hash_16K block.');
145
             $this->info('php artisan releases:fix-names 17 : Fix release names using Mediainfo in the past 6 hours.');
146
             $this->info('php artisan releases:fix-names 18 : Fix release names using Mediainfo.');
147
             $this->info('php artisan releases:fix-names 19 : Fix release names using CRC32 in the past 6 hours.');
148
             $this->info('php artisan releases:fix-names 20 : Fix release names using CRC32.');
149
             $this->info('');
150
             $this->info('Options:');
151
             $this->info('  --update           Actually update the names (default: only display potential changes)');
152
             $this->info('  --category=VALUE   Process "other" categories (default), "all" categories, or "predb_id" for unmatched');
153
             $this->info('  --set-status       Mark releases as checked so they won\'t be processed again');
154
             $this->info('  --show             Display detailed release changes (default: only show counters)');
155
             $this->info('');
156
         }
157
     }
158