1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Blacklight; |
4
|
|
|
|
5
|
|
|
use App\Models\Group; |
6
|
|
|
use App\Models\Predb; |
7
|
|
|
use App\Models\Release; |
8
|
|
|
use App\Models\Category; |
9
|
|
|
use Illuminate\Support\Arr; |
10
|
|
|
use Blacklight\utility\Utility; |
11
|
|
|
use Blacklight\processing\PostProcess; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class NameFixer. |
15
|
|
|
*/ |
16
|
|
|
class NameFixer |
17
|
|
|
{ |
18
|
|
|
public const PREDB_REGEX = '/([\w\(\)]+[\s\._-]([\w\(\)]+[\s\._-])+[\w\(\)]+-\w+)/'; |
19
|
|
|
|
20
|
|
|
// Constants for name fixing status |
21
|
|
|
public const PROC_NFO_NONE = 0; |
22
|
|
|
public const PROC_NFO_DONE = 1; |
23
|
|
|
public const PROC_FILES_NONE = 0; |
24
|
|
|
public const PROC_FILES_DONE = 1; |
25
|
|
|
public const PROC_PAR2_NONE = 0; |
26
|
|
|
public const PROC_PAR2_DONE = 1; |
27
|
|
|
public const PROC_UID_NONE = 0; |
28
|
|
|
public const PROC_UID_DONE = 1; |
29
|
|
|
public const PROC_HASH16K_NONE = 0; |
30
|
|
|
public const PROC_HASH16K_DONE = 1; |
31
|
|
|
public const PROC_SRR_NONE = 0; |
32
|
|
|
public const PROC_SRR_DONE = 1; |
33
|
|
|
public const PROC_CRC_NONE = 0; |
34
|
|
|
public const PROC_CRC_DONE = 1; |
35
|
|
|
|
36
|
|
|
// Constants for overall rename status |
37
|
|
|
public const IS_RENAMED_NONE = 0; |
38
|
|
|
public const IS_RENAMED_DONE = 1; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Has the current release found a new name? |
42
|
|
|
* |
43
|
|
|
* @var bool |
44
|
|
|
*/ |
45
|
|
|
public $matched; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* How many releases have got a new name? |
49
|
|
|
* |
50
|
|
|
* @var int |
51
|
|
|
*/ |
52
|
|
|
public $fixed; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* How many releases were checked. |
56
|
|
|
* |
57
|
|
|
* @var int |
58
|
|
|
*/ |
59
|
|
|
public $checked; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Whether or not the check has completed. |
63
|
|
|
* |
64
|
|
|
* @var bool |
65
|
|
|
*/ |
66
|
|
|
public $done; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Whether or not to echo info to CLI. |
70
|
|
|
* |
71
|
|
|
* @var bool |
72
|
|
|
*/ |
73
|
|
|
public $echooutput; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Total releases we are working on. |
77
|
|
|
* |
78
|
|
|
* @var int |
79
|
|
|
*/ |
80
|
|
|
protected $_totalReleases; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* The cleaned filename we want to match. |
84
|
|
|
* |
85
|
|
|
* @var string |
86
|
|
|
*/ |
87
|
|
|
protected $_fileName; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* The release ID we are trying to rename. |
91
|
|
|
* |
92
|
|
|
* @var int |
93
|
|
|
*/ |
94
|
|
|
protected $relid; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var string |
98
|
|
|
*/ |
99
|
|
|
protected $othercats; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var string |
103
|
|
|
*/ |
104
|
|
|
protected $timeother; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var string |
108
|
|
|
*/ |
109
|
|
|
protected $timeall; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var string |
113
|
|
|
*/ |
114
|
|
|
protected $fullother; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @var string |
118
|
|
|
*/ |
119
|
|
|
protected $fullall; |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @var \Blacklight\ConsoleTools |
123
|
|
|
*/ |
124
|
|
|
public $consoletools; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @var \Blacklight\Categorize |
128
|
|
|
*/ |
129
|
|
|
public $category; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @var \Blacklight\utility\Utility |
133
|
|
|
*/ |
134
|
|
|
public $text; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @var \Blacklight\SphinxSearch |
138
|
|
|
*/ |
139
|
|
|
public $sphinx; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @var \Blacklight\ColorCLI |
143
|
|
|
*/ |
144
|
|
|
protected $colorCli; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param array $options Class instances / Echo to cli. |
148
|
|
|
* @throws \Exception |
149
|
|
|
*/ |
150
|
|
|
public function __construct(array $options = []) |
151
|
|
|
{ |
152
|
|
|
$defaults = [ |
153
|
|
|
'Echo' => true, |
154
|
|
|
'Categorize' => null, |
155
|
|
|
'ConsoleTools' => null, |
156
|
|
|
'Groups' => null, |
157
|
|
|
'Misc' => null, |
158
|
|
|
'Settings' => null, |
159
|
|
|
'SphinxSearch' => null, |
160
|
|
|
]; |
161
|
|
|
$options += $defaults; |
162
|
|
|
|
163
|
|
|
$this->echooutput = ($options['Echo'] && config('nntmux.echocli')); |
164
|
|
|
$this->relid = $this->fixed = $this->checked = 0; |
165
|
|
|
$this->othercats = implode(',', Category::OTHERS_GROUP); |
166
|
|
|
$this->timeother = sprintf(' AND rel.adddate > (NOW() - INTERVAL 6 HOUR) AND rel.categories_id IN (%s) GROUP BY rel.id ORDER BY postdate DESC', $this->othercats); |
167
|
|
|
$this->timeall = ' AND rel.adddate > (NOW() - INTERVAL 6 HOUR) GROUP BY rel.id ORDER BY postdate DESC'; |
168
|
|
|
$this->fullother = sprintf(' AND rel.categories_id IN (%s) GROUP BY rel.id', $this->othercats); |
169
|
|
|
$this->fullall = ''; |
170
|
|
|
$this->_fileName = ''; |
171
|
|
|
$this->done = $this->matched = false; |
172
|
|
|
$this->consoletools = ($options['ConsoleTools'] instanceof ConsoleTools ? $options['ConsoleTools'] : new ConsoleTools()); |
173
|
|
|
$this->category = ($options['Categorize'] instanceof Categorize ? $options['Categorize'] : new Categorize(['Settings' => null])); |
|
|
|
|
174
|
|
|
$this->sphinx = ($options['SphinxSearch'] instanceof SphinxSearch ? $options['SphinxSearch'] : new SphinxSearch()); |
175
|
|
|
$this->colorCli = new ColorCLI(); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Attempts to fix release names using the NFO. |
180
|
|
|
* |
181
|
|
|
* |
182
|
|
|
* @param $time |
183
|
|
|
* @param $echo |
184
|
|
|
* @param $cats |
185
|
|
|
* @param $nameStatus |
186
|
|
|
* @param $show |
187
|
|
|
* @throws \Exception |
188
|
|
|
*/ |
189
|
|
|
public function fixNamesWithNfo($time, $echo, $cats, $nameStatus, $show): void |
190
|
|
|
{ |
191
|
|
|
$this->_echoStartMessage($time, '.nfo files'); |
192
|
|
|
$type = 'NFO, '; |
193
|
|
|
|
194
|
|
|
// Only select releases we haven't checked here before |
195
|
|
|
$preId = false; |
196
|
|
|
if ($cats === 3) { |
197
|
|
|
$query = sprintf( |
198
|
|
|
' |
199
|
|
|
SELECT rel.id AS releases_id, rel.fromname |
200
|
|
|
FROM releases rel |
201
|
|
|
INNER JOIN release_nfos nfo ON (nfo.releases_id = rel.id) |
202
|
|
|
WHERE rel.nzbstatus = %d |
203
|
|
|
AND rel.predb_id = 0', |
204
|
|
|
NZB::NZB_ADDED |
205
|
|
|
); |
206
|
|
|
$cats = 2; |
207
|
|
|
$preId = true; |
208
|
|
|
} else { |
209
|
|
|
$query = sprintf( |
210
|
|
|
' |
211
|
|
|
SELECT rel.id AS releases_id, rel.fromname |
212
|
|
|
FROM releases rel |
213
|
|
|
INNER JOIN release_nfos nfo ON (nfo.releases_id = rel.id) |
214
|
|
|
WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d)) |
215
|
|
|
AND rel.predb_id = 0 |
216
|
|
|
AND rel.proc_nfo = %d', |
217
|
|
|
self::IS_RENAMED_NONE, |
218
|
|
|
Category::OTHER_MISC, |
219
|
|
|
Category::OTHER_HASHED, |
220
|
|
|
self::PROC_NFO_NONE |
221
|
|
|
); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
$releases = $this->_getReleases($time, $cats, $query); |
225
|
|
|
|
226
|
|
|
$total = \count($releases); |
|
|
|
|
227
|
|
|
|
228
|
|
|
if ($total > 0) { |
229
|
|
|
$this->_totalReleases = $total; |
230
|
|
|
$this->colorCli->primary(number_format($total).' releases to process.'); |
231
|
|
|
|
232
|
|
|
foreach ($releases as $rel) { |
|
|
|
|
233
|
|
|
$releaseRow = Release::fromQuery( |
234
|
|
|
sprintf( |
235
|
|
|
' |
236
|
|
|
SELECT nfo.releases_id AS nfoid, rel.groups_id, rel.fromname, rel.categories_id, rel.name, rel.searchname, |
237
|
|
|
UNCOMPRESS(nfo) AS textstring, rel.id AS releases_id |
238
|
|
|
FROM releases rel |
239
|
|
|
INNER JOIN release_nfos nfo ON (nfo.releases_id = rel.id) |
240
|
|
|
WHERE rel.id = %d LIMIT 1', |
241
|
|
|
$rel->releases_id |
242
|
|
|
) |
243
|
|
|
); |
244
|
|
|
|
245
|
|
|
$this->checked++; |
246
|
|
|
|
247
|
|
|
// Ignore encrypted NFOs. |
248
|
|
|
if (preg_match('/^=newz\[NZB\]=\w+/', $releaseRow[0]->textstring)) { |
249
|
|
|
$this->_updateSingleColumn('proc_nfo', self::PROC_NFO_DONE, $rel->releases_id); |
250
|
|
|
continue; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
$this->reset(); |
254
|
|
|
$this->checkName($releaseRow[0], $echo, $type, $nameStatus, $show, $preId); |
255
|
|
|
$this->_echoRenamed($show); |
256
|
|
|
} |
257
|
|
|
$this->_echoFoundCount($echo, ' NFO\'s'); |
258
|
|
|
} else { |
259
|
|
|
$this->colorCli->info('Nothing to fix.'); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Attempts to fix release names using the File name. |
265
|
|
|
* |
266
|
|
|
* |
267
|
|
|
* @param $time |
268
|
|
|
* @param $echo |
269
|
|
|
* @param $cats |
270
|
|
|
* @param $nameStatus |
271
|
|
|
* @param $show |
272
|
|
|
* @throws \Exception |
273
|
|
|
*/ |
274
|
|
|
public function fixNamesWithFiles($time, $echo, $cats, $nameStatus, $show): void |
275
|
|
|
{ |
276
|
|
|
$this->_echoStartMessage($time, 'file names'); |
277
|
|
|
$type = 'Filenames, '; |
278
|
|
|
|
279
|
|
|
$preId = false; |
280
|
|
|
if ($cats === 3) { |
281
|
|
|
$query = sprintf( |
282
|
|
|
' |
283
|
|
|
SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, |
284
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
285
|
|
|
FROM releases rel |
286
|
|
|
INNER JOIN release_files rf ON rf.releases_id = rel.id |
287
|
|
|
WHERE nzbstatus = %d |
288
|
|
|
AND predb_id = 0', |
289
|
|
|
NZB::NZB_ADDED |
290
|
|
|
); |
291
|
|
|
$cats = 2; |
292
|
|
|
$preId = true; |
293
|
|
|
} else { |
294
|
|
|
$query = sprintf( |
295
|
|
|
' |
296
|
|
|
SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, |
297
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
298
|
|
|
FROM releases rel |
299
|
|
|
INNER JOIN release_files rf ON rf.releases_id = rel.id |
300
|
|
|
WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d)) |
301
|
|
|
AND rel.predb_id = 0 |
302
|
|
|
AND proc_files = %d', |
303
|
|
|
self::IS_RENAMED_NONE, |
304
|
|
|
Category::OTHER_MISC, |
305
|
|
|
Category::OTHER_HASHED, |
306
|
|
|
self::PROC_FILES_NONE |
307
|
|
|
); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
$releases = $this->_getReleases($time, $cats, $query); |
311
|
|
|
$total = \count($releases); |
|
|
|
|
312
|
|
|
if ($total > 0) { |
313
|
|
|
$this->_totalReleases = $total; |
314
|
|
|
$this->colorCli->primary(number_format($total).' file names to process.'); |
315
|
|
|
|
316
|
|
|
foreach ($releases as $release) { |
|
|
|
|
317
|
|
|
$this->reset(); |
318
|
|
|
$this->checkName($release, $echo, $type, $nameStatus, $show, $preId); |
319
|
|
|
$this->checked++; |
320
|
|
|
$this->_echoRenamed($show); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
$this->_echoFoundCount($echo, ' files'); |
324
|
|
|
} else { |
325
|
|
|
$this->colorCli->info('Nothing to fix.'); |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Attempts to fix release names using the rar file crc32 hash. |
331
|
|
|
* |
332
|
|
|
* |
333
|
|
|
* @param $time |
334
|
|
|
* @param $echo |
335
|
|
|
* @param $cats |
336
|
|
|
* @param $nameStatus |
337
|
|
|
* @param $show |
338
|
|
|
* @throws \Exception |
339
|
|
|
*/ |
340
|
|
|
public function fixNamesWithCrc($time, $echo, $cats, $nameStatus, $show): void |
341
|
|
|
{ |
342
|
|
|
$this->_echoStartMessage($time, 'CRC32'); |
343
|
|
|
$type = 'CRC32, '; |
344
|
|
|
|
345
|
|
|
$preId = false; |
346
|
|
|
if ($cats === 3) { |
347
|
|
|
$query = sprintf( |
348
|
|
|
' |
349
|
|
|
SELECT rf.crc32 AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, rel.size as relsize, |
350
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
351
|
|
|
FROM releases rel |
352
|
|
|
INNER JOIN release_files rf ON rf.releases_id = rel.id |
353
|
|
|
WHERE nzbstatus = %d |
354
|
|
|
AND predb_id = 0', |
355
|
|
|
NZB::NZB_ADDED |
356
|
|
|
); |
357
|
|
|
$cats = 2; |
358
|
|
|
$preId = true; |
359
|
|
|
} else { |
360
|
|
|
$query = sprintf( |
361
|
|
|
' |
362
|
|
|
SELECT rf.crc32 AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, rel.size as relsize, |
363
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
364
|
|
|
FROM releases rel |
365
|
|
|
INNER JOIN release_files rf ON rf.releases_id = rel.id |
366
|
|
|
WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d)) |
367
|
|
|
AND rel.predb_id = 0 |
368
|
|
|
AND rel.proc_crc32 = %d', |
369
|
|
|
self::IS_RENAMED_NONE, |
370
|
|
|
Category::OTHER_MISC, |
371
|
|
|
Category::OTHER_HASHED, |
372
|
|
|
self::PROC_CRC_NONE |
373
|
|
|
); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
$releases = $this->_getReleases($time, $cats, $query); |
377
|
|
|
$total = \count($releases); |
|
|
|
|
378
|
|
|
if ($total > 0) { |
379
|
|
|
$this->_totalReleases = $total; |
380
|
|
|
$this->colorCli->primary(number_format($total).' CRC32\'s to process.'); |
381
|
|
|
|
382
|
|
|
foreach ($releases as $release) { |
|
|
|
|
383
|
|
|
$this->reset(); |
384
|
|
|
$this->checkName($release, $echo, $type, $nameStatus, $show, $preId); |
385
|
|
|
$this->checked++; |
386
|
|
|
$this->_echoRenamed($show); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
$this->_echoFoundCount($echo, ' crc32\'s'); |
390
|
|
|
} else { |
391
|
|
|
$this->colorCli->info('Nothing to fix.'); |
392
|
|
|
} |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* Attempts to fix XXX release names using the File name. |
397
|
|
|
* |
398
|
|
|
* |
399
|
|
|
* @param $time |
400
|
|
|
* @param $echo |
401
|
|
|
* @param $cats |
402
|
|
|
* @param $nameStatus |
403
|
|
|
* @param $show |
404
|
|
|
* @throws \Exception |
405
|
|
|
*/ |
406
|
|
|
public function fixXXXNamesWithFiles($time, $echo, $cats, $nameStatus, $show): void |
407
|
|
|
{ |
408
|
|
|
$this->_echoStartMessage($time, 'file names'); |
409
|
|
|
$type = 'Filenames, '; |
410
|
|
|
|
411
|
|
|
if ($cats === 3) { |
412
|
|
|
$query = sprintf( |
413
|
|
|
' |
414
|
|
|
SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, |
415
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
416
|
|
|
FROM releases rel |
417
|
|
|
INNER JOIN release_files rf ON rf.releases_id = rel.id |
418
|
|
|
WHERE nzbstatus = %d |
419
|
|
|
AND predb_id = 0', |
420
|
|
|
NZB::NZB_ADDED |
421
|
|
|
); |
422
|
|
|
$cats = 2; |
423
|
|
|
} else { |
424
|
|
|
$query = sprintf( |
425
|
|
|
' |
426
|
|
|
SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, |
427
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
428
|
|
|
FROM releases rel |
429
|
|
|
INNER JOIN release_files rf ON rf.releases_id = rel.id |
430
|
|
|
WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d)) |
431
|
|
|
AND rel.predb_id = 0 |
432
|
|
|
AND rf.name LIKE %s', |
433
|
|
|
self::IS_RENAMED_NONE, |
434
|
|
|
Category::OTHER_MISC, |
435
|
|
|
Category::OTHER_HASHED, |
436
|
|
|
escapeString('%SDPORN%') |
437
|
|
|
); |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
$releases = $this->_getReleases($time, $cats, $query); |
441
|
|
|
$total = \count($releases); |
|
|
|
|
442
|
|
|
if ($total > 0) { |
443
|
|
|
$this->_totalReleases = $total; |
444
|
|
|
$this->colorCli->primary(number_format($total).' xxx file names to process.'); |
445
|
|
|
|
446
|
|
|
foreach ($releases as $release) { |
|
|
|
|
447
|
|
|
$this->reset(); |
448
|
|
|
$this->xxxNameCheck($release, $echo, $type, $nameStatus, $show); |
449
|
|
|
$this->checked++; |
450
|
|
|
$this->_echoRenamed($show); |
451
|
|
|
} |
452
|
|
|
$this->_echoFoundCount($echo, ' files'); |
453
|
|
|
} else { |
454
|
|
|
$this->colorCli->info('Nothing to fix.'); |
455
|
|
|
} |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Attempts to fix release names using the SRR filename. |
460
|
|
|
* |
461
|
|
|
* |
462
|
|
|
* @param $time |
463
|
|
|
* @param $echo |
464
|
|
|
* @param $cats |
465
|
|
|
* @param $nameStatus |
466
|
|
|
* @param $show |
467
|
|
|
* @throws \Exception |
468
|
|
|
*/ |
469
|
|
|
public function fixNamesWithSrr($time, $echo, $cats, $nameStatus, $show): void |
470
|
|
|
{ |
471
|
|
|
$this->_echoStartMessage($time, 'SRR file names'); |
472
|
|
|
$type = 'SRR, '; |
473
|
|
|
|
474
|
|
|
if ($cats === 3) { |
475
|
|
|
$query = sprintf( |
476
|
|
|
' |
477
|
|
|
SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, |
478
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
479
|
|
|
FROM releases rel |
480
|
|
|
INNER JOIN release_files rf ON rf.releases_id = rel.id |
481
|
|
|
WHERE nzbstatus = %d |
482
|
|
|
AND predb_id = 0', |
483
|
|
|
NZB::NZB_ADDED |
484
|
|
|
); |
485
|
|
|
$cats = 2; |
486
|
|
|
} else { |
487
|
|
|
$query = sprintf( |
488
|
|
|
' |
489
|
|
|
SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, |
490
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
491
|
|
|
FROM releases rel |
492
|
|
|
INNER JOIN release_files rf ON rf.releases_id = rel.id |
493
|
|
|
WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d)) |
494
|
|
|
AND rel.predb_id = 0 |
495
|
|
|
AND rf.name LIKE %s |
496
|
|
|
AND rel.proc_srr = %d', |
497
|
|
|
self::IS_RENAMED_NONE, |
498
|
|
|
Category::OTHER_MISC, |
499
|
|
|
Category::OTHER_HASHED, |
500
|
|
|
escapeString('%.srr'), |
501
|
|
|
self::PROC_SRR_NONE |
502
|
|
|
); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
$releases = $this->_getReleases($time, $cats, $query); |
506
|
|
|
$total = \count($releases); |
|
|
|
|
507
|
|
|
if ($total > 0) { |
508
|
|
|
$this->_totalReleases = $total; |
509
|
|
|
$this->colorCli->primary(number_format($total).' srr file extensions to process.'); |
510
|
|
|
|
511
|
|
|
foreach ($releases as $release) { |
|
|
|
|
512
|
|
|
$this->reset(); |
513
|
|
|
$this->srrNameCheck($release, $echo, $type, $nameStatus, $show); |
514
|
|
|
$this->checked++; |
515
|
|
|
$this->_echoRenamed($show); |
516
|
|
|
} |
517
|
|
|
$this->_echoFoundCount($echo, ' files'); |
518
|
|
|
} else { |
519
|
|
|
$this->colorCli->info('Nothing to fix.'); |
520
|
|
|
} |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* Attempts to fix release names using the Par2 File. |
525
|
|
|
* |
526
|
|
|
* @param int $time 1: 24 hours, 2: no time limit |
527
|
|
|
* @param int $echo 1: change the name, anything else: preview of what could have been changed. |
528
|
|
|
* @param int $cats 1: other categories, 2: all categories |
529
|
|
|
* @param $nameStatus |
530
|
|
|
* @param $show |
531
|
|
|
* @param NNTP $nntp |
532
|
|
|
* @throws \Exception |
533
|
|
|
*/ |
534
|
|
|
public function fixNamesWithPar2($time, $echo, $cats, $nameStatus, $show, $nntp): void |
535
|
|
|
{ |
536
|
|
|
$this->_echoStartMessage($time, 'par2 files'); |
537
|
|
|
|
538
|
|
|
if ($cats === 3) { |
539
|
|
|
$query = sprintf( |
540
|
|
|
' |
541
|
|
|
SELECT rel.id AS releases_id, rel.guid, rel.groups_id, rel.fromname |
542
|
|
|
FROM releases rel |
543
|
|
|
WHERE rel.nzbstatus = %d |
544
|
|
|
AND rel.predb_id = 0', |
545
|
|
|
NZB::NZB_ADDED |
546
|
|
|
); |
547
|
|
|
$cats = 2; |
548
|
|
|
} else { |
549
|
|
|
$query = sprintf( |
550
|
|
|
' |
551
|
|
|
SELECT rel.id AS releases_id, rel.guid, rel.groups_id, rel.fromname |
552
|
|
|
FROM releases rel |
553
|
|
|
WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d)) |
554
|
|
|
AND rel.predb_id = 0 |
555
|
|
|
AND rel.proc_par2 = %d', |
556
|
|
|
self::IS_RENAMED_NONE, |
557
|
|
|
Category::OTHER_MISC, |
558
|
|
|
Category::OTHER_HASHED, |
559
|
|
|
self::PROC_PAR2_NONE |
560
|
|
|
); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
$releases = $this->_getReleases($time, $cats, $query); |
564
|
|
|
|
565
|
|
|
$total = \count($releases); |
|
|
|
|
566
|
|
|
if ($total > 0) { |
567
|
|
|
$this->_totalReleases = $total; |
568
|
|
|
|
569
|
|
|
$this->colorCli->primary(number_format($total).' releases to process.'); |
570
|
|
|
$Nfo = new Nfo(); |
571
|
|
|
$nzbContents = new NZBContents( |
572
|
|
|
[ |
573
|
|
|
'Echo' => $this->echooutput, |
574
|
|
|
'NNTP' => $nntp, |
575
|
|
|
'Nfo' => $Nfo, |
576
|
|
|
'PostProcess' => new PostProcess(['Nfo' => $Nfo]), |
577
|
|
|
] |
578
|
|
|
); |
579
|
|
|
|
580
|
|
|
foreach ($releases as $release) { |
|
|
|
|
581
|
|
|
if ($nzbContents->checkPAR2($release->guid, $release->releases_id, $release->groups_id, $nameStatus, $show)) { |
582
|
|
|
$this->fixed++; |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
$this->checked++; |
586
|
|
|
$this->_echoRenamed($show); |
587
|
|
|
} |
588
|
|
|
$this->_echoFoundCount($echo, ' files'); |
589
|
|
|
} else { |
590
|
|
|
$this->colorCli->info('Nothing to fix.'); |
591
|
|
|
} |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
/** |
595
|
|
|
* Attempts to fix release names using the mediainfo xml Unique_ID. |
596
|
|
|
* |
597
|
|
|
* |
598
|
|
|
* @param $time |
599
|
|
|
* @param $echo |
600
|
|
|
* @param $cats |
601
|
|
|
* @param $nameStatus |
602
|
|
|
* @param $show |
603
|
|
|
* @throws \Exception |
604
|
|
|
*/ |
605
|
|
|
public function fixNamesWithMedia($time, $echo, $cats, $nameStatus, $show): void |
606
|
|
|
{ |
607
|
|
|
$type = 'UID, '; |
608
|
|
|
|
609
|
|
|
$this->_echoStartMessage($time, 'mediainfo Unique_IDs'); |
610
|
|
|
|
611
|
|
|
// Re-check all releases we haven't matched to a PreDB |
612
|
|
|
if ($cats === 3) { |
613
|
|
|
$query = sprintf( |
614
|
|
|
' |
615
|
|
|
SELECT |
616
|
|
|
rel.id AS releases_id, rel.size AS relsize, rel.groups_id, rel.fromname, rel.categories_id, |
617
|
|
|
rel.name, rel.name AS textstring, rel.predb_id, rel.searchname, |
618
|
|
|
ru.uniqueid AS uid |
619
|
|
|
FROM releases rel |
620
|
|
|
LEFT JOIN release_unique ru ON ru.releases_id = rel.id |
621
|
|
|
WHERE ru.releases_id IS NOT NULL |
622
|
|
|
AND rel.nzbstatus = %d |
623
|
|
|
AND rel.predb_id = 0', |
624
|
|
|
NZB::NZB_ADDED |
625
|
|
|
); |
626
|
|
|
$cats = 2; |
627
|
|
|
// Otherwise check only releases we haven't renamed and checked uid before in Misc categories |
628
|
|
|
} else { |
629
|
|
|
$query = sprintf( |
630
|
|
|
' |
631
|
|
|
SELECT |
632
|
|
|
rel.id AS releases_id, rel.size AS relsize, rel.groups_id, rel.fromname, rel.categories_id, |
633
|
|
|
rel.name, rel.name AS textstring, rel.predb_id, rel.searchname, |
634
|
|
|
ru.uniqueid AS uid |
635
|
|
|
FROM releases rel |
636
|
|
|
LEFT JOIN release_unique ru ON ru.releases_id = rel.id |
637
|
|
|
WHERE ru.releases_id IS NOT NULL |
638
|
|
|
AND rel.nzbstatus = %d |
639
|
|
|
AND (rel.isrenamed = %d OR rel.categories_id IN (%d, %d)) |
640
|
|
|
AND rel.predb_id = 0 |
641
|
|
|
AND rel.proc_uid = %d', |
642
|
|
|
NZB::NZB_ADDED, |
643
|
|
|
self::IS_RENAMED_NONE, |
644
|
|
|
Category::OTHER_MISC, |
645
|
|
|
Category::OTHER_HASHED, |
646
|
|
|
self::PROC_UID_NONE |
647
|
|
|
); |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
$releases = $this->_getReleases($time, $cats, $query); |
651
|
|
|
$total = \count($releases); |
|
|
|
|
652
|
|
|
if ($total > 0) { |
653
|
|
|
$this->_totalReleases = $total; |
654
|
|
|
$this->colorCli->primary(number_format($total).' unique ids to process.'); |
655
|
|
|
foreach ($releases as $rel) { |
|
|
|
|
656
|
|
|
$this->checked++; |
657
|
|
|
$this->reset(); |
658
|
|
|
$this->uidCheck($rel, $echo, $type, $nameStatus, $show); |
659
|
|
|
$this->_echoRenamed($show); |
660
|
|
|
} |
661
|
|
|
$this->_echoFoundCount($echo, ' UID\'s'); |
662
|
|
|
} else { |
663
|
|
|
$this->colorCli->info('Nothing to fix.'); |
664
|
|
|
} |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
/** |
668
|
|
|
* @param $time |
669
|
|
|
* @param $echo |
670
|
|
|
* @param $cats |
671
|
|
|
* @param $nameStatus |
672
|
|
|
* @param $show |
673
|
|
|
* @throws \Exception |
674
|
|
|
*/ |
675
|
|
|
public function fixNamesWithMediaMovieName($time, $echo, $cats, $nameStatus, $show): void |
676
|
|
|
{ |
677
|
|
|
$type = 'Mediainfo, '; |
678
|
|
|
|
679
|
|
|
$this->_echoStartMessage($time, 'Mediainfo movie_name'); |
680
|
|
|
|
681
|
|
|
// Re-check all releases we haven't matched to a PreDB |
682
|
|
|
if ($cats === 3) { |
683
|
|
|
$query = sprintf( |
684
|
|
|
" |
685
|
|
|
SELECT rel.id AS releases_id, rel.name, rel.name AS textstring, rel.predb_id, rel.searchname, rel.fromname, rel.groups_id, rel.categories_id, rel.id AS releases_id, rf.mediainfo AS mediainfo |
686
|
|
|
FROM releases rel |
687
|
|
|
INNER JOIN releaseextrafull rf ON rf.releases_id = rel.id |
688
|
|
|
WHERE rel.name REGEXP '[a-z0-9]{32,64}' |
689
|
|
|
AND rf.mediainfo REGEXP '\<Movie_name\>' |
690
|
|
|
AND rel.nzbstatus = %d |
691
|
|
|
AND rel.predb_id = 0", |
692
|
|
|
NZB::NZB_ADDED |
693
|
|
|
); |
694
|
|
|
$cats = 2; |
695
|
|
|
// Otherwise check only releases we haven't renamed and checked uid before in Misc categories |
696
|
|
|
} else { |
697
|
|
|
$query = sprintf( |
698
|
|
|
" |
699
|
|
|
SELECT rel.id AS releases_id, rel.name, rel.name AS textstring, rel.predb_id, rel.searchname, rel.fromname, rel.groups_id, rel.categories_id, rel.id AS releases_id, rf.mediainfo AS mediainfo |
700
|
|
|
FROM releases rel |
701
|
|
|
INNER JOIN releaseextrafull rf ON rf.releases_id = rel.id |
702
|
|
|
WHERE rel.name REGEXP '[a-z0-9]{32,64}' |
703
|
|
|
AND rf.mediainfo REGEXP '\<Movie_name\>' |
704
|
|
|
AND rel.nzbstatus = %d |
705
|
|
|
AND rel.isrenamed = %d |
706
|
|
|
AND rel.predb_id = 0 |
707
|
|
|
AND rel.categories_id IN (%d, %d)", |
708
|
|
|
NZB::NZB_ADDED, |
709
|
|
|
self::IS_RENAMED_NONE, |
710
|
|
|
Category::OTHER_MISC, |
711
|
|
|
Category::OTHER_HASHED |
712
|
|
|
); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
$releases = $this->_getReleases($time, $cats, $query); |
716
|
|
|
$total = \count($releases); |
|
|
|
|
717
|
|
|
if ($total > 0) { |
718
|
|
|
$this->_totalReleases = $total; |
719
|
|
|
$this->colorCli->primary(number_format($total).' mediainfo movie names to process.'); |
720
|
|
|
foreach ($releases as $rel) { |
|
|
|
|
721
|
|
|
$this->checked++; |
722
|
|
|
$this->reset(); |
723
|
|
|
$this->mediaMovieNameCheck($rel, $echo, $type, $nameStatus, $show); |
724
|
|
|
$this->_echoRenamed($show); |
725
|
|
|
} |
726
|
|
|
$this->_echoFoundCount($echo, ' MediaInfo\'s'); |
727
|
|
|
} else { |
728
|
|
|
$this->colorCli->info('Nothing to fix.'); |
729
|
|
|
} |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
/** |
733
|
|
|
* Attempts to fix release names using the par2 hash_16K block. |
734
|
|
|
* |
735
|
|
|
* |
736
|
|
|
* @param $time |
737
|
|
|
* @param $echo |
738
|
|
|
* @param $cats |
739
|
|
|
* @param $nameStatus |
740
|
|
|
* @param $show |
741
|
|
|
* @throws \Exception |
742
|
|
|
*/ |
743
|
|
|
public function fixNamesWithParHash($time, $echo, $cats, $nameStatus, $show): void |
744
|
|
|
{ |
745
|
|
|
$type = 'PAR2 hash, '; |
746
|
|
|
|
747
|
|
|
$this->_echoStartMessage($time, 'PAR2 hash_16K'); |
748
|
|
|
|
749
|
|
|
// Re-check all releases we haven't matched to a PreDB |
750
|
|
|
if ($cats === 3) { |
751
|
|
|
$query = sprintf( |
752
|
|
|
' |
753
|
|
|
SELECT |
754
|
|
|
rel.id AS releases_id, rel.size AS relsize, rel.groups_id, rel.fromname, rel.categories_id, |
755
|
|
|
rel.name, rel.name AS textstring, rel.predb_id, rel.searchname, |
756
|
|
|
IFNULL(ph.hash, "") AS hash |
757
|
|
|
FROM releases rel |
758
|
|
|
LEFT JOIN par_hashes ph ON ph.releases_id = rel.id |
759
|
|
|
WHERE ph.hash != "" |
760
|
|
|
AND rel.nzbstatus = %d |
761
|
|
|
AND rel.predb_id = 0', |
762
|
|
|
NZB::NZB_ADDED |
763
|
|
|
); |
764
|
|
|
$cats = 2; |
765
|
|
|
// Otherwise check only releases we haven't renamed and checked their par2 hash_16K before in Misc categories |
766
|
|
|
} else { |
767
|
|
|
$query = sprintf( |
768
|
|
|
' |
769
|
|
|
SELECT |
770
|
|
|
rel.id AS releases_id, rel.size AS relsize, rel.groups_id, rel.fromname, rel.categories_id, |
771
|
|
|
rel.name, rel.name AS textstring, rel.predb_id, rel.searchname, |
772
|
|
|
IFNULL(ph.hash, "") AS hash |
773
|
|
|
FROM releases rel |
774
|
|
|
LEFT JOIN par_hashes ph ON ph.releases_id = rel.id |
775
|
|
|
WHERE rel.nzbstatus = %d |
776
|
|
|
AND (rel.isrenamed = %d OR rel.categories_id IN (%d, %d)) |
777
|
|
|
AND rel.predb_id = 0 |
778
|
|
|
AND ph.hash != "" |
779
|
|
|
AND rel.proc_hash16k = %d', |
780
|
|
|
NZB::NZB_ADDED, |
781
|
|
|
self::IS_RENAMED_NONE, |
782
|
|
|
Category::OTHER_MISC, |
783
|
|
|
Category::OTHER_HASHED, |
784
|
|
|
self::PROC_HASH16K_NONE |
785
|
|
|
); |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
$releases = $this->_getReleases($time, $cats, $query); |
789
|
|
|
|
790
|
|
|
$total = \count($releases); |
|
|
|
|
791
|
|
|
if ($total > 0) { |
792
|
|
|
$this->_totalReleases = $total; |
793
|
|
|
$this->colorCli->primary(number_format($total).' hash_16K to process.'); |
794
|
|
|
foreach ($releases as $rel) { |
|
|
|
|
795
|
|
|
$this->checked++; |
796
|
|
|
$this->reset(); |
797
|
|
|
$this->hashCheck($rel, $echo, $type, $nameStatus, $show); |
798
|
|
|
$this->_echoRenamed($show); |
799
|
|
|
} |
800
|
|
|
$this->_echoFoundCount($echo, ' hashes'); |
801
|
|
|
} else { |
802
|
|
|
$this->colorCli->info('Nothing to fix.'); |
803
|
|
|
} |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
/** |
807
|
|
|
* @param $time |
808
|
|
|
* @param $cats |
809
|
|
|
* @param $query |
810
|
|
|
* @param string $limit |
811
|
|
|
* |
812
|
|
|
* @return array|false |
813
|
|
|
*/ |
814
|
|
|
protected function _getReleases($time, $cats, $query, $limit = '') |
815
|
|
|
{ |
816
|
|
|
$releases = false; |
817
|
|
|
$queryLimit = ($limit === '') ? '' : ' LIMIT '.$limit; |
818
|
|
|
// 24 hours, other cats |
819
|
|
|
if ($time === 1 && $cats === 1) { |
820
|
|
|
$releases = Release::fromQuery($query.$this->timeother.$queryLimit); |
821
|
|
|
} // 24 hours, all cats |
822
|
|
|
if ($time === 1 && $cats === 2) { |
823
|
|
|
$releases = Release::fromQuery($query.$this->timeall.$queryLimit); |
824
|
|
|
} //other cats |
825
|
|
|
if ($time === 2 && $cats === 1) { |
826
|
|
|
$releases = Release::fromQuery($query.$this->fullother.$queryLimit); |
827
|
|
|
} // all cats |
828
|
|
|
if ($time === 2 && $cats === 2) { |
829
|
|
|
$releases = Release::fromQuery($query.$this->fullall.$queryLimit); |
830
|
|
|
} |
831
|
|
|
|
832
|
|
|
return $releases; |
|
|
|
|
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
/** |
836
|
|
|
* Echo the amount of releases that found a new name. |
837
|
|
|
* |
838
|
|
|
* @param int|bool $echo 1: change the name, anything else: preview of what could have been changed. |
839
|
|
|
* @param string $type The function type that found the name. |
840
|
|
|
*/ |
841
|
|
|
protected function _echoFoundCount($echo, $type): void |
842
|
|
|
{ |
843
|
|
|
if ($echo === true) { |
844
|
|
|
$this->colorCli->header( |
845
|
|
|
PHP_EOL. |
846
|
|
|
number_format($this->fixed). |
847
|
|
|
' releases have had their names changed out of: '. |
848
|
|
|
number_format($this->checked). |
849
|
|
|
$type.'.' |
850
|
|
|
); |
851
|
|
|
} else { |
852
|
|
|
$this->colorCli->header( |
853
|
|
|
PHP_EOL. |
854
|
|
|
number_format($this->fixed). |
855
|
|
|
' releases could have their names changed. '. |
856
|
|
|
number_format($this->checked). |
857
|
|
|
$type.' were checked.' |
858
|
|
|
); |
859
|
|
|
} |
860
|
|
|
} |
861
|
|
|
|
862
|
|
|
/** |
863
|
|
|
* @param int $time 1: 24 hours, 2: no time limit |
864
|
|
|
* @param string $type The function type. |
865
|
|
|
*/ |
866
|
|
|
protected function _echoStartMessage($time, $type): void |
867
|
|
|
{ |
868
|
|
|
$this->colorCli->header( |
869
|
|
|
sprintf( |
870
|
|
|
'Fixing search names %s using %s.', |
871
|
|
|
($time === 1 ? 'in the past 6 hours' : 'since the beginning'), |
872
|
|
|
$type |
873
|
|
|
) |
874
|
|
|
); |
875
|
|
|
} |
876
|
|
|
|
877
|
|
|
/** |
878
|
|
|
* @param int $show |
879
|
|
|
*/ |
880
|
|
|
protected function _echoRenamed($show): void |
881
|
|
|
{ |
882
|
|
|
if ($this->checked % 500 === 0 && $show === 1) { |
883
|
|
|
$this->colorCli->alternate(PHP_EOL.number_format($this->checked).' files processed.'.PHP_EOL); |
884
|
|
|
} |
885
|
|
|
|
886
|
|
|
if ($show === 2) { |
887
|
|
|
$this->consoletools->overWritePrimary( |
888
|
|
|
'Renamed Releases: ['. |
889
|
|
|
number_format($this->fixed). |
890
|
|
|
'] '. |
891
|
|
|
$this->consoletools->percentString($this->checked, $this->_totalReleases) |
892
|
|
|
); |
893
|
|
|
} |
894
|
|
|
} |
895
|
|
|
|
896
|
|
|
/** |
897
|
|
|
* Update the release with the new information. |
898
|
|
|
* |
899
|
|
|
* |
900
|
|
|
* @param $release |
901
|
|
|
* @param $name |
902
|
|
|
* @param $method |
903
|
|
|
* @param $echo |
904
|
|
|
* @param $type |
905
|
|
|
* @param int $nameStatus |
906
|
|
|
* @param bool $show |
907
|
|
|
* @param int $preId |
908
|
|
|
* |
909
|
|
|
* @throws \Exception |
910
|
|
|
*/ |
911
|
|
|
public function updateRelease($release, $name, $method, $echo, $type, int $nameStatus, bool $show, int $preId = 0): void |
912
|
|
|
{ |
913
|
|
|
if (\is_array($release)) { |
914
|
|
|
$release = (object) $release; |
915
|
|
|
} |
916
|
|
|
if ($this->relid !== $release->releases_id) { |
917
|
|
|
$newName = (new ReleaseCleaning())->fixerCleaner($name); |
918
|
|
|
if (strtolower($newName) !== strtolower($release->searchname)) { |
919
|
|
|
$this->matched = true; |
920
|
|
|
$this->relid = (int) $release->releases_id; |
921
|
|
|
|
922
|
|
|
$determinedCategory = $this->category->determineCategory($release->groups_id, $newName, ! empty($release->fromname) ? $release->fromname : ''); |
923
|
|
|
|
924
|
|
|
if ($type === 'PAR2, ') { |
925
|
|
|
$newName = ucwords($newName); |
926
|
|
|
if (preg_match('/(.+?)\.[a-z0-9]{2,3}(PAR2)?$/i', $name, $match)) { |
927
|
|
|
$newName = $match[1]; |
928
|
|
|
} |
929
|
|
|
} |
930
|
|
|
|
931
|
|
|
$this->fixed++; |
932
|
|
|
|
933
|
|
|
$newName = explode('\\', $newName); |
934
|
|
|
$newName = preg_replace(['/^[-=_\.:\s]+/', '/[-=_\.:\s]+$/'], '', $newName[0]); |
935
|
|
|
|
936
|
|
|
if ($this->echooutput && $show) { |
937
|
|
|
$groupName = Group::getNameByID($release->groups_id); |
938
|
|
|
$oldCatName = Category::getNameByID($release->categories_id); |
939
|
|
|
$newCatName = Category::getNameByID($determinedCategory['categories_id']); |
940
|
|
|
|
941
|
|
|
if ($type === 'PAR2, ') { |
942
|
|
|
echo PHP_EOL; |
943
|
|
|
} |
944
|
|
|
|
945
|
|
|
echo PHP_EOL; |
946
|
|
|
|
947
|
|
|
$this->colorCli->headerOver('New name: '). |
|
|
|
|
948
|
|
|
$this->colorCli->primary(substr($newName, 0, 299)). |
|
|
|
|
949
|
|
|
$this->colorCli->headerOver('Old name: '). |
|
|
|
|
950
|
|
|
$this->colorCli->primary($release->searchname). |
|
|
|
|
951
|
|
|
$this->colorCli->headerOver('Use name: '). |
|
|
|
|
952
|
|
|
$this->colorCli->primary($release->name). |
|
|
|
|
953
|
|
|
$this->colorCli->headerOver('New cat: '). |
|
|
|
|
954
|
|
|
$this->colorCli->primary($newCatName). |
|
|
|
|
955
|
|
|
$this->colorCli->headerOver('Old cat: '). |
|
|
|
|
956
|
|
|
$this->colorCli->primary($oldCatName). |
|
|
|
|
957
|
|
|
$this->colorCli->headerOver('Group: '). |
|
|
|
|
958
|
|
|
$this->colorCli->primary($groupName). |
|
|
|
|
959
|
|
|
$this->colorCli->headerOver('Method: '). |
|
|
|
|
960
|
|
|
$this->colorCli->primary($type.$method). |
|
|
|
|
961
|
|
|
$this->colorCli->headerOver('Releases ID: '). |
|
|
|
|
962
|
|
|
$this->colorCli->primary($release->releases_id); |
|
|
|
|
963
|
|
|
if (! empty($release->filename)) { |
964
|
|
|
$this->colorCli->headerOver('Filename: '). |
|
|
|
|
965
|
|
|
$this->colorCli->primary($release->filename); |
|
|
|
|
966
|
|
|
} |
967
|
|
|
|
968
|
|
|
if ($type !== 'PAR2, ') { |
969
|
|
|
echo PHP_EOL; |
970
|
|
|
} |
971
|
|
|
} |
972
|
|
|
|
973
|
|
|
$newTitle = substr($newName, 0, 299); |
974
|
|
|
$taggedRelease = Release::find($release->releases_id); |
975
|
|
|
|
976
|
|
|
if ($echo === true) { |
977
|
|
|
if ($nameStatus === 1) { |
978
|
|
|
$status = ''; |
979
|
|
|
switch ($type) { |
980
|
|
|
case 'NFO, ': |
981
|
|
|
$status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_nfo' => 1]; |
982
|
|
|
break; |
983
|
|
|
case 'PAR2, ': |
984
|
|
|
$status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_par2' => 1]; |
985
|
|
|
break; |
986
|
|
|
case 'Filenames, ': |
987
|
|
|
case 'file matched source: ': |
988
|
|
|
$status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_files' => 1]; |
989
|
|
|
break; |
990
|
|
|
case 'SHA1, ': |
991
|
|
|
case 'MD5, ': |
992
|
|
|
$status = ['isrenamed' => 1, 'iscategorized' => 1, 'dehashstatus' => 1]; |
993
|
|
|
break; |
994
|
|
|
case 'PreDB FT Exact, ': |
995
|
|
|
$status = ['isrenamed' => 1, 'iscategorized' => 1]; |
996
|
|
|
break; |
997
|
|
|
case 'sorter, ': |
998
|
|
|
$status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_sorter' => 1]; |
999
|
|
|
break; |
1000
|
|
|
case 'UID, ': |
1001
|
|
|
case 'Mediainfo, ': |
1002
|
|
|
$status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_uid' => 1]; |
1003
|
|
|
break; |
1004
|
|
|
case 'PAR2 hash, ': |
1005
|
|
|
$status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_hash16k' => 1]; |
1006
|
|
|
break; |
1007
|
|
|
case 'SRR, ': |
1008
|
|
|
$status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_srr' => 1]; |
1009
|
|
|
break; |
1010
|
|
|
case 'CRC32, ': |
1011
|
|
|
$status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_crc32' => 1]; |
1012
|
|
|
break; |
1013
|
|
|
} |
1014
|
|
|
|
1015
|
|
|
$updateColumns = [ |
1016
|
|
|
'videos_id' => 0, |
1017
|
|
|
'tv_episodes_id' => 0, |
1018
|
|
|
'imdbid' => null, |
1019
|
|
|
'musicinfo_id' => null, |
1020
|
|
|
'consoleinfo_id' => null, |
1021
|
|
|
'bookinfo_id' => null, |
1022
|
|
|
'anidbid' => null, |
1023
|
|
|
'predb_id' => $preId, |
1024
|
|
|
'searchname' => $newTitle, |
1025
|
|
|
'categories_id' => $determinedCategory['categories_id'], |
1026
|
|
|
]; |
1027
|
|
|
|
1028
|
|
|
if ($status !== '') { |
1029
|
|
|
foreach ($status as $key => $stat) { |
1030
|
|
|
$updateColumns = Arr::add($updateColumns, $key, $stat); |
1031
|
|
|
} |
1032
|
|
|
} |
1033
|
|
|
|
1034
|
|
|
$taggedRelease->update($updateColumns); |
1035
|
|
|
$taggedRelease->retag($determinedCategory['tags']); |
1036
|
|
|
$this->sphinx->updateRelease($release->releases_id); |
1037
|
|
|
} else { |
1038
|
|
|
$newTitle = substr($newName, 0, 299); |
1039
|
|
|
|
1040
|
|
|
$release->update( |
1041
|
|
|
[ |
1042
|
|
|
'videos_id' => 0, |
1043
|
|
|
'tv_episodes_id' => 0, |
1044
|
|
|
'imdbid' => null, |
1045
|
|
|
'musicinfo_id' => null, |
1046
|
|
|
'consoleinfo_id' => null, |
1047
|
|
|
'bookinfo_id' => null, |
1048
|
|
|
'anidbid' => null, |
1049
|
|
|
'predb_id' => $preId, |
1050
|
|
|
'searchname' => $newTitle, |
1051
|
|
|
'categories_id' => $determinedCategory['categories_id'], |
1052
|
|
|
'iscategorized' => 1, |
1053
|
|
|
] |
1054
|
|
|
); |
1055
|
|
|
$taggedRelease->retag($determinedCategory['tags']); |
1056
|
|
|
$this->sphinx->updateRelease($release->releases_id); |
1057
|
|
|
} |
1058
|
|
|
} |
1059
|
|
|
} |
1060
|
|
|
} |
1061
|
|
|
$this->done = true; |
1062
|
|
|
} |
1063
|
|
|
|
1064
|
|
|
/** |
1065
|
|
|
* Echo a updated release name to CLI. |
1066
|
|
|
* |
1067
|
|
|
* @param array $data |
1068
|
|
|
* array( |
1069
|
|
|
* 'new_name' => (string) The new release search name. |
1070
|
|
|
* 'old_name' => (string) The old release search name. |
1071
|
|
|
* 'new_category' => (string) The new category name or ID for the release. |
1072
|
|
|
* 'old_category' => (string) The old category name or ID for the release. |
1073
|
|
|
* 'group' => (string) The group name or ID of the release. |
1074
|
|
|
* 'release_id' => (int) The ID of the release. |
1075
|
|
|
* 'method' => (string) The method used to rename the release. |
1076
|
|
|
* ) |
1077
|
|
|
* |
1078
|
|
|
* @static |
1079
|
|
|
* @void |
1080
|
|
|
*/ |
1081
|
|
|
public static function echoChangedReleaseName( |
1082
|
|
|
array $data = |
1083
|
|
|
[ |
1084
|
|
|
'new_name' => '', |
1085
|
|
|
'old_name' => '', |
1086
|
|
|
'new_category' => '', |
1087
|
|
|
'old_category' => '', |
1088
|
|
|
'group' => '', |
1089
|
|
|
'releases_id' => 0, |
1090
|
|
|
'method' => '', |
1091
|
|
|
] |
1092
|
|
|
): void { |
1093
|
|
|
$colorCLI = new ColorCLI(); |
1094
|
|
|
echo PHP_EOL; |
1095
|
|
|
|
1096
|
|
|
$colorCLI->headerOver('New name: ').$colorCLI->primaryOver($data['new_name']). |
|
|
|
|
1097
|
|
|
$colorCLI->headerOver('Old name: ').$colorCLI->primaryOver($data['old_name']). |
|
|
|
|
1098
|
|
|
$colorCLI->headerOver('New category: ').$colorCLI->primaryOver($data['new_category']). |
|
|
|
|
1099
|
|
|
$colorCLI->headerOver('Old category: ').$colorCLI->primaryOver($data['old_category']). |
|
|
|
|
1100
|
|
|
$colorCLI->headerOver('Group: ').$colorCLI->primaryOver($data['group']). |
|
|
|
|
1101
|
|
|
$colorCLI->headerOver('Releases ID: ').$colorCLI->primaryOver($data['releases_id']). |
|
|
|
|
1102
|
|
|
$colorCLI->headerOver('Method: ').$colorCLI->primaryOver($data['method']); |
|
|
|
|
1103
|
|
|
} |
1104
|
|
|
|
1105
|
|
|
/** |
1106
|
|
|
* Match a PreDB title to a release name or searchname using an exact full-text match. |
1107
|
|
|
* |
1108
|
|
|
* @param $pre |
1109
|
|
|
* @param $echo |
1110
|
|
|
* @param $nameStatus |
1111
|
|
|
* @param $show |
1112
|
|
|
* |
1113
|
|
|
* @return int |
1114
|
|
|
* @throws \Exception |
1115
|
|
|
*/ |
1116
|
|
|
public function matchPredbFT($pre, $echo, $nameStatus, $show): int |
1117
|
|
|
{ |
1118
|
|
|
$matching = $total = 0; |
1119
|
|
|
|
1120
|
|
|
$join = $this->_preFTsearchQuery($pre['title']); |
1121
|
|
|
|
1122
|
|
|
if ($join === '') { |
1123
|
|
|
return $matching; |
1124
|
|
|
} |
1125
|
|
|
|
1126
|
|
|
//Find release matches with fulltext and then identify exact matches with cleaned LIKE string |
1127
|
|
|
$res = Release::fromQuery( |
1128
|
|
|
sprintf( |
1129
|
|
|
' |
1130
|
|
|
SELECT r.id AS releases_id, r.name, r.searchname, |
1131
|
|
|
r.fromname, r.groups_id, r.categories_id |
1132
|
|
|
FROM releases r |
1133
|
|
|
WHERE r.id IN (%s) |
1134
|
|
|
AND r.predb_id = 0', |
1135
|
|
|
$join |
1136
|
|
|
) |
1137
|
|
|
); |
1138
|
|
|
|
1139
|
|
|
if (! empty($res)) { |
1140
|
|
|
$total = \count($res); |
1141
|
|
|
} |
1142
|
|
|
|
1143
|
|
|
// Run if row count is positive, but do not run if row count exceeds 10 (as this is likely a failed title match) |
1144
|
|
|
if ($total > 0 && $total <= 15) { |
1145
|
|
|
foreach ($res as $row) { |
1146
|
|
|
if ($pre['title'] !== $row->searchname) { |
1147
|
|
|
$this->updateRelease($row, $pre['title'], 'Title Match source: '.$pre['source'], $echo, 'PreDB FT Exact, ', $nameStatus, $show, $pre['predb_id']); |
1148
|
|
|
$matching++; |
1149
|
|
|
} else { |
1150
|
|
|
$this->_updateSingleColumn('predb_id', $pre['predb_id'], $row->releases_id); |
|
|
|
|
1151
|
|
|
} |
1152
|
|
|
} |
1153
|
|
|
} elseif ($total >= 16) { |
1154
|
|
|
$matching = -1; |
1155
|
|
|
} |
1156
|
|
|
|
1157
|
|
|
return $matching; |
1158
|
|
|
} |
1159
|
|
|
|
1160
|
|
|
/** |
1161
|
|
|
* @param $preTitle |
1162
|
|
|
* |
1163
|
|
|
* @return string |
1164
|
|
|
*/ |
1165
|
|
|
protected function _preFTsearchQuery($preTitle): string |
1166
|
|
|
{ |
1167
|
|
|
$join = ''; |
1168
|
|
|
|
1169
|
|
|
if (\strlen($preTitle) >= 15 && preg_match(self::PREDB_REGEX, $preTitle)) { |
1170
|
|
|
$titlematch = $this->sphinx->searchIndexes('releases_rt', $preTitle, ['name', 'searchname', 'filename']); |
1171
|
|
|
if (! empty($titlematch)) { |
1172
|
|
|
$join = implode(',', Arr::pluck($titlematch, 'id')); |
1173
|
|
|
} |
1174
|
|
|
} |
1175
|
|
|
|
1176
|
|
|
return $join; |
1177
|
|
|
} |
1178
|
|
|
|
1179
|
|
|
/** |
1180
|
|
|
* Retrieves releases and their file names to attempt PreDB matches |
1181
|
|
|
* Runs in a limited mode based on arguments passed or a full mode broken into chunks of entire DB. |
1182
|
|
|
* |
1183
|
|
|
* @param array $args The CLI script arguments |
1184
|
|
|
* @throws \Exception |
1185
|
|
|
*/ |
1186
|
|
|
public function getPreFileNames(array $args = []): void |
1187
|
|
|
{ |
1188
|
|
|
$show = isset($args[2]) && $args[2] === 'show'; |
1189
|
|
|
|
1190
|
|
|
if (isset($args[1]) && is_numeric($args[1])) { |
1191
|
|
|
$limit = 'LIMIT '.$args[1]; |
1192
|
|
|
$orderby = 'ORDER BY r.id DESC'; |
1193
|
|
|
} else { |
1194
|
|
|
$orderby = 'ORDER BY r.id ASC'; |
1195
|
|
|
$limit = 'LIMIT 1000000'; |
1196
|
|
|
} |
1197
|
|
|
|
1198
|
|
|
$this->colorCli->header(PHP_EOL.'Match PreFiles '.$args[1].' Started at '.now()); |
1199
|
|
|
$this->colorCli->primary('Matching predb filename to cleaned release_files.name.'); |
1200
|
|
|
|
1201
|
|
|
$counter = $counted = 0; |
1202
|
|
|
$timestart = now(); |
1203
|
|
|
|
1204
|
|
|
$query = Release::fromQuery( |
1205
|
|
|
sprintf( |
1206
|
|
|
" |
1207
|
|
|
SELECT r.id AS releases_id, r.name, r.searchname, |
1208
|
|
|
r.fromname, r.groups_id, r.categories_id, |
1209
|
|
|
GROUP_CONCAT(rf.name ORDER BY LENGTH(rf.name) DESC SEPARATOR '||') AS filename |
1210
|
|
|
FROM releases r |
1211
|
|
|
INNER JOIN release_files rf ON r.id = rf.releases_id |
1212
|
|
|
WHERE rf.name IS NOT NULL |
1213
|
|
|
AND r.predb_id = 0 |
1214
|
|
|
AND r.categories_id IN (%s) |
1215
|
|
|
AND r.isrenamed = 0 |
1216
|
|
|
GROUP BY r.id |
1217
|
|
|
%s %s", |
1218
|
|
|
implode(',', Category::OTHERS_GROUP), |
1219
|
|
|
$orderby, |
1220
|
|
|
$limit |
1221
|
|
|
) |
1222
|
|
|
); |
1223
|
|
|
|
1224
|
|
|
if (! empty($query)) { |
1225
|
|
|
$total = \count($query); |
1226
|
|
|
|
1227
|
|
|
if ($total > 0) { |
1228
|
|
|
$this->colorCli->header(PHP_EOL.number_format($total).' releases to process.'); |
1229
|
|
|
|
1230
|
|
|
foreach ($query as $row) { |
1231
|
|
|
$success = $this->matchPreDbFiles($row, true, 1, $show); |
1232
|
|
|
if ($success === 1) { |
1233
|
|
|
$counted++; |
1234
|
|
|
} |
1235
|
|
|
if ($show === 0) { |
1236
|
|
|
$this->consoletools->overWritePrimary('Renamed Releases: ['.number_format($counted).'] '.$this->consoletools->percentString(++$counter, $total)); |
1237
|
|
|
} |
1238
|
|
|
} |
1239
|
|
|
$this->colorCli->header(PHP_EOL.'Renamed '.number_format($counted).' releases in '.now()->diffInSeconds($timestart).' seconds'.'.'); |
1240
|
|
|
} else { |
1241
|
|
|
$this->colorCli->info('Nothing to do.'); |
1242
|
|
|
} |
1243
|
|
|
} |
1244
|
|
|
} |
1245
|
|
|
|
1246
|
|
|
/** |
1247
|
|
|
* Match a release filename to a PreDB filename or title. |
1248
|
|
|
* |
1249
|
|
|
* @param $release |
1250
|
|
|
* @param bool $echo |
1251
|
|
|
* @param int $nameStatus |
1252
|
|
|
* @param bool $show |
1253
|
|
|
* |
1254
|
|
|
* @return int |
1255
|
|
|
* @throws \Exception |
1256
|
|
|
*/ |
1257
|
|
|
public function matchPreDbFiles($release, $echo, $nameStatus, $show): int |
1258
|
|
|
{ |
1259
|
|
|
$matching = 0; |
1260
|
|
|
|
1261
|
|
|
foreach (explode('||', $release->filename) as $key => $fileName) { |
1262
|
|
|
$this->_fileName = $fileName; |
1263
|
|
|
$this->_cleanMatchFiles(); |
1264
|
|
|
$preMatch = $this->preMatch($this->_fileName); |
1265
|
|
|
if ($preMatch[0] === true) { |
1266
|
|
|
$results = $this->sphinx->searchIndexes('predb_rt', $preMatch[1], ['filename', 'title']); |
1267
|
|
|
if (! empty($results)) { |
1268
|
|
|
foreach ($results as $result) { |
1269
|
|
|
if (! empty($result)) { |
1270
|
|
|
$preFtMatch = $this->preMatch($result['filename']); |
1271
|
|
|
if ($preFtMatch[0] === true) { |
1272
|
|
|
$this->_fileName = $result['filename']; |
1273
|
|
|
$release->filename = $this->_fileName; |
1274
|
|
|
if ($result['title'] !== $release->searchname) { |
1275
|
|
|
$this->updateRelease($release, $result['title'], 'file matched source: '.$result['source'], $echo, 'PreDB file match, ', $nameStatus, $show, $result['id']); |
1276
|
|
|
} else { |
1277
|
|
|
$this->_updateSingleColumn('predb_id', $result['id'], $release->releases_id); |
1278
|
|
|
} |
1279
|
|
|
$matching++; |
1280
|
|
|
break; |
1281
|
|
|
} |
1282
|
|
|
} |
1283
|
|
|
} |
1284
|
|
|
} |
1285
|
|
|
} |
1286
|
|
|
} |
1287
|
|
|
|
1288
|
|
|
return $matching; |
1289
|
|
|
} |
1290
|
|
|
|
1291
|
|
|
/** |
1292
|
|
|
* Cleans file names for PreDB Match. |
1293
|
|
|
* |
1294
|
|
|
* |
1295
|
|
|
* @return string |
1296
|
|
|
*/ |
1297
|
|
|
protected function _cleanMatchFiles(): string |
1298
|
|
|
{ |
1299
|
|
|
|
1300
|
|
|
// first strip all non-printing chars from filename |
1301
|
|
|
$this->_fileName = Utility::stripNonPrintingChars($this->_fileName); |
1302
|
|
|
|
1303
|
|
|
if ($this->_fileName !== '' && strpos($this->_fileName, '.') !== 0) { |
1304
|
|
|
switch (true) { |
|
|
|
|
1305
|
|
|
|
1306
|
|
|
case strpos($this->_fileName, '.') !== false: |
1307
|
|
|
//some filenames start with a period that ends up creating bad matches so we don't process them |
1308
|
|
|
$this->_fileName = Utility::cutStringUsingLast('.', $this->_fileName, 'left', false); |
1309
|
|
|
break; |
1310
|
|
|
|
1311
|
|
|
//if filename has a .part001, send it back to the function to cut the next period |
1312
|
|
|
case preg_match('/\.part\d+$/', $this->_fileName): |
1313
|
|
|
$this->_fileName = Utility::cutStringUsingLast('.', $this->_fileName, 'left', false); |
1314
|
|
|
break; |
1315
|
|
|
|
1316
|
|
|
//if filename has a .vol001, send it back to the function to cut the next period |
1317
|
|
|
case preg_match('/\.vol\d+(\+\d+)?$/', $this->_fileName): |
1318
|
|
|
$this->_fileName = Utility::cutStringUsingLast('.', $this->_fileName, 'left', false); |
1319
|
|
|
break; |
1320
|
|
|
|
1321
|
|
|
//if filename contains a slash, cut the string and keep string to the right of the last slash to remove dir |
1322
|
|
|
case strpos($this->_fileName, '\\') !== false: |
1323
|
|
|
$this->_fileName = Utility::cutStringUsingLast('\\', $this->_fileName, 'right', false); |
1324
|
|
|
break; |
1325
|
|
|
|
1326
|
|
|
// A lot of obscured releases have one NFO file properly named with a track number (Audio) at the front of it |
1327
|
|
|
// This will strip out the track and match it to its pre title |
1328
|
|
|
case preg_match('/^\d{2}-/', $this->_fileName): |
1329
|
|
|
$this->_fileName = preg_replace('/^\d{2}-/', '', $this->_fileName); |
1330
|
|
|
} |
1331
|
|
|
|
1332
|
|
|
return trim($this->_fileName); |
1333
|
|
|
} |
1334
|
|
|
|
1335
|
|
|
return false; |
|
|
|
|
1336
|
|
|
} |
1337
|
|
|
|
1338
|
|
|
/** |
1339
|
|
|
* Match a Hash from the predb to a release. |
1340
|
|
|
* |
1341
|
|
|
* @param string $hash |
1342
|
|
|
* @param $release |
1343
|
|
|
* @param $echo |
1344
|
|
|
* @param $nameStatus |
1345
|
|
|
* @param $show |
1346
|
|
|
* |
1347
|
|
|
* @return int |
1348
|
|
|
* @throws \Exception |
1349
|
|
|
*/ |
1350
|
|
|
public function matchPredbHash($hash, $release, $echo, $nameStatus, $show): int |
1351
|
|
|
{ |
1352
|
|
|
$matching = 0; |
1353
|
|
|
$this->matched = false; |
1354
|
|
|
|
1355
|
|
|
// Determine MD5 or SHA1 |
1356
|
|
|
if (\strlen($hash) === 40) { |
1357
|
|
|
$hashtype = 'SHA1, '; |
1358
|
|
|
} else { |
1359
|
|
|
$hashtype = 'MD5, '; |
1360
|
|
|
} |
1361
|
|
|
|
1362
|
|
|
$row = Predb::fromQuery( |
1363
|
|
|
sprintf( |
1364
|
|
|
' |
1365
|
|
|
SELECT p.id AS predb_id, p.title, p.source |
1366
|
|
|
FROM predb p INNER JOIN predb_hashes h ON h.predb_id = p.id |
1367
|
|
|
WHERE h.hash = UNHEX(%s) |
1368
|
|
|
LIMIT 1', |
1369
|
|
|
escapeString($hash) |
1370
|
|
|
) |
1371
|
|
|
); |
1372
|
|
|
|
1373
|
|
|
foreach ($row as $item) { |
1374
|
|
|
if (! empty($item)) { |
1375
|
|
|
if ($item->title !== $release->searchname) { |
1376
|
|
|
$this->updateRelease($release, $item->title, 'predb hash release name: '.$item->source, $echo, $hashtype, $nameStatus, $show, $item->predb_id); |
|
|
|
|
1377
|
|
|
$matching++; |
1378
|
|
|
} |
1379
|
|
|
} else { |
1380
|
|
|
$this->_updateSingleColumn('dehashstatus', $release->dehashstatus - 1, $release->releases_id); |
1381
|
|
|
} |
1382
|
|
|
} |
1383
|
|
|
|
1384
|
|
|
return $matching; |
1385
|
|
|
} |
1386
|
|
|
|
1387
|
|
|
/** |
1388
|
|
|
* Matches the hashes within the predb table to release files and subjects (names) which are hashed. |
1389
|
|
|
* |
1390
|
|
|
* @param $time |
1391
|
|
|
* @param $echo |
1392
|
|
|
* @param $cats |
1393
|
|
|
* @param $nameStatus |
1394
|
|
|
* @param $show |
1395
|
|
|
* |
1396
|
|
|
* @return int |
1397
|
|
|
* @throws \Exception |
1398
|
|
|
*/ |
1399
|
|
|
public function parseTitles($time, $echo, $cats, $nameStatus, $show): int |
1400
|
|
|
{ |
1401
|
|
|
$updated = $checked = 0; |
1402
|
|
|
|
1403
|
|
|
$tq = ''; |
1404
|
|
|
if ($time === 1) { |
1405
|
|
|
$tq = 'AND r.adddate > (NOW() - INTERVAL 3 HOUR) ORDER BY rf.releases_id, rf.size DESC'; |
1406
|
|
|
} |
1407
|
|
|
$ct = ''; |
1408
|
|
|
if ($cats === 1) { |
1409
|
|
|
$ct = sprintf('AND r.categories_id IN (%s)', $this->othercats); |
1410
|
|
|
} |
1411
|
|
|
|
1412
|
|
|
if ($this->echooutput) { |
1413
|
|
|
$te = ''; |
1414
|
|
|
if ($time === 1) { |
1415
|
|
|
$te = ' in the past 3 hours'; |
1416
|
|
|
} |
1417
|
|
|
$this->colorCli->header('Fixing search names'.$te.' using the predb hash.'); |
1418
|
|
|
} |
1419
|
|
|
$regex = 'AND (r.ishashed = 1 OR rf.ishashed = 1)'; |
1420
|
|
|
|
1421
|
|
|
if ($cats === 3) { |
1422
|
|
|
$query = sprintf('SELECT r.id AS releases_id, r.name, r.searchname, r.categories_id, r.groups_id, ' |
1423
|
|
|
.'dehashstatus, rf.name AS filename FROM releases r ' |
1424
|
|
|
.'LEFT OUTER JOIN release_files rf ON r.id = rf.releases_id ' |
1425
|
|
|
.'WHERE nzbstatus = 1 AND dehashstatus BETWEEN -6 AND 0 AND predb_id = 0 %s', $regex); |
1426
|
|
|
} else { |
1427
|
|
|
$query = sprintf('SELECT r.id AS releases_id, r.name, r.searchname, r.categories_id, r.groups_id, ' |
1428
|
|
|
.'dehashstatus, rf.name AS filename FROM releases r ' |
1429
|
|
|
.'LEFT OUTER JOIN release_files rf ON r.id = rf.releases_id ' |
1430
|
|
|
.'WHERE nzbstatus = 1 AND isrenamed = 0 AND dehashstatus BETWEEN -6 AND 0 %s %s %s', $regex, $ct, $tq); |
1431
|
|
|
} |
1432
|
|
|
|
1433
|
|
|
$res = Release::fromQuery($query); |
1434
|
|
|
$total = \count($res); |
1435
|
|
|
$this->colorCli->primary(number_format($total).' releases to process.'); |
1436
|
|
|
foreach ($res as $row) { |
1437
|
|
|
if (preg_match('/[a-fA-F0-9]{32,40}/i', $row->name, $matches)) { |
1438
|
|
|
$updated += $this->matchPredbHash($matches[0], $row, $echo, $nameStatus, $show); |
1439
|
|
|
} elseif (preg_match('/[a-fA-F0-9]{32,40}/i', $row->filename, $matches)) { |
|
|
|
|
1440
|
|
|
$updated += $this->matchPredbHash($matches[0], $row, $echo, $nameStatus, $show); |
1441
|
|
|
} |
1442
|
|
|
if ($show === 2) { |
1443
|
|
|
$this->colorCli->overWritePrimary('Renamed Releases: ['.number_format($updated).'] '.$this->consoletools->percentString($checked++, $total)); |
|
|
|
|
1444
|
|
|
} |
1445
|
|
|
} |
1446
|
|
|
if ($echo === 1) { |
1447
|
|
|
$this->colorCli->header(PHP_EOL.$updated.' releases have had their names changed out of: '.number_format($checked).' files.'); |
1448
|
|
|
} else { |
1449
|
|
|
$this->colorCli->header(PHP_EOL.$updated.' releases could have their names changed. '.number_format($checked).' files were checked.'); |
1450
|
|
|
} |
1451
|
|
|
|
1452
|
|
|
return $updated; |
1453
|
|
|
} |
1454
|
|
|
|
1455
|
|
|
/** |
1456
|
|
|
* Check the array using regex for a clean name. |
1457
|
|
|
* |
1458
|
|
|
* @param $release |
1459
|
|
|
* @param bool $echo |
1460
|
|
|
* @param string $type |
1461
|
|
|
* @param int $nameStatus |
1462
|
|
|
* @param bool $show |
1463
|
|
|
* @param bool $preid |
1464
|
|
|
* |
1465
|
|
|
* @return bool |
1466
|
|
|
* @throws \Exception |
1467
|
|
|
*/ |
1468
|
|
|
public function checkName($release, $echo, $type, $nameStatus, $show, $preid = false): bool |
1469
|
|
|
{ |
1470
|
|
|
// Get pre style name from releases.name |
1471
|
|
|
if (preg_match_all(self::PREDB_REGEX, $release->textstring, $matches) && ! preg_match('/Source\s\:/i', $release->textstring)) { |
1472
|
|
|
foreach ($matches as $match) { |
1473
|
|
|
foreach ($match as $val) { |
1474
|
|
|
$title = Predb::query()->where('title', trim($val))->select(['title', 'id'])->first(); |
1475
|
|
|
if ($title !== null) { |
1476
|
|
|
$this->updateRelease($release, $title['title'], 'preDB: Match', $echo, $type, $nameStatus, $show, $title['id']); |
1477
|
|
|
$preid = true; |
1478
|
|
|
} |
1479
|
|
|
} |
1480
|
|
|
} |
1481
|
|
|
} |
1482
|
|
|
|
1483
|
|
|
// if only processing for PreDB match skip to return |
1484
|
|
|
if (! $preid) { |
1485
|
|
|
switch ($type) { |
1486
|
|
|
case 'PAR2, ': |
1487
|
|
|
$this->fileCheck($release, $echo, $type, $nameStatus, $show); |
1488
|
|
|
break; |
1489
|
|
|
case 'PAR2 hash, ': |
1490
|
|
|
$this->hashCheck($release, $echo, $type, $nameStatus, $show); |
1491
|
|
|
break; |
1492
|
|
|
case 'UID, ': |
1493
|
|
|
$this->uidCheck($release, $echo, $type, $nameStatus, $show); |
1494
|
|
|
break; |
1495
|
|
|
case 'Mediainfo, ': |
1496
|
|
|
$this->mediaMovieNameCheck($release, $echo, $type, $nameStatus, $show); |
1497
|
|
|
break; |
1498
|
|
|
case 'SRR, ': |
1499
|
|
|
$this->srrNameCheck($release, $echo, $type, $nameStatus, $show); |
1500
|
|
|
break; |
1501
|
|
|
case 'CRC32, ': |
1502
|
|
|
$this->crcCheck($release, $echo, $type, $nameStatus, $show); |
1503
|
|
|
break; |
1504
|
|
|
case 'NFO, ': |
1505
|
|
|
$this->nfoCheckTV($release, $echo, $type, $nameStatus, $show); |
1506
|
|
|
$this->nfoCheckMov($release, $echo, $type, $nameStatus, $show); |
1507
|
|
|
$this->nfoCheckMus($release, $echo, $type, $nameStatus, $show); |
1508
|
|
|
$this->nfoCheckTY($release, $echo, $type, $nameStatus, $show); |
1509
|
|
|
$this->nfoCheckG($release, $echo, $type, $nameStatus, $show); |
1510
|
|
|
break; |
1511
|
|
|
case 'Filenames, ': |
1512
|
|
|
$this->preDbFileCheck($release, $echo, $type, $nameStatus, $show); |
1513
|
|
|
$this->preDbTitleCheck($release, $echo, $type, $nameStatus, $show); |
1514
|
|
|
$this->fileCheck($release, $echo, $type, $nameStatus, $show); |
1515
|
|
|
break; |
1516
|
|
|
default: |
1517
|
|
|
$this->tvCheck($release, $echo, $type, $nameStatus, $show); |
1518
|
|
|
$this->movieCheck($release, $echo, $type, $nameStatus, $show); |
1519
|
|
|
$this->gameCheck($release, $echo, $type, $nameStatus, $show); |
1520
|
|
|
$this->appCheck($release, $echo, $type, $nameStatus, $show); |
1521
|
|
|
} |
1522
|
|
|
|
1523
|
|
|
// set NameFixer process flags after run |
1524
|
|
|
if ($nameStatus === 1 && ! $this->matched) { |
1525
|
|
|
switch ($type) { |
1526
|
|
|
case 'NFO, ': |
1527
|
|
|
$this->_updateSingleColumn('proc_nfo', self::PROC_NFO_DONE, $release->releases_id); |
1528
|
|
|
break; |
1529
|
|
|
case 'Filenames, ': |
1530
|
|
|
$this->_updateSingleColumn('proc_files', self::PROC_FILES_DONE, $release->releases_id); |
1531
|
|
|
break; |
1532
|
|
|
case 'PAR2, ': |
1533
|
|
|
$this->_updateSingleColumn('proc_par2', self::PROC_PAR2_DONE, $release->releases_id); |
1534
|
|
|
break; |
1535
|
|
|
case 'PAR2 hash, ': |
1536
|
|
|
$this->_updateSingleColumn('proc_hash16k', self::PROC_HASH16K_DONE, $release->releases_id); |
1537
|
|
|
break; |
1538
|
|
|
case 'SRR, ': |
1539
|
|
|
$this->_updateSingleColumn('proc_srr', self::PROC_SRR_DONE, $release->releases_id); |
1540
|
|
|
break; |
1541
|
|
|
case 'UID, ': |
1542
|
|
|
$this->_updateSingleColumn('proc_uid', self::PROC_UID_DONE, $release->releases_id); |
1543
|
|
|
break; |
1544
|
|
|
} |
1545
|
|
|
} |
1546
|
|
|
} |
1547
|
|
|
|
1548
|
|
|
return $this->matched; |
1549
|
|
|
} |
1550
|
|
|
|
1551
|
|
|
/** This function updates a single variable column in releases |
1552
|
|
|
* The first parameter is the column to update, the second is the value |
1553
|
|
|
* The final parameter is the ID of the release to update. |
1554
|
|
|
* |
1555
|
|
|
* @param string $column |
1556
|
|
|
* @param int $status |
1557
|
|
|
* @param int $id |
1558
|
|
|
*/ |
1559
|
|
|
public function _updateSingleColumn($column = '', $status = 0, $id = 0): void |
1560
|
|
|
{ |
1561
|
|
|
if ((string) $column !== '' && (int) $id !== 0) { |
1562
|
|
|
Release::query()->where('id', $id)->update([$column => $status]); |
1563
|
|
|
} |
1564
|
|
|
} |
1565
|
|
|
|
1566
|
|
|
/** |
1567
|
|
|
* Look for a TV name. |
1568
|
|
|
* |
1569
|
|
|
* @param $release |
1570
|
|
|
* @param bool $echo |
1571
|
|
|
* @param string $type |
1572
|
|
|
* @param $nameStatus |
1573
|
|
|
* @param $show |
1574
|
|
|
* @throws \Exception |
1575
|
|
|
*/ |
1576
|
|
|
public function tvCheck($release, $echo, $type, $nameStatus, $show): void |
1577
|
|
|
{ |
1578
|
|
|
$result = []; |
1579
|
|
|
|
1580
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
1581
|
|
|
if (preg_match('/\w[-\w.\',;& ]+((s\d{1,2}[._ -]?[bde]\d{1,2})|(?<!\d)[S|]\d{1,2}[E|x]\d{1,}(?!\d)|ep[._ -]?\d{2})[-\w.\',;.()]+(BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -][-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1582
|
|
|
$this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.Text.source.group', $echo, $type, $nameStatus, $show); |
1583
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((s\d{1,2}[._ -]?[bde]\d{1,2})|\d{1,2}x\d{2}|ep[._ -]?\d{2})[-\w.\',;& ]+((19|20)\d\d)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1584
|
|
|
$this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.Text.year.group', $echo, $type, $nameStatus, $show); |
1585
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((s\d{1,2}[._ -]?[bde]\d{1,2})|\d{1,2}x\d{2}|ep[._ -]?\d{2})[-\w.\',;& ]+(480|720|1080)[ip][._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1586
|
|
|
$this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.Text.resolution.source.vcodec.group', $echo, $type, $nameStatus, $show); |
1587
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((s\d{1,2}[._ -]?[bde]\d{1,2})|\d{1,2}x\d{2}|ep[._ -]?\d{2})[._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1588
|
|
|
$this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.source.vcodec.group', $echo, $type, $nameStatus, $show); |
1589
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((s\d{1,2}[._ -]?[bde]\d{1,2})|\d{1,2}x\d{2}|ep[._ -]?\d{2})[._ -](AAC( LC)?|AC-?3|DD5([._ -]1)?|(A_)?DTS-?(HD)?|Dolby( ?TrueHD)?|MP3|TrueHD)[._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](480|720|1080)[ip][._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1590
|
|
|
$this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.acodec.source.res.vcodec.group', $echo, $type, $nameStatus, $show); |
1591
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((19|20)\d\d)[._ -]((s\d{1,2}[._ -]?[bde]\d{1,2})|\d{1,2}x\d{2}|ep[._ -]?\d{2})[._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1592
|
|
|
$this->updateRelease($release, $result['0'], 'tvCheck: Title.year.###(season/episode).source.group', $echo, $type, $nameStatus, $show); |
1593
|
|
|
} elseif (preg_match('/\w(19|20)\d\d[._ -]\d{2}[._ -]\d{2}[._ -](IndyCar|NBA|NCW([TY])S|NNS|NSCS?)([._ -](19|20)\d\d)?[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1594
|
|
|
$this->updateRelease($release, $result['0'], 'tvCheck: Sports', $echo, $type, $nameStatus, $show); |
1595
|
|
|
} |
1596
|
|
|
} |
1597
|
|
|
} |
1598
|
|
|
|
1599
|
|
|
/** |
1600
|
|
|
* Look for a movie name. |
1601
|
|
|
* |
1602
|
|
|
* @param $release |
1603
|
|
|
* @param bool $echo |
1604
|
|
|
* @param string $type |
1605
|
|
|
* @param $nameStatus |
1606
|
|
|
* @param $show |
1607
|
|
|
* @throws \Exception |
1608
|
|
|
*/ |
1609
|
|
|
public function movieCheck($release, $echo, $type, $nameStatus, $show): void |
1610
|
|
|
{ |
1611
|
|
|
$result = []; |
1612
|
|
|
|
1613
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
1614
|
|
|
if (preg_match('/\w[-\w.\',;& ]+((19|20)\d\d)[-\w.\',;& ]+(480|720|1080)[ip][._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1615
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.year.Text.res.vcod.group', $echo, $type, $nameStatus, $show); |
1616
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((19|20)\d\d)[._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[._ -](480|720|1080)[ip][-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1617
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.vcodec.res.group', $echo, $type, $nameStatus, $show); |
1618
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((19|20)\d\d)[._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[._ -](AAC( LC)?|AC-?3|DD5([._ -]1)?|(A_)?DTS-?(HD)?|Dolby( ?TrueHD)?|MP3|TrueHD)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1619
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.vcodec.acodec.group', $echo, $type, $nameStatus, $show); |
1620
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+(Brazilian|Chinese|Croatian|Danish|Deutsch|Dutch|Estonian|English|Finnish|Flemish|Francais|French|German|Greek|Hebrew|Icelandic|Italian|Japenese|Japan|Japanese|Korean|Latin|Nordic|Norwegian|Polish|Portuguese|Russian|Serbian|Slovenian|Swedish|Spanisch|Spanish|Thai|Turkish)[._ -](AAC( LC)?|AC-?3|DD5([._ -]1)?|(A_)?DTS-?(HD)?|Dolby( ?TrueHD)?|MP3|TrueHD)[._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1621
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.year.language.acodec.source.vcodec.group', $echo, $type, $nameStatus, $show); |
1622
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((19|20)\d\d)[._ -](480|720|1080)[ip][._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](AAC( LC)?|AC-?3|DD5([._ -]1)?|(A_)?DTS-?(HD)?|Dolby( ?TrueHD)?|MP3|TrueHD)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1623
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.year.resolution.source.acodec.vcodec.group', $echo, $type, $nameStatus, $show); |
1624
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((19|20)\d\d)[._ -](480|720|1080)[ip][._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1625
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.year.resolution.source.vcodec.group', $echo, $type, $nameStatus, $show); |
1626
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((19|20)\d\d)[._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](480|720|1080)[ip][._ -](AAC( LC)?|AC-?3|DD5([._ -]1)?|(A_)?DTS-?(HD)?|Dolby( ?TrueHD)?|MP3|TrueHD)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1627
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.resolution.acodec.vcodec.group', $echo, $type, $nameStatus, $show); |
1628
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((19|20)\d\d)[._ -](480|720|1080)[ip][._ -](AAC( LC)?|AC-?3|DD5([._ -]1)?|(A_)?DTS-?(HD)?|Dolby( ?TrueHD)?|MP3|TrueHD)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1629
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.year.resolution.acodec.vcodec.group', $echo, $type, $nameStatus, $show); |
1630
|
|
|
} elseif (preg_match('/[-\w.\',;& ]+((19|20)\d\d)[._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BR(RIP)?|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](480|720|1080)[ip][._ -][-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1631
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.res.group', $echo, $type, $nameStatus, $show); |
1632
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+((19|20)\d\d)[._ -][-\w.\',;& ]+[._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BR(RIP)?|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1633
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.year.eptitle.source.vcodec.group', $echo, $type, $nameStatus, $show); |
1634
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+(480|720|1080)[ip][._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -](AAC( LC)?|AC-?3|DD5([._ -]1)?|(A_)?DTS-?(HD)?|Dolby( ?TrueHD)?|MP3|TrueHD)[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1635
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.resolution.source.acodec.vcodec.group', $echo, $type, $nameStatus, $show); |
1636
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+(480|720|1080)[ip][._ -](AAC( LC)?|AC-?3|DD5([._ -]1)?|(A_)?DTS-?(HD)?|Dolby( ?TrueHD)?|MP3|TrueHD)[-\w.\',;& ]+(BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -]((19|20)\d\d)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1637
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.resolution.acodec.eptitle.source.year.group', $echo, $type, $nameStatus, $show); |
1638
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+(Brazilian|Chinese|Croatian|Danish|Deutsch|Dutch|Estonian|English|Finnish|Flemish|Francais|French|German|Greek|Hebrew|Icelandic|Italian|Japenese|Japan|Japanese|Korean|Latin|Nordic|Norwegian|Polish|Portuguese|Russian|Serbian|Slovenian|Swedish|Spanisch|Spanish|Thai|Turkish)[._ -]((19|20)\d\d)[._ -](AAC( LC)?|AC-?3|DD5([._ -]1)?|(A_)?DTS-?(HD)?|Dolby( ?TrueHD)?|MP3|TrueHD)[._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1639
|
|
|
$this->updateRelease($release, $result['0'], 'movieCheck: Title.language.year.acodec.src', $echo, $type, $nameStatus, $show); |
1640
|
|
|
} |
1641
|
|
|
} |
1642
|
|
|
} |
1643
|
|
|
|
1644
|
|
|
/** |
1645
|
|
|
* Look for a game name. |
1646
|
|
|
* |
1647
|
|
|
* @param $release |
1648
|
|
|
* @param bool $echo |
1649
|
|
|
* @param string $type |
1650
|
|
|
* @param $nameStatus |
1651
|
|
|
* @param $show |
1652
|
|
|
* @throws \Exception |
1653
|
|
|
*/ |
1654
|
|
|
public function gameCheck($release, $echo, $type, $nameStatus, $show): void |
1655
|
|
|
{ |
1656
|
|
|
$result = []; |
1657
|
|
|
|
1658
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
1659
|
|
|
if (preg_match('/\w[-\w.\',;& ]+(ASIA|DLC|EUR|GOTY|JPN|KOR|MULTI\d{1}|NTSCU?|PAL|RF|Region[._ -]?Free|USA|XBLA)[._ -](DLC[._ -]Complete|FRENCH|GERMAN|MULTI\d{1}|PROPER|PSN|READ[._ -]?NFO|UMD)?[._ -]?(GC|NDS|NGC|PS3|PSP|WII|XBOX(360)?)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1660
|
|
|
$this->updateRelease($release, $result['0'], 'gameCheck: Videogames 1', $echo, $type, $nameStatus, $show); |
1661
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+(GC|NDS|NGC|PS3|WII|XBOX(360)?)[._ -](DUPLEX|iNSOMNi|OneUp|STRANGE|SWAG|SKY)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1662
|
|
|
$this->updateRelease($release, $result['0'], 'gameCheck: Videogames 2', $echo, $type, $nameStatus, $show); |
1663
|
|
|
} elseif (preg_match('/\w[\w.\',;-].+-OUTLAWS/i', $release->textstring, $result)) { |
1664
|
|
|
$result = str_replace('OUTLAWS', 'PC GAME OUTLAWS', $result['0']); |
1665
|
|
|
$this->updateRelease($release, $result['0'], 'gameCheck: PC Games -OUTLAWS', $echo, $type, $nameStatus, $show); |
1666
|
|
|
} elseif (preg_match('/\w[\w.\',;-].+\-ALiAS/i', $release->textstring, $result)) { |
1667
|
|
|
$newresult = str_replace('-ALiAS', ' PC GAME ALiAS', $result['0']); |
1668
|
|
|
$this->updateRelease($release, $newresult, 'gameCheck: PC Games -ALiAS', $echo, $type, $nameStatus, $show); |
1669
|
|
|
} |
1670
|
|
|
} |
1671
|
|
|
} |
1672
|
|
|
|
1673
|
|
|
/** |
1674
|
|
|
* Look for a app name. |
1675
|
|
|
* |
1676
|
|
|
* @param $release |
1677
|
|
|
* @param bool $echo |
1678
|
|
|
* @param string $type |
1679
|
|
|
* @param $nameStatus |
1680
|
|
|
* @param $show |
1681
|
|
|
* @throws \Exception |
1682
|
|
|
*/ |
1683
|
|
|
public function appCheck($release, $echo, $type, $nameStatus, $show): void |
1684
|
|
|
{ |
1685
|
|
|
$result = []; |
1686
|
|
|
|
1687
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
1688
|
|
|
if (preg_match('/\w[-\w.\',;& ]+(\d{1,10}|Linux|UNIX)[._ -](RPM)?[._ -]?(X64)?[._ -]?(Incl)[._ -](Keygen)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1689
|
|
|
$this->updateRelease($release, $result['0'], 'appCheck: Apps 1', $echo, $type, $nameStatus, $show); |
1690
|
|
|
} elseif (preg_match('/\w[-\w.\',;& ]+\d{1,8}[._ -](winall-freeware)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1691
|
|
|
$this->updateRelease($release, $result['0'], 'appCheck: Apps 2', $echo, $type, $nameStatus, $show); |
1692
|
|
|
} |
1693
|
|
|
} |
1694
|
|
|
} |
1695
|
|
|
|
1696
|
|
|
/** |
1697
|
|
|
* TV. |
1698
|
|
|
* |
1699
|
|
|
* @param $release |
1700
|
|
|
* @param bool $echo |
1701
|
|
|
* @param string $type |
1702
|
|
|
* @param $nameStatus |
1703
|
|
|
* @param $show |
1704
|
|
|
* @throws \Exception |
1705
|
|
|
*/ |
1706
|
|
|
public function nfoCheckTV($release, $echo, $type, $nameStatus, $show): void |
1707
|
|
|
{ |
1708
|
|
|
$result = []; |
1709
|
|
|
|
1710
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
1711
|
|
|
if (preg_match('/:\s*.*[\\\\\/]([A-Z0-9].+?S\d+[.-_ ]?[ED]\d+.+?)\.\w{2,}\s+/i', $release->textstring, $result)) { |
1712
|
|
|
$this->updateRelease($release, $result['1'], 'nfoCheck: Generic TV 1', $echo, $type, $nameStatus, $show); |
1713
|
|
|
} elseif (preg_match('/(?:(\:\s{1,}))(.+?S\d{1,3}[.-_ ]?[ED]\d{1,3}.+?)(\s{2,}|\r|\n)/i', $release->textstring, $result)) { |
1714
|
|
|
$this->updateRelease($release, $result['2'], 'nfoCheck: Generic TV 2', $echo, $type, $nameStatus, $show); |
1715
|
|
|
} |
1716
|
|
|
} |
1717
|
|
|
} |
1718
|
|
|
|
1719
|
|
|
/** |
1720
|
|
|
* Movies. |
1721
|
|
|
* |
1722
|
|
|
* @param $release |
1723
|
|
|
* @param bool $echo |
1724
|
|
|
* @param string $type |
1725
|
|
|
* @param $nameStatus |
1726
|
|
|
* @param $show |
1727
|
|
|
* @throws \Exception |
1728
|
|
|
*/ |
1729
|
|
|
public function nfoCheckMov($release, $echo, $type, $nameStatus, $show): void |
1730
|
|
|
{ |
1731
|
|
|
$result = []; |
1732
|
|
|
|
1733
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
1734
|
|
|
if (preg_match('/(?:((?!Source\s)\:\s{1,}))(.+?(19|20)\d\d.+?(BDRip|bluray|DVD(R|Rip)?|XVID).+?)(\s{2,}|\r|\n)/i', $release->textstring, $result)) { |
1735
|
|
|
$this->updateRelease($release, $result['2'], 'nfoCheck: Generic Movies 1', $echo, $type, $nameStatus, $show); |
1736
|
|
|
} elseif (preg_match('/(?:(\s{2,}))((?!Source).+?[\.\-_ ](19|20)\d\d.+?(BDRip|bluray|DVD(R|Rip)?|XVID).+?)(\s{2,}|\r|\n)/i', $release->textstring, $result)) { |
1737
|
|
|
$this->updateRelease($release, $result['2'], 'nfoCheck: Generic Movies 2', $echo, $type, $nameStatus, $show); |
1738
|
|
|
} elseif (preg_match('/(?:(\s{2,}))(.+?[\.\-_ ](NTSC|MULTi).+?(MULTi|DVDR)[\.\-_ ].+?)(\s{2,}|\r|\n)/i', $release->textstring, $result)) { |
1739
|
|
|
$this->updateRelease($release, $result['2'], 'nfoCheck: Generic Movies 3', $echo, $type, $nameStatus, $show); |
1740
|
|
|
} |
1741
|
|
|
} |
1742
|
|
|
} |
1743
|
|
|
|
1744
|
|
|
/** |
1745
|
|
|
* @param $release |
1746
|
|
|
* @param bool $echo |
1747
|
|
|
* @param string $type |
1748
|
|
|
* @param $nameStatus |
1749
|
|
|
* @param $show |
1750
|
|
|
* @throws \Exception |
1751
|
|
|
*/ |
1752
|
|
|
public function nfoCheckMus($release, $echo, $type, $nameStatus, $show): void |
1753
|
|
|
{ |
1754
|
|
|
$result = []; |
1755
|
|
|
|
1756
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id && preg_match('/(?:\s{2,})(.+?-FM-\d{2}-\d{2})/i', $release->textstring, $result)) { |
1757
|
|
|
$newname = str_replace('-FM-', '-FM-Radio-MP3-', $result['1']); |
1758
|
|
|
$this->updateRelease($release, $newname, 'nfoCheck: Music FM RADIO', $echo, $type, $nameStatus, $show); |
1759
|
|
|
} |
1760
|
|
|
} |
1761
|
|
|
|
1762
|
|
|
/** |
1763
|
|
|
* Title (year). |
1764
|
|
|
* |
1765
|
|
|
* @param $release |
1766
|
|
|
* @param bool $echo |
1767
|
|
|
* @param string $type |
1768
|
|
|
* @param $nameStatus |
1769
|
|
|
* @param $show |
1770
|
|
|
* @throws \Exception |
1771
|
|
|
*/ |
1772
|
|
|
public function nfoCheckTY($release, $echo, $type, $nameStatus, $show): void |
1773
|
|
|
{ |
1774
|
|
|
$result = []; |
1775
|
|
|
|
1776
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id && preg_match('/(\w[-\w`~!@#$%^&*()_+={}|"<>?\[\]\\;\',.\/ ]+\s?\((19|20)\d\d\))/i', $release->textstring, $result) && ! preg_match('/\.pdf|Audio ?Book/i', $release->textstring)) { |
1777
|
|
|
$releaseName = $result[0]; |
1778
|
|
|
if (preg_match('/(idiomas|lang|language|langue|sprache).*?\b(?P<lang>Brazilian|Chinese|Croatian|Danish|DE|Deutsch|Dutch|Estonian|ES|English|Englisch|Finnish|Flemish|Francais|French|FR|German|Greek|Hebrew|Icelandic|Italian|Japenese|Japan|Japanese|Korean|Latin|Nordic|Norwegian|Polish|Portuguese|Russian|Serbian|Slovenian|Swedish|Spanisch|Spanish|Thai|Turkish)\b/i', $release->textstring, $result)) { |
1779
|
|
|
switch ($result['lang']) { |
1780
|
|
|
case 'DE': |
1781
|
|
|
$result['lang'] = 'DUTCH'; |
1782
|
|
|
break; |
1783
|
|
|
case 'Englisch': |
1784
|
|
|
$result['lang'] = 'ENGLISH'; |
1785
|
|
|
break; |
1786
|
|
|
case 'FR': |
1787
|
|
|
$result['lang'] = 'FRENCH'; |
1788
|
|
|
break; |
1789
|
|
|
case 'ES': |
1790
|
|
|
$result['lang'] = 'SPANISH'; |
1791
|
|
|
break; |
1792
|
|
|
default: |
1793
|
|
|
break; |
1794
|
|
|
} |
1795
|
|
|
$releaseName = $releaseName.'.'.$result['lang']; |
1796
|
|
|
} |
1797
|
|
|
|
1798
|
|
|
if (preg_match('/(frame size|(video )?res(olution)?|video).*?(?P<res>(272|336|480|494|528|608|\(?640|688|704|720x480|810|816|820|1 ?080|1280( \@)?|1 ?920(x1080)?))/i', $release->textstring, $result)) { |
1799
|
|
|
switch ($result['res']) { |
1800
|
|
|
case '272': |
1801
|
|
|
case '336': |
1802
|
|
|
case '480': |
1803
|
|
|
case '494': |
1804
|
|
|
case '608': |
1805
|
|
|
case '640': |
1806
|
|
|
case '(640': |
1807
|
|
|
case '688': |
1808
|
|
|
case '704': |
1809
|
|
|
case '720x480': |
1810
|
|
|
$result['res'] = '480p'; |
1811
|
|
|
break; |
1812
|
|
|
case '1280x720': |
1813
|
|
|
case '1280': |
1814
|
|
|
case '1280 @': |
1815
|
|
|
$result['res'] = '720p'; |
1816
|
|
|
break; |
1817
|
|
|
case '810': |
1818
|
|
|
case '816': |
1819
|
|
|
case '820': |
1820
|
|
|
case '1920': |
1821
|
|
|
case '1 920': |
1822
|
|
|
case '1080': |
1823
|
|
|
case '1 080': |
1824
|
|
|
case '1920x1080': |
1825
|
|
|
$result['res'] = '1080p'; |
1826
|
|
|
break; |
1827
|
|
|
case '2160': |
1828
|
|
|
$result['res'] = '2160p'; |
1829
|
|
|
break; |
1830
|
|
|
} |
1831
|
|
|
|
1832
|
|
|
$releaseName = $releaseName.'.'.$result['res']; |
1833
|
|
|
} elseif (preg_match('/(largeur|width).*?(?P<res>(\(?640|688|704|720|1280( \@)?|1 ?920))/i', $release->textstring, $result)) { |
1834
|
|
|
switch ($result['res']) { |
1835
|
|
|
case '640': |
1836
|
|
|
case '(640': |
1837
|
|
|
case '688': |
1838
|
|
|
case '704': |
1839
|
|
|
case '720': |
1840
|
|
|
$result['res'] = '480p'; |
1841
|
|
|
break; |
1842
|
|
|
case '1280 @': |
1843
|
|
|
case '1280': |
1844
|
|
|
$result['res'] = '720p'; |
1845
|
|
|
break; |
1846
|
|
|
case '1920': |
1847
|
|
|
case '1 920': |
1848
|
|
|
$result['res'] = '1080p'; |
1849
|
|
|
break; |
1850
|
|
|
case '2160': |
1851
|
|
|
$result['res'] = '2160p'; |
1852
|
|
|
break; |
1853
|
|
|
} |
1854
|
|
|
|
1855
|
|
|
$releaseName = $releaseName.'.'.$result['res']; |
1856
|
|
|
} |
1857
|
|
|
|
1858
|
|
|
if (preg_match('/source.*?\b(?P<source>BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)\b/i', $release->textstring, $result)) { |
1859
|
|
|
switch ($result['source']) { |
1860
|
|
|
case 'BD': |
1861
|
|
|
$result['source'] = 'Bluray.x264'; |
1862
|
|
|
break; |
1863
|
|
|
case 'CAMRIP': |
1864
|
|
|
$result['source'] = 'CAM'; |
1865
|
|
|
break; |
1866
|
|
|
case 'DBrip': |
1867
|
|
|
$result['source'] = 'BDRIP'; |
1868
|
|
|
break; |
1869
|
|
|
case 'DVD R1': |
1870
|
|
|
case 'NTSC': |
1871
|
|
|
case 'PAL': |
1872
|
|
|
case 'VOD': |
1873
|
|
|
$result['source'] = 'DVD'; |
1874
|
|
|
break; |
1875
|
|
|
case 'HD': |
1876
|
|
|
$result['source'] = 'HDTV'; |
1877
|
|
|
break; |
1878
|
|
|
case 'Ripped ': |
1879
|
|
|
$result['source'] = 'DVDRIP'; |
1880
|
|
|
} |
1881
|
|
|
|
1882
|
|
|
$releaseName = $releaseName.'.'.$result['source']; |
1883
|
|
|
} elseif (preg_match('/(codec( (name|code))?|(original )?format|res(olution)|video( (codec|format|res))?|tv system|type|writing library).*?\b(?P<video>AVC|AVI|DBrip|DIVX|\(Divx|DVD|[HX][._ -]?264|MPEG-4 Visual|NTSC|PAL|WMV|XVID)\b/i', $release->textstring, $result)) { |
1884
|
|
|
switch ($result['video']) { |
1885
|
|
|
case 'AVI': |
1886
|
|
|
$result['video'] = 'DVDRIP'; |
1887
|
|
|
break; |
1888
|
|
|
case 'DBrip': |
1889
|
|
|
$result['video'] = 'BDRIP'; |
1890
|
|
|
break; |
1891
|
|
|
case '(Divx': |
1892
|
|
|
$result['video'] = 'DIVX'; |
1893
|
|
|
break; |
1894
|
|
|
case 'h264': |
1895
|
|
|
case 'h-264': |
1896
|
|
|
case 'h.264': |
1897
|
|
|
$result['video'] = 'H264'; |
1898
|
|
|
break; |
1899
|
|
|
case 'MPEG-4 Visual': |
1900
|
|
|
case 'x264': |
1901
|
|
|
case 'x-264': |
1902
|
|
|
case 'x.264': |
1903
|
|
|
$result['video'] = 'x264'; |
1904
|
|
|
break; |
1905
|
|
|
case 'NTSC': |
1906
|
|
|
case 'PAL': |
1907
|
|
|
$result['video'] = 'DVD'; |
1908
|
|
|
break; |
1909
|
|
|
} |
1910
|
|
|
|
1911
|
|
|
$releaseName = $releaseName.'.'.$result['video']; |
1912
|
|
|
} |
1913
|
|
|
|
1914
|
|
|
if (preg_match('/(audio( format)?|codec( name)?|format).*?\b(?P<audio>0x0055 MPEG-1 Layer 3|AAC( LC)?|AC-?3|\(AC3|DD5(.1)?|(A_)?DTS-?(HD)?|Dolby(\s?TrueHD)?|TrueHD|FLAC|MP3)\b/i', $release->textstring, $result)) { |
1915
|
|
|
switch ($result['audio']) { |
1916
|
|
|
case '0x0055 MPEG-1 Layer 3': |
1917
|
|
|
$result['audio'] = 'MP3'; |
1918
|
|
|
break; |
1919
|
|
|
case 'AC-3': |
1920
|
|
|
case '(AC3': |
1921
|
|
|
$result['audio'] = 'AC3'; |
1922
|
|
|
break; |
1923
|
|
|
case 'AAC LC': |
1924
|
|
|
$result['audio'] = 'AAC'; |
1925
|
|
|
break; |
1926
|
|
|
case 'A_DTS': |
1927
|
|
|
case 'DTS-HD': |
1928
|
|
|
case 'DTSHD': |
1929
|
|
|
$result['audio'] = 'DTS'; |
1930
|
|
|
} |
1931
|
|
|
$releaseName = $releaseName.'.'.$result['audio']; |
1932
|
|
|
} |
1933
|
|
|
$releaseName .= '-NoGroup'; |
1934
|
|
|
$this->updateRelease($release, $releaseName, 'nfoCheck: Title (Year)', $echo, $type, $nameStatus, $show); |
1935
|
|
|
} |
1936
|
|
|
} |
1937
|
|
|
|
1938
|
|
|
/** |
1939
|
|
|
* Games. |
1940
|
|
|
* |
1941
|
|
|
* @param $release |
1942
|
|
|
* @param bool $echo |
1943
|
|
|
* @param string $type |
1944
|
|
|
* @param $nameStatus |
1945
|
|
|
* @param $show |
1946
|
|
|
* @throws \Exception |
1947
|
|
|
*/ |
1948
|
|
|
public function nfoCheckG($release, $echo, $type, $nameStatus, $show): void |
1949
|
|
|
{ |
1950
|
|
|
$result = []; |
1951
|
|
|
|
1952
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
1953
|
|
|
if (preg_match('/ALiAS|BAT-TEAM|FAiRLiGHT|Game Type|Glamoury|HI2U|iTWINS|JAGUAR|(LARGE|MEDIUM)ISO|MAZE|nERv|PROPHET|PROFiT|PROCYON|RELOADED|REVOLVER|ROGUE|ViTALiTY/i', $release->textstring)) { |
1954
|
|
|
if (preg_match('/\w[\w.+&*\/\()\',;: -]+\(c\)[-\w.\',;& ]+\w/i', $release->textstring, $result)) { |
1955
|
|
|
$releaseName = str_replace(['(c)', '(C)'], '(GAMES) (c)', $result['0']); |
1956
|
|
|
$this->updateRelease($release, $releaseName, 'nfoCheck: PC Games (c)', $echo, $type, $nameStatus, $show); |
1957
|
|
|
} elseif (preg_match('/\w[\w.+&*\/()\',;: -]+\*ISO\*/i', $release->textstring, $result)) { |
1958
|
|
|
$releaseName = str_replace('*ISO*', '*ISO* (PC GAMES)', $result['0']); |
1959
|
|
|
$this->updateRelease($release, $releaseName, 'nfoCheck: PC Games *ISO*', $echo, $type, $nameStatus, $show); |
1960
|
|
|
} |
1961
|
|
|
} |
1962
|
|
|
} |
1963
|
|
|
} |
1964
|
|
|
|
1965
|
|
|
// |
1966
|
|
|
|
1967
|
|
|
/** |
1968
|
|
|
* Misc. |
1969
|
|
|
* |
1970
|
|
|
* @param $release |
1971
|
|
|
* @param bool $echo |
1972
|
|
|
* @param string $type |
1973
|
|
|
* @param $nameStatus |
1974
|
|
|
* @param $show |
1975
|
|
|
* @throws \Exception |
1976
|
|
|
*/ |
1977
|
|
|
public function nfoCheckMisc($release, $echo, $type, $nameStatus, $show): void |
1978
|
|
|
{ |
1979
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
1980
|
|
|
if (preg_match('/Supplier.+?IGUANA/i', $release->textstring)) { |
1981
|
|
|
$releaseName = ''; |
1982
|
|
|
$result = []; |
1983
|
|
|
if (preg_match('/\w[-\w`~!@#$%^&*()+={}|:"<>?\[\]\\;\',.\/ ]+\s\((19|20)\d\d\)/i', $release->textstring, $result)) { |
1984
|
|
|
$releaseName = $result[0]; |
1985
|
|
|
} elseif (preg_match('/\s\[\*\] (English|Dutch|French|German|Spanish)\b/i', $release->textstring, $result)) { |
1986
|
|
|
$releaseName = $releaseName.'.'.$result[1]; |
1987
|
|
|
} elseif (preg_match('/\s\[\*\] (DT?S [2567][._ -][0-2]( MONO)?)\b/i', $release->textstring, $result)) { |
1988
|
|
|
$releaseName = $releaseName.'.'.$result[2]; |
1989
|
|
|
} elseif (preg_match('/Format.+(DVD([59R])?|[HX][._ -]?264)\b/i', $release->textstring, $result)) { |
1990
|
|
|
$releaseName = $releaseName.'.'.$result[1]; |
1991
|
|
|
} elseif (preg_match('/\[(640x.+|1280x.+|1920x.+)\] Resolution\b/i', $release->textstring, $result)) { |
1992
|
|
|
if ($result[1] === '640x.+') { |
1993
|
|
|
$result[1] = '480p'; |
1994
|
|
|
} elseif ($result[1] === '1280x.+') { |
1995
|
|
|
$result[1] = '720p'; |
1996
|
|
|
} elseif ($result[1] === '1920x.+') { |
1997
|
|
|
$result[1] = '1080p'; |
1998
|
|
|
} |
1999
|
|
|
$releaseName = $releaseName.'.'.$result[1]; |
2000
|
|
|
} |
2001
|
|
|
$result = $releaseName.'.IGUANA'; |
2002
|
|
|
$this->updateRelease($release, $result, 'nfoCheck: IGUANA', $echo, $type, $nameStatus, $show); |
2003
|
|
|
} |
2004
|
|
|
} |
2005
|
|
|
} |
2006
|
|
|
|
2007
|
|
|
/** |
2008
|
|
|
* Just for filenames. |
2009
|
|
|
* |
2010
|
|
|
* @param $release |
2011
|
|
|
* @param bool $echo |
2012
|
|
|
* @param string $type |
2013
|
|
|
* @param $nameStatus |
2014
|
|
|
* @param $show |
2015
|
|
|
* |
2016
|
|
|
* @return bool |
2017
|
|
|
* @throws \Exception |
2018
|
|
|
*/ |
2019
|
|
|
public function fileCheck($release, $echo, $type, $nameStatus, $show): bool |
2020
|
|
|
{ |
2021
|
|
|
$result = []; |
2022
|
|
|
|
2023
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
2024
|
|
|
switch (true) { |
|
|
|
|
2025
|
|
|
case preg_match('/^(.+?(x264|XviD)\-TVP)\\\\/i', $release->textstring, $result): |
2026
|
|
|
$this->updateRelease($release, $result['1'], 'fileCheck: TVP', $echo, $type, $nameStatus, $show); |
2027
|
|
|
break; |
2028
|
|
|
case preg_match('/^(\\\\|\/)?(.+(\\\\|\/))*(.+?S\d{1,3}[.-_ ]?[ED]\d{1,3}.+)\.(.+)$/i', $release->textstring, $result): |
2029
|
|
|
$this->updateRelease($release, $result['4'], 'fileCheck: Generic TV', $echo, $type, $nameStatus, $show); |
2030
|
|
|
break; |
2031
|
|
|
case preg_match('/^(\\\\|\/)?(.+(\\\\|\/))*(.+?([\.\-_ ]\d{4}[\.\-_ ].+?(BDRip|bluray|DVDRip|XVID)).+)\.(.+)$/i', $release->textstring, $result): |
2032
|
|
|
$this->updateRelease($release, $result['4'], 'fileCheck: Generic movie 1', $echo, $type, $nameStatus, $show); |
2033
|
|
|
break; |
2034
|
|
|
case preg_match('/^([a-z0-9\.\-_]+(19|20)\d\d[a-z0-9\.\-_]+[\.\-_ ](720p|1080p|BDRip|bluray|DVDRip|x264|XviD)[a-z0-9\.\-_]+)\.[a-z]{2,}$/i', $release->textstring, $result): |
2035
|
|
|
$this->updateRelease($release, $result['1'], 'fileCheck: Generic movie 2', $echo, $type, $nameStatus, $show); |
2036
|
|
|
break; |
2037
|
|
|
case preg_match('/(.+?([\.\-_ ](CD|FM)|[\.\-_ ]\dCD|CDR|FLAC|SAT|WEB).+?(19|20)\d\d.+?)\\\\.+/i', $release->textstring, $result): |
2038
|
|
|
$this->updateRelease($release, $result['1'], 'fileCheck: Generic music', $echo, $type, $nameStatus, $show); |
2039
|
|
|
break; |
2040
|
|
|
case preg_match('/^(.+?(19|20)\d\d\-([a-z0-9]{3}|[a-z]{2,}|C4))\\\\/i', $release->textstring, $result): |
2041
|
|
|
$this->updateRelease($release, $result['1'], 'fileCheck: music groups', $echo, $type, $nameStatus, $show); |
2042
|
|
|
break; |
2043
|
|
|
case preg_match('/.+\\\\(.+\((19|20)\d\d\)\.avi)$/i', $release->textstring, $result): |
2044
|
|
|
$newname = str_replace('.avi', ' DVDRip XVID NoGroup', $result['1']); |
2045
|
|
|
$this->updateRelease($release, $newname, 'fileCheck: Movie (year) avi', $echo, $type, $nameStatus, $show); |
2046
|
|
|
break; |
2047
|
|
|
case preg_match('/.+\\\\(.+\((19|20)\d\d\)\.iso)$/i', $release->textstring, $result): |
2048
|
|
|
$newname = str_replace('.iso', ' DVD NoGroup', $result['1']); |
2049
|
|
|
$this->updateRelease($release, $newname, 'fileCheck: Movie (year) iso', $echo, $type, $nameStatus, $show); |
2050
|
|
|
break; |
2051
|
|
|
case preg_match('/^(.+?IMAGESET.+?)\\\\.+/i', $release->textstring, $result): |
2052
|
|
|
$this->updateRelease($release, $result['1'], 'fileCheck: XXX Imagesets', $echo, $type, $nameStatus, $show); |
2053
|
|
|
break; |
2054
|
|
|
case preg_match('/^VIDEOOT-[A-Z0-9]+\\\\([\w!.,& ()\[\]\'\`-]{8,}?\b.?)([-_](proof|sample|thumbs?))*(\.part\d*(\.rar)?|\.rar|\.7z)?(\d{1,3}\.rev|\.vol.+?|\.mp4)/', $release->textstring, $result): |
2055
|
|
|
$this->updateRelease($release, $result['1'].' XXX DVDRIP XviD-VIDEOOT', 'fileCheck: XXX XviD VIDEOOT', $echo, $type, $nameStatus, $show); |
2056
|
|
|
break; |
2057
|
|
|
case preg_match('/^.+?SDPORN/i', $release->textstring, $result): |
2058
|
|
|
$this->updateRelease($release, $result['0'], 'fileCheck: XXX SDPORN', $echo, $type, $nameStatus, $show); |
2059
|
|
|
break; |
2060
|
|
|
case preg_match('/\w[-\w.\',;& ]+1080i[._ -]DD5[._ -]1[._ -]MPEG2-R&C(?=\.ts)$/i', $release->textstring, $result): |
2061
|
|
|
$result = str_replace('MPEG2', 'MPEG2.HDTV', $result['0']); |
2062
|
|
|
$this->updateRelease($release, $result, 'fileCheck: R&C', $echo, $type, $nameStatus, $show); |
2063
|
|
|
break; |
2064
|
|
|
case preg_match('/\w[-\w.\',;& ]+((s\d{1,2}[._ -]?[bde]\d{1,2})|\d{1,2}x\d{2}|ep[._ -]?\d{2})[._ -](480|720|1080)[ip][._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -]nSD[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[._ -]NhaNC3[-\w.\',;& ]+\w/i', $release->textstring, $result): |
2065
|
|
|
$this->updateRelease($release, $result['0'], 'fileCheck: NhaNc3', $echo, $type, $nameStatus, $show); |
2066
|
|
|
break; |
2067
|
|
|
case preg_match('/\wtvp-[\w.\-\',;]+((s\d{1,2}[._ -]?[bde]\d{1,2})|\d{1,2}x\d{2}|ep[._ -]?\d{2})[._ -](720p|1080p|xvid)(?=\.(avi|mkv))$/i', $release->textstring, $result): |
2068
|
|
|
$result = str_replace('720p', '720p.HDTV.X264', $result['0']); |
2069
|
|
|
$result = str_replace('1080p', '1080p.Bluray.X264', $result['0']); |
2070
|
|
|
$result = str_replace('xvid', 'XVID.DVDrip', $result['0']); |
2071
|
|
|
$this->updateRelease($release, $result, 'fileCheck: tvp', $echo, $type, $nameStatus, $show); |
2072
|
|
|
break; |
2073
|
|
|
case preg_match('/\w[-\w.\',;& ]+\d{3,4}\.hdtv-lol\.(avi|mp4|mkv|ts|nfo|nzb)/i', $release->textstring, $result): |
2074
|
|
|
$this->updateRelease($release, $result['0'], 'fileCheck: Title.211.hdtv-lol.extension', $echo, $type, $nameStatus, $show); |
2075
|
|
|
break; |
2076
|
|
|
case preg_match('/\w[-\w.\',;& ]+-S\d{1,2}[EX]\d{1,2}-XVID-DL.avi/i', $release->textstring, $result): |
2077
|
|
|
$this->updateRelease($release, $result['0'], 'fileCheck: Title-SxxExx-XVID-DL.avi', $echo, $type, $nameStatus, $show); |
2078
|
|
|
break; |
2079
|
|
|
case preg_match('/\S.*[\w.\-\',;]+\s\-\ss\d{2}[ex]\d{2}\s\-\s[\w.\-\',;].+\./i', $release->textstring, $result): |
2080
|
|
|
$this->updateRelease($release, $result['0'], 'fileCheck: Title - SxxExx - Eptitle', $echo, $type, $nameStatus, $show); |
2081
|
|
|
break; |
2082
|
|
|
case preg_match('/\w.+?\)\.nds$/i', $release->textstring, $result): |
2083
|
|
|
$this->updateRelease($release, $result['0'], 'fileCheck: ).nds Nintendo DS', $echo, $type, $nameStatus, $show); |
2084
|
|
|
break; |
2085
|
|
|
case preg_match('/3DS_\d{4}.+\d{4} - (.+?)\.3ds/i', $release->textstring, $result): |
2086
|
|
|
$this->updateRelease($release, '3DS '.$result['1'], 'fileCheck: .3ds Nintendo 3DS', $echo, $type, $nameStatus, $show); |
2087
|
|
|
break; |
2088
|
|
|
case preg_match('/\w.+?\.(epub|mobi|azw|opf|fb2|prc|djvu|cb[rz])/i', $release->textstring, $result): |
2089
|
|
|
$result = str_replace('.'.$result['1'], ' ('.$result['1'].')', $result['0']); |
2090
|
|
|
$this->updateRelease($release, $result, 'fileCheck: EBook', $echo, $type, $nameStatus, $show); |
2091
|
|
|
break; |
2092
|
|
|
case preg_match('/\w+[-\w.\',;& ]+$/i', $release->textstring, $result) && preg_match(self::PREDB_REGEX, $release->textstring): |
2093
|
|
|
$this->updateRelease($release, $result['0'], 'fileCheck: Folder name', $echo, $type, $nameStatus, $show); |
2094
|
|
|
break; |
2095
|
|
|
default: |
2096
|
|
|
return false; |
2097
|
|
|
} |
2098
|
|
|
|
2099
|
|
|
return true; |
2100
|
|
|
} |
2101
|
|
|
|
2102
|
|
|
return false; |
2103
|
|
|
} |
2104
|
|
|
|
2105
|
|
|
/** |
2106
|
|
|
* Look for a name based on mediainfo xml Unique_ID. |
2107
|
|
|
* |
2108
|
|
|
* |
2109
|
|
|
* @param $release |
2110
|
|
|
* @param $echo |
2111
|
|
|
* @param $type |
2112
|
|
|
* @param $nameStatus |
2113
|
|
|
* @param $show |
2114
|
|
|
* |
2115
|
|
|
* @return bool |
2116
|
|
|
* @throws \Exception |
2117
|
|
|
*/ |
2118
|
|
|
public function uidCheck($release, $echo, $type, $nameStatus, $show): bool |
2119
|
|
|
{ |
2120
|
|
|
if (! empty($release->uid) && ! $this->done && $this->relid !== (int) $release->releases_id) { |
2121
|
|
|
$result = Release::fromQuery(sprintf( |
2122
|
|
|
' |
2123
|
|
|
SELECT r.id AS releases_id, r.size AS relsize, r.name AS textstring, r.searchname, r.fromname, r.predb_id |
2124
|
|
|
FROM releases r |
2125
|
|
|
LEFT JOIN release_unique ru ON ru.releases_id = r.id |
2126
|
|
|
WHERE ru.releases_id IS NOT NULL |
2127
|
|
|
AND ru.uniqueid = %s |
2128
|
|
|
AND ru.releases_id != %d |
2129
|
|
|
AND (r.predb_id > 0 OR r.anidbid > 0 OR r.fromname = %s)', |
2130
|
|
|
escapeString($release->uid), |
2131
|
|
|
$release->releases_id, |
2132
|
|
|
escapeString('[email protected] (EF)') |
2133
|
|
|
)); |
2134
|
|
|
|
2135
|
|
|
foreach ($result as $res) { |
2136
|
|
|
$floor = round(($res['relsize'] - $release->relsize) / $res['relsize'] * 100, 1); |
2137
|
|
|
if ($floor >= -10 && $floor <= 10) { |
2138
|
|
|
$this->updateRelease( |
2139
|
|
|
$release, |
2140
|
|
|
$res->searchname, |
2141
|
|
|
'uidCheck: Unique_ID', |
2142
|
|
|
$echo, |
2143
|
|
|
$type, |
2144
|
|
|
$nameStatus, |
2145
|
|
|
$show, |
2146
|
|
|
$res->predb_id |
2147
|
|
|
); |
2148
|
|
|
|
2149
|
|
|
return true; |
2150
|
|
|
} |
2151
|
|
|
} |
2152
|
|
|
} |
2153
|
|
|
$this->_updateSingleColumn('proc_uid', self::PROC_UID_DONE, $release->releases_id); |
2154
|
|
|
|
2155
|
|
|
return false; |
2156
|
|
|
} |
2157
|
|
|
|
2158
|
|
|
/** |
2159
|
|
|
* Look for a name based on mediainfo xml Unique_ID. |
2160
|
|
|
* |
2161
|
|
|
* |
2162
|
|
|
* @param $release |
2163
|
|
|
* @param $echo |
2164
|
|
|
* @param $type |
2165
|
|
|
* @param $nameStatus |
2166
|
|
|
* @param $show |
2167
|
|
|
* |
2168
|
|
|
* @return bool |
2169
|
|
|
* @throws \Exception |
2170
|
|
|
*/ |
2171
|
|
|
public function mediaMovieNameCheck($release, $echo, $type, $nameStatus, $show): bool |
2172
|
|
|
{ |
2173
|
|
|
$newName = ''; |
2174
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
2175
|
|
|
if (preg_match('/<Movie_name>(.+)<\/Movie_name>/i', $release->mediainfo, $match)) { |
2176
|
|
|
$media = $match[1]; |
2177
|
|
|
if (preg_match(self::PREDB_REGEX, $media, $match)) { |
2178
|
|
|
$newName = $match[1]; |
2179
|
|
|
} elseif (preg_match('/(.+)[\,](\sRMZ\.cr)?$/i', $media, $match)) { |
2180
|
|
|
$newName = $match[1]; |
2181
|
|
|
} else { |
2182
|
|
|
$newName = $media; |
2183
|
|
|
} |
2184
|
|
|
} |
2185
|
|
|
|
2186
|
|
|
if ($newName !== '') { |
2187
|
|
|
$this->updateRelease($release, $newName, 'MediaInfo: Movie Name', $echo, $type, $nameStatus, $show, $release->predb_id); |
2188
|
|
|
|
2189
|
|
|
return true; |
2190
|
|
|
} |
2191
|
|
|
} |
2192
|
|
|
$this->_updateSingleColumn('proc_uid', self::PROC_UID_DONE, $release->releases_id); |
2193
|
|
|
|
2194
|
|
|
return false; |
2195
|
|
|
} |
2196
|
|
|
|
2197
|
|
|
/** |
2198
|
|
|
* Look for a name based on xxx release filename. |
2199
|
|
|
* |
2200
|
|
|
* |
2201
|
|
|
* @param $release |
2202
|
|
|
* @param $echo |
2203
|
|
|
* @param $type |
2204
|
|
|
* @param $nameStatus |
2205
|
|
|
* @param $show |
2206
|
|
|
* |
2207
|
|
|
* @return bool |
2208
|
|
|
* @throws \Exception |
2209
|
|
|
*/ |
2210
|
|
|
public function xxxNameCheck($release, $echo, $type, $nameStatus, $show): bool |
2211
|
|
|
{ |
2212
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
2213
|
|
|
$result = Release::fromQuery( |
2214
|
|
|
sprintf( |
2215
|
|
|
" |
2216
|
|
|
SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, |
2217
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
2218
|
|
|
FROM releases rel |
2219
|
|
|
INNER JOIN release_files rf ON (rf.releases_id = {$release->releases_id}) |
2220
|
|
|
WHERE (rel.isrenamed = %d OR rel.categories_id IN(%d, %d)) |
2221
|
|
|
AND rf.name LIKE %s", |
2222
|
|
|
self::IS_RENAMED_NONE, |
2223
|
|
|
Category::OTHER_MISC, |
2224
|
|
|
Category::OTHER_HASHED, |
2225
|
|
|
escapeString('%SDPORN%') |
2226
|
|
|
) |
2227
|
|
|
); |
2228
|
|
|
|
2229
|
|
|
foreach ($result as $res) { |
2230
|
|
|
if (preg_match('/^.+?SDPORN/i', $res->textstring, $match)) { |
|
|
|
|
2231
|
|
|
$this->updateRelease( |
2232
|
|
|
$release, |
2233
|
|
|
$match['0'], |
2234
|
|
|
'fileCheck: XXX SDPORN', |
2235
|
|
|
$echo, |
2236
|
|
|
$type, |
2237
|
|
|
$nameStatus, |
2238
|
|
|
$show |
2239
|
|
|
); |
2240
|
|
|
|
2241
|
|
|
return true; |
2242
|
|
|
} |
2243
|
|
|
} |
2244
|
|
|
} |
2245
|
|
|
$this->_updateSingleColumn('proc_files', self::PROC_FILES_DONE, $release->releases_id); |
2246
|
|
|
|
2247
|
|
|
return false; |
2248
|
|
|
} |
2249
|
|
|
|
2250
|
|
|
/** |
2251
|
|
|
* Look for a name based on .srr release files extension. |
2252
|
|
|
* |
2253
|
|
|
* |
2254
|
|
|
* @param $release |
2255
|
|
|
* @param $echo |
2256
|
|
|
* @param $type |
2257
|
|
|
* @param $nameStatus |
2258
|
|
|
* @param $show |
2259
|
|
|
* |
2260
|
|
|
* @return bool |
2261
|
|
|
* @throws \Exception |
2262
|
|
|
*/ |
2263
|
|
|
public function srrNameCheck($release, $echo, $type, $nameStatus, $show): bool |
2264
|
|
|
{ |
2265
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
2266
|
|
|
$result = Release::fromQuery( |
2267
|
|
|
sprintf( |
2268
|
|
|
" |
2269
|
|
|
SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, |
2270
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
2271
|
|
|
FROM releases rel |
2272
|
|
|
INNER JOIN release_files rf ON (rf.releases_id = {$release->releases_id}) |
2273
|
|
|
WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d)) |
2274
|
|
|
AND rf.name LIKE %s", |
2275
|
|
|
self::IS_RENAMED_NONE, |
2276
|
|
|
Category::OTHER_MISC, |
2277
|
|
|
Category::OTHER_HASHED, |
2278
|
|
|
escapeString('%.srr') |
2279
|
|
|
) |
2280
|
|
|
); |
2281
|
|
|
|
2282
|
|
|
foreach ($result as $res) { |
2283
|
|
|
if (preg_match('/^(.*)\.srr$/i', $res->textstring, $match)) { |
|
|
|
|
2284
|
|
|
$this->updateRelease( |
2285
|
|
|
$release, |
2286
|
|
|
$match['1'], |
2287
|
|
|
'fileCheck: SRR extension', |
2288
|
|
|
$echo, |
2289
|
|
|
$type, |
2290
|
|
|
$nameStatus, |
2291
|
|
|
$show |
2292
|
|
|
); |
2293
|
|
|
|
2294
|
|
|
return true; |
2295
|
|
|
} |
2296
|
|
|
} |
2297
|
|
|
} |
2298
|
|
|
$this->_updateSingleColumn('proc_srr', self::PROC_SRR_DONE, $release->releases_id); |
2299
|
|
|
|
2300
|
|
|
return false; |
2301
|
|
|
} |
2302
|
|
|
|
2303
|
|
|
/** |
2304
|
|
|
* Look for a name based on par2 hash_16K block. |
2305
|
|
|
* |
2306
|
|
|
* |
2307
|
|
|
* @param $release |
2308
|
|
|
* @param $echo |
2309
|
|
|
* @param $type |
2310
|
|
|
* @param $nameStatus |
2311
|
|
|
* @param $show |
2312
|
|
|
* |
2313
|
|
|
* @return bool |
2314
|
|
|
* @throws \Exception |
2315
|
|
|
*/ |
2316
|
|
|
public function hashCheck($release, $echo, $type, $nameStatus, $show): bool |
2317
|
|
|
{ |
2318
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id) { |
2319
|
|
|
$result = Release::fromQuery(sprintf( |
2320
|
|
|
' |
2321
|
|
|
SELECT r.id AS releases_id, r.size AS relsize, r.name AS textstring, r.searchname, r.fromname, r.predb_id |
2322
|
|
|
FROM releases r |
2323
|
|
|
LEFT JOIN par_hashes ph ON ph.releases_id = r.id |
2324
|
|
|
WHERE ph.hash = %s |
2325
|
|
|
AND ph.releases_id != %d |
2326
|
|
|
AND (r.predb_id > 0 OR r.anidbid > 0)', |
2327
|
|
|
escapeString($release->hash), |
2328
|
|
|
$release->releases_id |
2329
|
|
|
)); |
2330
|
|
|
|
2331
|
|
|
foreach ($result as $res) { |
2332
|
|
|
$floor = round(($res->relsize - $release->relsize) / $res->relsize * 100, 1); |
|
|
|
|
2333
|
|
|
if ($floor >= -5 && $floor <= 5) { |
2334
|
|
|
$this->updateRelease( |
2335
|
|
|
$release, |
2336
|
|
|
$res->searchname, |
2337
|
|
|
'hashCheck: PAR2 hash_16K', |
2338
|
|
|
$echo, |
2339
|
|
|
$type, |
2340
|
|
|
$nameStatus, |
2341
|
|
|
$show, |
2342
|
|
|
$res->predb_id |
2343
|
|
|
); |
2344
|
|
|
|
2345
|
|
|
return true; |
2346
|
|
|
} |
2347
|
|
|
} |
2348
|
|
|
} |
2349
|
|
|
$this->_updateSingleColumn('proc_hash16k', self::PROC_HASH16K_DONE, $release->releases_id); |
2350
|
|
|
|
2351
|
|
|
return false; |
2352
|
|
|
} |
2353
|
|
|
|
2354
|
|
|
/** |
2355
|
|
|
* Look for a name based on rar crc32 hash. |
2356
|
|
|
* |
2357
|
|
|
* |
2358
|
|
|
* @param $release |
2359
|
|
|
* @param $echo |
2360
|
|
|
* @param $type |
2361
|
|
|
* @param $nameStatus |
2362
|
|
|
* @param $show |
2363
|
|
|
* |
2364
|
|
|
* @return bool |
2365
|
|
|
* @throws \Exception |
2366
|
|
|
*/ |
2367
|
|
|
public function crcCheck($release, $echo, $type, $nameStatus, $show): bool |
2368
|
|
|
{ |
2369
|
|
|
if (! $this->done && $this->relid !== (int) $release->releases_id && $release->textstring !== '') { |
2370
|
|
|
$result = Release::fromQuery( |
2371
|
|
|
sprintf( |
2372
|
|
|
' |
2373
|
|
|
SELECT rf.crc32, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, rel.size as relsize, rel.predb_id as predb_id, |
2374
|
|
|
rf.releases_id AS fileid, rel.id AS releases_id |
2375
|
|
|
FROM releases rel |
2376
|
|
|
LEFT JOIN release_files rf ON rf.releases_id = rel.id |
2377
|
|
|
WHERE rel.predb_id > 0 |
2378
|
|
|
AND rf.crc32 = %s', |
2379
|
|
|
escapeString($release->textstring) |
2380
|
|
|
) |
2381
|
|
|
); |
2382
|
|
|
|
2383
|
|
|
foreach ($result as $res) { |
2384
|
|
|
$floor = round(($res->relsize - $release->relsize) / $res->relsize * 100, 1); |
|
|
|
|
2385
|
|
|
if ($floor >= -5 && $floor <= 5) { |
2386
|
|
|
$this->updateRelease( |
2387
|
|
|
$release, |
2388
|
|
|
$res->searchname, |
2389
|
|
|
'crcCheck: CRC32', |
2390
|
|
|
$echo, |
2391
|
|
|
$type, |
2392
|
|
|
$nameStatus, |
2393
|
|
|
$show, |
2394
|
|
|
$res->predb_id |
2395
|
|
|
); |
2396
|
|
|
|
2397
|
|
|
return true; |
2398
|
|
|
} |
2399
|
|
|
} |
2400
|
|
|
} |
2401
|
|
|
$this->_updateSingleColumn('proc_crc32', self::PROC_CRC_DONE, $release->releases_id); |
2402
|
|
|
|
2403
|
|
|
return false; |
2404
|
|
|
} |
2405
|
|
|
|
2406
|
|
|
/** |
2407
|
|
|
* Resets NameFixer status variables for new processing. |
2408
|
|
|
*/ |
2409
|
|
|
public function reset(): void |
2410
|
|
|
{ |
2411
|
|
|
$this->done = $this->matched = false; |
2412
|
|
|
} |
2413
|
|
|
|
2414
|
|
|
/** |
2415
|
|
|
* @param string $fileName |
2416
|
|
|
* |
2417
|
|
|
* @return array |
2418
|
|
|
*/ |
2419
|
|
|
private function preMatch($fileName): array |
2420
|
|
|
{ |
2421
|
|
|
$result = preg_match('/(\d{2}\.\d{2}\.\d{2})+([\w\-.]+[\w]$)/i', $fileName, $match); |
2422
|
|
|
|
2423
|
|
|
return [$result === 1, $match[0] ?? '']; |
2424
|
|
|
} |
2425
|
|
|
|
2426
|
|
|
/** |
2427
|
|
|
* @param $release |
2428
|
|
|
* @param bool $echo |
2429
|
|
|
* @param string $type |
2430
|
|
|
* @param int $nameStatus |
2431
|
|
|
* @param bool $show |
2432
|
|
|
* @return bool |
2433
|
|
|
* @throws \Exception |
2434
|
|
|
*/ |
2435
|
|
|
public function preDbFileCheck($release, bool $echo, string $type, int $nameStatus, bool $show): bool |
2436
|
|
|
{ |
2437
|
|
|
$this->_fileName = $release->textstring; |
2438
|
|
|
$this->_cleanMatchFiles(); |
2439
|
|
|
|
2440
|
|
|
if (! empty($this->_fileName)) { |
2441
|
|
|
foreach ($this->sphinx->searchIndexes('predb_rt', $this->_fileName, ['filename', 'title']) as $match) { |
2442
|
|
|
if (! empty($match)) { |
2443
|
|
|
$this->updateRelease($release, $match['title'], 'PreDb: Filename match', $echo, $type, $nameStatus, $show, $match['id']); |
2444
|
|
|
|
2445
|
|
|
return true; |
2446
|
|
|
} |
2447
|
|
|
} |
2448
|
|
|
} |
2449
|
|
|
|
2450
|
|
|
return false; |
2451
|
|
|
} |
2452
|
|
|
|
2453
|
|
|
/** |
2454
|
|
|
* @param $release |
2455
|
|
|
* @param bool $echo |
2456
|
|
|
* @param string $type |
2457
|
|
|
* @param int $nameStatus |
2458
|
|
|
* @param bool $show |
2459
|
|
|
* @return bool |
2460
|
|
|
* @throws \Exception |
2461
|
|
|
*/ |
2462
|
|
|
public function preDbTitleCheck($release, bool $echo, string $type, int $nameStatus, bool $show): bool |
2463
|
|
|
{ |
2464
|
|
|
$this->_fileName = $release->textstring; |
2465
|
|
|
$this->_cleanMatchFiles(); |
2466
|
|
|
$this->cleanFileNames(); |
2467
|
|
|
if (! empty($this->_fileName)) { |
2468
|
|
|
foreach ($this->sphinx->searchIndexes('predb_rt', $this->_fileName, ['title']) as $match) { |
2469
|
|
|
if (! empty($match)) { |
2470
|
|
|
$this->updateRelease($release, $match['title'], 'PreDb: Title match', $echo, $type, $nameStatus, $show, $match['id']); |
2471
|
|
|
|
2472
|
|
|
return true; |
2473
|
|
|
} |
2474
|
|
|
} |
2475
|
|
|
} |
2476
|
|
|
|
2477
|
|
|
return false; |
2478
|
|
|
} |
2479
|
|
|
|
2480
|
|
|
/** |
2481
|
|
|
* Clean filenames for predb title match. |
2482
|
|
|
* |
2483
|
|
|
* |
2484
|
|
|
* @return string|string[]|null |
2485
|
|
|
*/ |
2486
|
|
|
private function cleanFileNames() |
2487
|
|
|
{ |
2488
|
|
|
if (preg_match('/(\.[a-zA-Z]{2})?(\.4k|\.fullhd|\.hd|\.int|\.\d+)?$/i', $this->_fileName, $match)) { |
2489
|
|
|
if (! empty($match[1]) && preg_match('/\.[a-zA-Z]{2}/i', $match[1])) { |
2490
|
|
|
$this->_fileName = preg_replace('/\.[a-zA-Z]{2}\./i', '.', $this->_fileName); |
2491
|
|
|
} |
2492
|
|
|
if (! empty($match[2])) { |
2493
|
|
|
if (preg_match('/\.4k$/', $match[2])) { |
2494
|
|
|
$this->_fileName = preg_replace('/\.4k$/', '.2160p', $this->_fileName); |
2495
|
|
|
} |
2496
|
|
|
if (preg_match('/\.fullhd$/i', $match[2])) { |
2497
|
|
|
$this->_fileName = preg_replace('/\.fullhd$/i', '.1080p', $this->_fileName); |
2498
|
|
|
} |
2499
|
|
|
if (preg_match('/\.hd$/i', $match[2])) { |
2500
|
|
|
$this->_fileName = preg_replace('/\.hd$/i', '.720p', $this->_fileName); |
2501
|
|
|
} |
2502
|
|
|
if (preg_match('/\.int$/i', $match[2])) { |
2503
|
|
|
$this->_fileName = preg_replace('/\.int$/i', '.INTERNAL', $this->_fileName); |
2504
|
|
|
} |
2505
|
|
|
if (preg_match('/\.\d+/', $match[2])) { |
2506
|
|
|
$this->_fileName = preg_replace('/\.\d+$/', '', $this->_fileName); |
2507
|
|
|
} |
2508
|
|
|
} |
2509
|
|
|
if (preg_match('/^[a-zA-Z]{0,7}\./', $this->_fileName)) { |
2510
|
|
|
$this->_fileName = preg_replace('/^[a-zA-Z]{0,7}\./', '', $this->_fileName); |
2511
|
|
|
} |
2512
|
|
|
} |
2513
|
|
|
|
2514
|
|
|
return $this->_fileName; |
2515
|
|
|
} |
2516
|
|
|
} |
2517
|
|
|
|
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.