Completed
Push — dev ( e5a31e...27c800 )
by Darko
06:50
created

NameFixer::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Blacklight;
4
5
use App\Models\Category;
6
use App\Models\Predb;
7
use App\Models\Release;
8
use App\Models\UsenetGroup;
9
use Blacklight\processing\PostProcess;
10
use Blacklight\utility\Utility;
11
use Illuminate\Support\Arr;
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]));
0 ignored issues
show
Unused Code introduced by
The call to Blacklight\Categorize::__construct() has too many arguments starting with array('Settings' => null). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
        $this->category = ($options['Categorize'] instanceof Categorize ? $options['Categorize'] : /** @scrutinizer ignore-call */ new Categorize(['Settings' => null]));

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.

Loading history...
174
        $this->sphinx = ($options['SphinxSearch'] instanceof SphinxSearch ? $options['SphinxSearch'] : new SphinxSearch());
175
    }
176
177
    /**
178
     * Attempts to fix release names using the NFO.
179
     *
180
     *
181
     * @param $time
182
     * @param $echo
183
     * @param $cats
184
     * @param $nameStatus
185
     * @param $show
186
     * @throws \Exception
187
     */
188
    public function fixNamesWithNfo($time, $echo, $cats, $nameStatus, $show): void
189
    {
190
        $this->_echoStartMessage($time, '.nfo files');
191
        $type = 'NFO, ';
192
193
        // Only select releases we haven't checked here before
194
        $preId = false;
195
        if ($cats === 3) {
196
            $query = sprintf(
197
                '
198
					SELECT rel.id AS releases_id, rel.fromname
199
					FROM releases rel
200
					INNER JOIN release_nfos nfo ON (nfo.releases_id = rel.id)
201
					WHERE rel.nzbstatus = %d
202
					AND rel.predb_id = 0',
203
                NZB::NZB_ADDED
204
            );
205
            $cats = 2;
206
            $preId = true;
207
        } else {
208
            $query = sprintf(
209
                '
210
					SELECT rel.id AS releases_id, rel.fromname
211
					FROM releases rel
212
					INNER JOIN release_nfos nfo ON (nfo.releases_id = rel.id)
213
					WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d))
214
					AND rel.predb_id = 0
215
					AND rel.proc_nfo = %d',
216
                self::IS_RENAMED_NONE,
217
                Category::OTHER_MISC,
218
                Category::OTHER_HASHED,
219
                self::PROC_NFO_NONE
220
            );
221
        }
222
223
        $releases = $this->_getReleases($time, $cats, $query);
224
225
        $total = \count($releases);
0 ignored issues
show
Bug introduced by
$releases of type false is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

225
        $total = \count(/** @scrutinizer ignore-type */ $releases);
Loading history...
226
227
        if ($total > 0) {
228
            $this->_totalReleases = $total;
229
            $this->consoletools->primary(number_format($total).' releases to process.');
230
231
            foreach ($releases as $rel) {
0 ignored issues
show
Bug introduced by
The expression $releases of type false is not traversable.
Loading history...
232
                $releaseRow = Release::fromQuery(
233
                        sprintf(
234
                            '
235
							SELECT nfo.releases_id AS nfoid, rel.groups_id, rel.fromname, rel.categories_id, rel.name, rel.searchname,
236
								UNCOMPRESS(nfo) AS textstring, rel.id AS releases_id
237
							FROM releases rel
238
							INNER JOIN release_nfos nfo ON (nfo.releases_id = rel.id)
239
							WHERE rel.id = %d LIMIT 1',
240
                            $rel->releases_id
241
                        )
242
                    );
243
244
                $this->checked++;
245
246
                // Ignore encrypted NFOs.
247
                if (preg_match('/^=newz\[NZB\]=\w+/', $releaseRow[0]->textstring)) {
248
                    $this->_updateSingleColumn('proc_nfo', self::PROC_NFO_DONE, $rel->releases_id);
249
                    continue;
250
                }
251
252
                $this->reset();
253
                $this->checkName($releaseRow[0], $echo, $type, $nameStatus, $show, $preId);
254
                $this->_echoRenamed($show);
255
            }
256
            $this->_echoFoundCount($echo, ' NFO\'s');
257
        } else {
258
            $this->consoletools->info('Nothing to fix.');
259
        }
260
    }
261
262
    /**
263
     * Attempts to fix release names using the File name.
264
     *
265
     *
266
     * @param $time
267
     * @param $echo
268
     * @param $cats
269
     * @param $nameStatus
270
     * @param $show
271
     * @throws \Exception
272
     */
273
    public function fixNamesWithFiles($time, $echo, $cats, $nameStatus, $show): void
274
    {
275
        $this->_echoStartMessage($time, 'file names');
276
        $type = 'Filenames, ';
277
278
        $preId = false;
279
        if ($cats === 3) {
280
            $query = sprintf(
281
                '
282
					SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id,
283
						rf.releases_id AS fileid, rel.id AS releases_id
284
					FROM releases rel
285
					INNER JOIN release_files rf ON rf.releases_id = rel.id
286
					WHERE nzbstatus = %d
287
					AND predb_id = 0',
288
                NZB::NZB_ADDED
289
            );
290
            $cats = 2;
291
            $preId = true;
292
        } else {
293
            $query = sprintf(
294
                '
295
					SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id,
296
						rf.releases_id AS fileid, rel.id AS releases_id
297
					FROM releases rel
298
					INNER JOIN release_files rf ON rf.releases_id = rel.id
299
					WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d))
300
					AND rel.predb_id = 0
301
					AND proc_files = %d',
302
                self::IS_RENAMED_NONE,
303
                Category::OTHER_MISC,
304
                Category::OTHER_HASHED,
305
                self::PROC_FILES_NONE
306
            );
307
        }
308
309
        $releases = $this->_getReleases($time, $cats, $query);
310
        $total = \count($releases);
0 ignored issues
show
Bug introduced by
$releases of type false is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

310
        $total = \count(/** @scrutinizer ignore-type */ $releases);
Loading history...
311
        if ($total > 0) {
312
            $this->_totalReleases = $total;
313
            $this->consoletools->primary(number_format($total).' file names to process.');
314
315
            foreach ($releases as $release) {
0 ignored issues
show
Bug introduced by
The expression $releases of type false is not traversable.
Loading history...
316
                $this->reset();
317
                $this->checkName($release, $echo, $type, $nameStatus, $show, $preId);
318
                $this->checked++;
319
                $this->_echoRenamed($show);
320
            }
321
322
            $this->_echoFoundCount($echo, ' files');
323
        } else {
324
            $this->consoletools->info('Nothing to fix.');
325
        }
326
    }
327
328
    /**
329
     * Attempts to fix release names using the rar file crc32 hash.
330
     *
331
     *
332
     * @param $time
333
     * @param $echo
334
     * @param $cats
335
     * @param $nameStatus
336
     * @param $show
337
     * @throws \Exception
338
     */
339
    public function fixNamesWithCrc($time, $echo, $cats, $nameStatus, $show): void
340
    {
341
        $this->_echoStartMessage($time, 'CRC32');
342
        $type = 'CRC32, ';
343
344
        $preId = false;
345
        if ($cats === 3) {
346
            $query = sprintf(
347
                '
348
					SELECT rf.crc32 AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, rel.size as relsize,
349
						rf.releases_id AS fileid, rel.id AS releases_id
350
					FROM releases rel
351
					INNER JOIN release_files rf ON rf.releases_id = rel.id
352
					WHERE nzbstatus = %d
353
					AND predb_id = 0',
354
                NZB::NZB_ADDED
355
            );
356
            $cats = 2;
357
            $preId = true;
358
        } else {
359
            $query = sprintf(
360
                '
361
					SELECT rf.crc32 AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id, rel.size as relsize,
362
						rf.releases_id AS fileid, rel.id AS releases_id
363
					FROM releases rel
364
					INNER JOIN release_files rf ON rf.releases_id = rel.id
365
					WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d))
366
					AND rel.predb_id = 0
367
					AND rel.proc_crc32 = %d',
368
                self::IS_RENAMED_NONE,
369
                Category::OTHER_MISC,
370
                Category::OTHER_HASHED,
371
                self::PROC_CRC_NONE
372
            );
373
        }
374
375
        $releases = $this->_getReleases($time, $cats, $query);
376
        $total = \count($releases);
0 ignored issues
show
Bug introduced by
$releases of type false is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

376
        $total = \count(/** @scrutinizer ignore-type */ $releases);
Loading history...
377
        if ($total > 0) {
378
            $this->_totalReleases = $total;
379
            $this->consoletools->primary(number_format($total).' CRC32\'s to process.');
380
381
            foreach ($releases as $release) {
0 ignored issues
show
Bug introduced by
The expression $releases of type false is not traversable.
Loading history...
382
                $this->reset();
383
                $this->checkName($release, $echo, $type, $nameStatus, $show, $preId);
384
                $this->checked++;
385
                $this->_echoRenamed($show);
386
            }
387
388
            $this->_echoFoundCount($echo, ' crc32\'s');
389
        } else {
390
            $this->consoletools->info('Nothing to fix.');
391
        }
392
    }
393
394
    /**
395
     * Attempts to fix XXX release names using the File name.
396
     *
397
     *
398
     * @param $time
399
     * @param $echo
400
     * @param $cats
401
     * @param $nameStatus
402
     * @param $show
403
     * @throws \Exception
404
     */
405
    public function fixXXXNamesWithFiles($time, $echo, $cats, $nameStatus, $show): void
406
    {
407
        $this->_echoStartMessage($time, 'file names');
408
        $type = 'Filenames, ';
409
410
        if ($cats === 3) {
411
            $query = sprintf(
412
                '
413
					SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id,
414
						rf.releases_id AS fileid, rel.id AS releases_id
415
					FROM releases rel
416
					INNER JOIN release_files rf ON rf.releases_id = rel.id
417
					WHERE nzbstatus = %d
418
					AND predb_id = 0',
419
                NZB::NZB_ADDED
420
            );
421
            $cats = 2;
422
        } else {
423
            $query = sprintf(
424
                '
425
					SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id,
426
						rf.releases_id AS fileid, rel.id AS releases_id
427
					FROM releases rel
428
					INNER JOIN release_files rf ON rf.releases_id = rel.id
429
					WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d))
430
					AND rel.predb_id = 0
431
					AND rf.name LIKE %s',
432
                self::IS_RENAMED_NONE,
433
                Category::OTHER_MISC,
434
                Category::OTHER_HASHED,
435
                escapeString('%SDPORN%')
436
            );
437
        }
438
439
        $releases = $this->_getReleases($time, $cats, $query);
440
        $total = \count($releases);
0 ignored issues
show
Bug introduced by
$releases of type false is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

440
        $total = \count(/** @scrutinizer ignore-type */ $releases);
Loading history...
441
        if ($total > 0) {
442
            $this->_totalReleases = $total;
443
            $this->consoletools->primary(number_format($total).' xxx file names to process.');
444
445
            foreach ($releases as $release) {
0 ignored issues
show
Bug introduced by
The expression $releases of type false is not traversable.
Loading history...
446
                $this->reset();
447
                $this->xxxNameCheck($release, $echo, $type, $nameStatus, $show);
448
                $this->checked++;
449
                $this->_echoRenamed($show);
450
            }
451
            $this->_echoFoundCount($echo, ' files');
452
        } else {
453
            $this->consoletools->info('Nothing to fix.');
454
        }
455
    }
456
457
    /**
458
     * Attempts to fix release names using the SRR filename.
459
     *
460
     *
461
     * @param $time
462
     * @param $echo
463
     * @param $cats
464
     * @param $nameStatus
465
     * @param $show
466
     * @throws \Exception
467
     */
468
    public function fixNamesWithSrr($time, $echo, $cats, $nameStatus, $show): void
469
    {
470
        $this->_echoStartMessage($time, 'SRR file names');
471
        $type = 'SRR, ';
472
473
        if ($cats === 3) {
474
            $query = sprintf(
475
                '
476
					SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id,
477
						rf.releases_id AS fileid, rel.id AS releases_id
478
					FROM releases rel
479
					INNER JOIN release_files rf ON rf.releases_id = rel.id
480
					WHERE nzbstatus = %d
481
					AND predb_id = 0',
482
                NZB::NZB_ADDED
483
            );
484
            $cats = 2;
485
        } else {
486
            $query = sprintf(
487
                '
488
					SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id,
489
						rf.releases_id AS fileid, rel.id AS releases_id
490
					FROM releases rel
491
					INNER JOIN release_files rf ON rf.releases_id = rel.id
492
					WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d))
493
					AND rel.predb_id = 0
494
					AND rf.name LIKE %s
495
					AND rel.proc_srr = %d',
496
                self::IS_RENAMED_NONE,
497
                Category::OTHER_MISC,
498
                Category::OTHER_HASHED,
499
                escapeString('%.srr'),
500
                self::PROC_SRR_NONE
501
            );
502
        }
503
504
        $releases = $this->_getReleases($time, $cats, $query);
505
        $total = \count($releases);
0 ignored issues
show
Bug introduced by
$releases of type false is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

505
        $total = \count(/** @scrutinizer ignore-type */ $releases);
Loading history...
506
        if ($total > 0) {
507
            $this->_totalReleases = $total;
508
            $this->consoletools->primary(number_format($total).' srr file extensions to process.');
509
510
            foreach ($releases as $release) {
0 ignored issues
show
Bug introduced by
The expression $releases of type false is not traversable.
Loading history...
511
                $this->reset();
512
                $this->srrNameCheck($release, $echo, $type, $nameStatus, $show);
513
                $this->checked++;
514
                $this->_echoRenamed($show);
515
            }
516
            $this->_echoFoundCount($echo, ' files');
517
        } else {
518
            $this->consoletools->info('Nothing to fix.');
519
        }
520
    }
521
522
    /**
523
     * Attempts to fix release names using the Par2 File.
524
     *
525
     * @param int $time 1: 24 hours, 2: no time limit
526
     * @param int $echo 1: change the name, anything else: preview of what could have been changed.
527
     * @param int $cats 1: other categories, 2: all categories
528
     * @param      $nameStatus
529
     * @param      $show
530
     * @param NNTP $nntp
531
     * @throws \Exception
532
     */
533
    public function fixNamesWithPar2($time, $echo, $cats, $nameStatus, $show, $nntp): void
534
    {
535
        $this->_echoStartMessage($time, 'par2 files');
536
537
        if ($cats === 3) {
538
            $query = sprintf(
539
                '
540
					SELECT rel.id AS releases_id, rel.guid, rel.groups_id, rel.fromname
541
					FROM releases rel
542
					WHERE rel.nzbstatus = %d
543
					AND rel.predb_id = 0',
544
                NZB::NZB_ADDED
545
            );
546
            $cats = 2;
547
        } else {
548
            $query = sprintf(
549
                '
550
					SELECT rel.id AS releases_id, rel.guid, rel.groups_id, rel.fromname
551
					FROM releases rel
552
					WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d))
553
					AND rel.predb_id = 0
554
					AND rel.proc_par2 = %d',
555
                self::IS_RENAMED_NONE,
556
                Category::OTHER_MISC,
557
                Category::OTHER_HASHED,
558
                self::PROC_PAR2_NONE
559
            );
560
        }
561
562
        $releases = $this->_getReleases($time, $cats, $query);
563
564
        $total = \count($releases);
0 ignored issues
show
Bug introduced by
$releases of type false is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

564
        $total = \count(/** @scrutinizer ignore-type */ $releases);
Loading history...
565
        if ($total > 0) {
566
            $this->_totalReleases = $total;
567
568
            $this->consoletools->primary(number_format($total).' releases to process.');
569
            $Nfo = new Nfo();
570
            $nzbContents = new NZBContents(
571
                    [
572
                        'Echo'        => $this->echooutput,
573
                        'NNTP'        => $nntp,
574
                        'Nfo'         => $Nfo,
575
                        'PostProcess' => new PostProcess(['Nfo' => $Nfo]),
576
                    ]
577
                );
578
579
            foreach ($releases as $release) {
0 ignored issues
show
Bug introduced by
The expression $releases of type false is not traversable.
Loading history...
580
                if ($nzbContents->checkPAR2($release->guid, $release->releases_id, $release->groups_id, $nameStatus, $show)) {
581
                    $this->fixed++;
582
                }
583
584
                $this->checked++;
585
                $this->_echoRenamed($show);
586
            }
587
            $this->_echoFoundCount($echo, ' files');
588
        } else {
589
            $this->consoletools->info('Nothing to fix.');
590
        }
591
    }
592
593
    /**
594
     * Attempts to fix release names using the mediainfo xml Unique_ID.
595
     *
596
     *
597
     * @param $time
598
     * @param $echo
599
     * @param $cats
600
     * @param $nameStatus
601
     * @param $show
602
     * @throws \Exception
603
     */
604
    public function fixNamesWithMedia($time, $echo, $cats, $nameStatus, $show): void
605
    {
606
        $type = 'UID, ';
607
608
        $this->_echoStartMessage($time, 'mediainfo Unique_IDs');
609
610
        // Re-check all releases we haven't matched to a PreDB
611
        if ($cats === 3) {
612
            $query = sprintf(
613
                '
614
				SELECT
615
					rel.id AS releases_id, rel.size AS relsize, rel.groups_id, rel.fromname, rel.categories_id,
616
					rel.name, rel.name AS textstring, rel.predb_id, rel.searchname,
617
					ru.uniqueid AS uid
618
				FROM releases rel
619
				LEFT JOIN release_unique ru ON ru.releases_id = rel.id
620
				WHERE ru.releases_id IS NOT NULL
621
				AND rel.nzbstatus = %d
622
				AND rel.predb_id = 0',
623
                NZB::NZB_ADDED
624
            );
625
            $cats = 2;
626
        // Otherwise check only releases we haven't renamed and checked uid before in Misc categories
627
        } else {
628
            $query = sprintf(
629
                '
630
				SELECT
631
					rel.id AS releases_id, rel.size AS relsize, rel.groups_id, rel.fromname, rel.categories_id,
632
					rel.name, rel.name AS textstring, rel.predb_id, rel.searchname,
633
					ru.uniqueid AS uid
634
				FROM releases rel
635
				LEFT JOIN release_unique ru ON ru.releases_id = rel.id
636
				WHERE ru.releases_id IS NOT NULL
637
				AND rel.nzbstatus = %d
638
				AND (rel.isrenamed = %d OR rel.categories_id IN (%d, %d))
639
				AND rel.predb_id = 0
640
				AND rel.proc_uid = %d',
641
                NZB::NZB_ADDED,
642
                self::IS_RENAMED_NONE,
643
                Category::OTHER_MISC,
644
                Category::OTHER_HASHED,
645
                self::PROC_UID_NONE
646
            );
647
        }
648
649
        $releases = $this->_getReleases($time, $cats, $query);
650
        $total = \count($releases);
0 ignored issues
show
Bug introduced by
$releases of type false is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

650
        $total = \count(/** @scrutinizer ignore-type */ $releases);
Loading history...
651
        if ($total > 0) {
652
            $this->_totalReleases = $total;
653
            $this->consoletools->primary(number_format($total).' unique ids to process.');
654
            foreach ($releases as $rel) {
0 ignored issues
show
Bug introduced by
The expression $releases of type false is not traversable.
Loading history...
655
                $this->checked++;
656
                $this->reset();
657
                $this->uidCheck($rel, $echo, $type, $nameStatus, $show);
658
                $this->_echoRenamed($show);
659
            }
660
            $this->_echoFoundCount($echo, ' UID\'s');
661
        } else {
662
            $this->consoletools->info('Nothing to fix.');
663
        }
664
    }
665
666
    /**
667
     * @param $time
668
     * @param $echo
669
     * @param $cats
670
     * @param $nameStatus
671
     * @param $show
672
     * @throws \Exception
673
     */
674
    public function fixNamesWithMediaMovieName($time, $echo, $cats, $nameStatus, $show): void
675
    {
676
        $type = 'Mediainfo, ';
677
678
        $this->_echoStartMessage($time, 'Mediainfo movie_name');
679
680
        // Re-check all releases we haven't matched to a PreDB
681
        if ($cats === 3) {
682
            $query = sprintf(
683
                "
684
				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
685
				FROM releases rel
686
				INNER JOIN releaseextrafull rf ON rf.releases_id = rel.id
687
				WHERE rel.name REGEXP '[a-z0-9]{32,64}'
688
                AND rf.mediainfo REGEXP '\<Movie_name\>'
689
                AND rel.nzbstatus = %d
690
                AND rel.predb_id = 0",
691
                NZB::NZB_ADDED
692
            );
693
            $cats = 2;
694
        // Otherwise check only releases we haven't renamed and checked uid before in Misc categories
695
        } else {
696
            $query = sprintf(
697
                "
698
				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
699
				FROM releases rel
700
				INNER JOIN releaseextrafull rf ON rf.releases_id = rel.id
701
				WHERE rel.name REGEXP '[a-z0-9]{32,64}'
702
				AND rf.mediainfo REGEXP '\<Movie_name\>'
703
				AND rel.nzbstatus = %d
704
                AND rel.isrenamed = %d
705
                AND rel.predb_id = 0
706
				AND rel.categories_id IN (%d, %d)",
707
                NZB::NZB_ADDED,
708
                self::IS_RENAMED_NONE,
709
                Category::OTHER_MISC,
710
                Category::OTHER_HASHED
711
            );
712
        }
713
714
        $releases = $this->_getReleases($time, $cats, $query);
715
        $total = \count($releases);
0 ignored issues
show
Bug introduced by
$releases of type false is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

715
        $total = \count(/** @scrutinizer ignore-type */ $releases);
Loading history...
716
        if ($total > 0) {
717
            $this->_totalReleases = $total;
718
            $this->consoletools->primary(number_format($total).' mediainfo movie names to process.');
719
            foreach ($releases as $rel) {
0 ignored issues
show
Bug introduced by
The expression $releases of type false is not traversable.
Loading history...
720
                $this->checked++;
721
                $this->reset();
722
                $this->mediaMovieNameCheck($rel, $echo, $type, $nameStatus, $show);
723
                $this->_echoRenamed($show);
724
            }
725
            $this->_echoFoundCount($echo, ' MediaInfo\'s');
726
        } else {
727
            $this->consoletools->info('Nothing to fix.');
728
        }
729
    }
730
731
    /**
732
     * Attempts to fix release names using the par2 hash_16K block.
733
     *
734
     *
735
     * @param $time
736
     * @param $echo
737
     * @param $cats
738
     * @param $nameStatus
739
     * @param $show
740
     * @throws \Exception
741
     */
742
    public function fixNamesWithParHash($time, $echo, $cats, $nameStatus, $show): void
743
    {
744
        $type = 'PAR2 hash, ';
745
746
        $this->_echoStartMessage($time, 'PAR2 hash_16K');
747
748
        // Re-check all releases we haven't matched to a PreDB
749
        if ($cats === 3) {
750
            $query = sprintf(
751
                '
752
				SELECT
753
					rel.id AS releases_id, rel.size AS relsize, rel.groups_id, rel.fromname, rel.categories_id,
754
					rel.name, rel.name AS textstring, rel.predb_id, rel.searchname,
755
					IFNULL(ph.hash, "") AS hash
756
				FROM releases rel
757
				LEFT JOIN par_hashes ph ON ph.releases_id = rel.id
758
				WHERE ph.hash != ""
759
				AND rel.nzbstatus = %d
760
				AND rel.predb_id = 0',
761
                NZB::NZB_ADDED
762
            );
763
            $cats = 2;
764
        // Otherwise check only releases we haven't renamed and checked their par2 hash_16K before in Misc categories
765
        } else {
766
            $query = sprintf(
767
                '
768
				SELECT
769
					rel.id AS releases_id, rel.size AS relsize, rel.groups_id, rel.fromname, rel.categories_id,
770
					rel.name, rel.name AS textstring, rel.predb_id, rel.searchname,
771
					IFNULL(ph.hash, "") AS hash
772
				FROM releases rel
773
				LEFT JOIN par_hashes ph ON ph.releases_id = rel.id
774
				WHERE rel.nzbstatus = %d
775
				AND (rel.isrenamed = %d OR rel.categories_id IN (%d, %d))
776
				AND rel.predb_id = 0
777
				AND ph.hash != ""
778
				AND rel.proc_hash16k = %d',
779
                NZB::NZB_ADDED,
780
                self::IS_RENAMED_NONE,
781
                Category::OTHER_MISC,
782
                Category::OTHER_HASHED,
783
                self::PROC_HASH16K_NONE
784
            );
785
        }
786
787
        $releases = $this->_getReleases($time, $cats, $query);
788
789
        $total = \count($releases);
0 ignored issues
show
Bug introduced by
$releases of type false is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

789
        $total = \count(/** @scrutinizer ignore-type */ $releases);
Loading history...
790
        if ($total > 0) {
791
            $this->_totalReleases = $total;
792
            $this->consoletools->primary(number_format($total).' hash_16K to process.');
793
            foreach ($releases as $rel) {
0 ignored issues
show
Bug introduced by
The expression $releases of type false is not traversable.
Loading history...
794
                $this->checked++;
795
                $this->reset();
796
                $this->hashCheck($rel, $echo, $type, $nameStatus, $show);
797
                $this->_echoRenamed($show);
798
            }
799
            $this->_echoFoundCount($echo, ' hashes');
800
        } else {
801
            $this->consoletools->info('Nothing to fix.');
802
        }
803
    }
804
805
    /**
806
     * @param        $time
807
     * @param        $cats
808
     * @param        $query
809
     * @param string $limit
810
     *
811
     * @return array|false
812
     */
813
    protected function _getReleases($time, $cats, $query, $limit = '')
814
    {
815
        $releases = false;
816
        $queryLimit = ($limit === '') ? '' : ' LIMIT '.$limit;
817
        // 24 hours, other cats
818
        if ($time === 1 && $cats === 1) {
819
            $releases = Release::fromQuery($query.$this->timeother.$queryLimit);
820
        } // 24 hours, all cats
821
        if ($time === 1 && $cats === 2) {
822
            $releases = Release::fromQuery($query.$this->timeall.$queryLimit);
823
        } //other cats
824
        if ($time === 2 && $cats === 1) {
825
            $releases = Release::fromQuery($query.$this->fullother.$queryLimit);
826
        } // all cats
827
        if ($time === 2 && $cats === 2) {
828
            $releases = Release::fromQuery($query.$this->fullall.$queryLimit);
829
        }
830
831
        return $releases;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $releases also could return the type Illuminate\Database\Eloquent\Collection which is incompatible with the documented return type array|false.
Loading history...
832
    }
833
834
    /**
835
     * Echo the amount of releases that found a new name.
836
     *
837
     * @param int|bool    $echo 1: change the name, anything else: preview of what could have been changed.
838
     * @param string $type The function type that found the name.
839
     */
840
    protected function _echoFoundCount($echo, $type): void
841
    {
842
        if ($echo === true) {
843
            $this->consoletools->header(
844
                PHP_EOL.
845
                number_format($this->fixed).
846
                ' releases have had their names changed out of: '.
847
                number_format($this->checked).
848
                $type.'.'
849
            );
850
        } else {
851
            $this->consoletools->header(
852
                PHP_EOL.
853
                number_format($this->fixed).
854
                ' releases could have their names changed. '.
855
                number_format($this->checked).
856
                $type.' were checked.'
857
            );
858
        }
859
    }
860
861
    /**
862
     * @param int    $time 1: 24 hours, 2: no time limit
863
     * @param string $type The function type.
864
     */
865
    protected function _echoStartMessage($time, $type): void
866
    {
867
        $this->consoletools->header(
868
            sprintf(
869
                'Fixing search names %s using %s.',
870
                ($time === 1 ? 'in the past 6 hours' : 'since the beginning'),
871
                $type
872
            )
873
        );
874
    }
875
876
    /**
877
     * @param int $show
878
     */
879
    protected function _echoRenamed($show): void
880
    {
881
        if ($this->checked % 500 === 0 && $show === 1) {
882
            $this->consoletools->alternate(PHP_EOL.number_format($this->checked).' files processed.'.PHP_EOL);
883
        }
884
885
        if ($show === 2) {
886
            $this->consoletools->overWritePrimary(
887
                'Renamed Releases: ['.
888
                number_format($this->fixed).
889
                '] '.
890
                $this->consoletools->percentString($this->checked, $this->_totalReleases)
891
            );
892
        }
893
    }
894
895
    /**
896
     * Update the release with the new information.
897
     *
898
     *
899
     * @param     $release
900
     * @param     $name
901
     * @param     $method
902
     * @param     $echo
903
     * @param     $type
904
     * @param int $nameStatus
905
     * @param bool $show
906
     * @param int $preId
907
     *
908
     * @throws \Exception
909
     */
910
    public function updateRelease($release, $name, $method, $echo, $type, int $nameStatus, bool $show, int $preId = 0): void
911
    {
912
        if (\is_array($release)) {
913
            $release = (object) $release;
914
        }
915
        if ($this->relid !== $release->releases_id) {
916
            $newName = (new ReleaseCleaning())->fixerCleaner($name);
917
            if (strtolower($newName) !== strtolower($release->searchname)) {
918
                $this->matched = true;
919
                $this->relid = (int) $release->releases_id;
920
921
                $determinedCategory = $this->category->determineCategory($release->groups_id, $newName, ! empty($release->fromname) ? $release->fromname : '');
922
923
                if ($type === 'PAR2, ') {
924
                    $newName = ucwords($newName);
925
                    if (preg_match('/(.+?)\.[a-z0-9]{2,3}(PAR2)?$/i', $name, $match)) {
926
                        $newName = $match[1];
927
                    }
928
                }
929
930
                $this->fixed++;
931
932
                $newName = explode('\\', $newName);
933
                $newName = preg_replace(['/^[=_\.:\s-]+/', '/[=_\.:\s-]+$/'], '', $newName[0]);
934
935
                if ($this->echooutput && $show) {
936
                    $groupName = UsenetGroup::getNameByID($release->groups_id);
937
                    $oldCatName = Category::getNameByID($release->categories_id);
938
                    $newCatName = Category::getNameByID($determinedCategory['categories_id']);
939
940
                    if ($type === 'PAR2, ') {
941
                        echo PHP_EOL;
942
                    }
943
944
                    echo PHP_EOL;
945
946
                    $this->consoletools->headerOver('New name:  ').
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->headerOver('New name: ') targeting Blacklight\ColorCLI::headerOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $this->consoletools->headerOver('New name: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

946
                    /** @scrutinizer ignore-type */ $this->consoletools->headerOver('New name:  ').
Loading history...
947
                        $this->consoletools->primary(substr($newName, 0, 299)).
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->pri...bstr($newName, 0, 299)) targeting Blacklight\ColorCLI::primary() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
948
                        $this->consoletools->headerOver('Old name:  ').
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->headerOver('Old name: ') targeting Blacklight\ColorCLI::headerOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $this->consoletools->headerOver('Old name: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

948
                        /** @scrutinizer ignore-type */ $this->consoletools->headerOver('Old name:  ').
Loading history...
949
                        $this->consoletools->primary($release->searchname).
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->pri...y($release->searchname) targeting Blacklight\ColorCLI::primary() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $this->consoletools->pri...y($release->searchname) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

949
                        /** @scrutinizer ignore-type */ $this->consoletools->primary($release->searchname).
Loading history...
950
                        $this->consoletools->headerOver('Use name:  ').
0 ignored issues
show
Bug introduced by
Are you sure $this->consoletools->headerOver('Use name: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

950
                        /** @scrutinizer ignore-type */ $this->consoletools->headerOver('Use name:  ').
Loading history...
Bug introduced by
Are you sure the usage of $this->consoletools->headerOver('Use name: ') targeting Blacklight\ColorCLI::headerOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
951
                        $this->consoletools->primary($release->name).
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->primary($release->name) targeting Blacklight\ColorCLI::primary() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $this->consoletools->primary($release->name) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

951
                        /** @scrutinizer ignore-type */ $this->consoletools->primary($release->name).
Loading history...
952
                        $this->consoletools->headerOver('New cat:   ').
0 ignored issues
show
Bug introduced by
Are you sure $this->consoletools->headerOver('New cat: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

952
                        /** @scrutinizer ignore-type */ $this->consoletools->headerOver('New cat:   ').
Loading history...
Bug introduced by
Are you sure the usage of $this->consoletools->headerOver('New cat: ') targeting Blacklight\ColorCLI::headerOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
953
                        $this->consoletools->primary($newCatName).
0 ignored issues
show
Bug introduced by
Are you sure $this->consoletools->primary($newCatName) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

953
                        /** @scrutinizer ignore-type */ $this->consoletools->primary($newCatName).
Loading history...
Bug introduced by
Are you sure the usage of $this->consoletools->primary($newCatName) targeting Blacklight\ColorCLI::primary() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
954
                        $this->consoletools->headerOver('Old cat:   ').
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->headerOver('Old cat: ') targeting Blacklight\ColorCLI::headerOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $this->consoletools->headerOver('Old cat: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

954
                        /** @scrutinizer ignore-type */ $this->consoletools->headerOver('Old cat:   ').
Loading history...
955
                        $this->consoletools->primary($oldCatName).
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->primary($oldCatName) targeting Blacklight\ColorCLI::primary() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $this->consoletools->primary($oldCatName) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

955
                        /** @scrutinizer ignore-type */ $this->consoletools->primary($oldCatName).
Loading history...
956
                        $this->consoletools->headerOver('Group:     ').
0 ignored issues
show
Bug introduced by
Are you sure $this->consoletools->headerOver('Group: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

956
                        /** @scrutinizer ignore-type */ $this->consoletools->headerOver('Group:     ').
Loading history...
Bug introduced by
Are you sure the usage of $this->consoletools->headerOver('Group: ') targeting Blacklight\ColorCLI::headerOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
957
                        $this->consoletools->primary($groupName).
0 ignored issues
show
Bug introduced by
Are you sure $this->consoletools->primary($groupName) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

957
                        /** @scrutinizer ignore-type */ $this->consoletools->primary($groupName).
Loading history...
Bug introduced by
Are you sure the usage of $this->consoletools->primary($groupName) targeting Blacklight\ColorCLI::primary() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
958
                        $this->consoletools->headerOver('Method:    ').
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->headerOver('Method: ') targeting Blacklight\ColorCLI::headerOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $this->consoletools->headerOver('Method: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

958
                        /** @scrutinizer ignore-type */ $this->consoletools->headerOver('Method:    ').
Loading history...
959
                        $this->consoletools->primary($type.$method).
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->primary($type . $method) targeting Blacklight\ColorCLI::primary() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $this->consoletools->primary($type . $method) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

959
                        /** @scrutinizer ignore-type */ $this->consoletools->primary($type.$method).
Loading history...
960
                        $this->consoletools->headerOver('Releases ID: ').
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->headerOver('Releases ID: ') targeting Blacklight\ColorCLI::headerOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $this->consoletools->headerOver('Releases ID: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

960
                        /** @scrutinizer ignore-type */ $this->consoletools->headerOver('Releases ID: ').
Loading history...
961
                        $this->consoletools->primary($release->releases_id);
0 ignored issues
show
Bug introduced by
Are you sure $this->consoletools->pri...($release->releases_id) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

961
                        /** @scrutinizer ignore-type */ $this->consoletools->primary($release->releases_id);
Loading history...
Bug introduced by
Are you sure the usage of $this->consoletools->pri...($release->releases_id) targeting Blacklight\ColorCLI::primary() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
962
                    if (! empty($release->filename)) {
963
                        $this->consoletools->headerOver('Filename:  ').
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->headerOver('Filename: ') targeting Blacklight\ColorCLI::headerOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $this->consoletools->headerOver('Filename: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

963
                        /** @scrutinizer ignore-type */ $this->consoletools->headerOver('Filename:  ').
Loading history...
964
                            $this->consoletools->primary($release->filename);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->consoletools->primary($release->filename) targeting Blacklight\ColorCLI::primary() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
965
                    }
966
967
                    if ($type !== 'PAR2, ') {
968
                        echo PHP_EOL;
969
                    }
970
                }
971
972
                $newTitle = substr($newName, 0, 299);
973
                $taggedRelease = Release::find($release->releases_id);
974
975
                if ($echo === true) {
976
                    if ($nameStatus === 1) {
977
                        $status = '';
978
                        switch ($type) {
979
                            case 'NFO, ':
980
                                $status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_nfo' => 1];
981
                                break;
982
                            case 'PAR2, ':
983
                                $status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_par2' => 1];
984
                                break;
985
                            case 'Filenames, ':
986
                            case 'file matched source: ':
987
                                $status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_files' => 1];
988
                                break;
989
                            case 'SHA1, ':
990
                            case 'MD5, ':
991
                                $status = ['isrenamed' => 1, 'iscategorized' => 1, 'dehashstatus' => 1];
992
                                break;
993
                            case 'PreDB FT Exact, ':
994
                                $status = ['isrenamed' => 1, 'iscategorized' => 1];
995
                                break;
996
                            case 'sorter, ':
997
                                $status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_sorter' => 1];
998
                                break;
999
                            case 'UID, ':
1000
                            case 'Mediainfo, ':
1001
                                $status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_uid' => 1];
1002
                                break;
1003
                            case 'PAR2 hash, ':
1004
                                $status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_hash16k' => 1];
1005
                                break;
1006
                            case 'SRR, ':
1007
                                $status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_srr' => 1];
1008
                                break;
1009
                            case 'CRC32, ':
1010
                                $status = ['isrenamed' => 1, 'iscategorized' => 1, 'proc_crc32' => 1];
1011
                                break;
1012
                        }
1013
1014
                        $updateColumns = [
1015
                            'videos_id' => 0,
1016
                            'tv_episodes_id' => 0,
1017
                            'imdbid' => null,
1018
                            'musicinfo_id' => null,
1019
                            'consoleinfo_id' => null,
1020
                            'bookinfo_id' => null,
1021
                            'anidbid' => null,
1022
                            'predb_id' => $preId,
1023
                            'searchname' => $newTitle,
1024
                            'categories_id' => $determinedCategory['categories_id'],
1025
                        ];
1026
1027
                        if ($status !== '') {
1028
                            foreach ($status as $key => $stat) {
1029
                                $updateColumns = Arr::add($updateColumns, $key, $stat);
1030
                            }
1031
                        }
1032
1033
                        $taggedRelease->update($updateColumns);
1034
                        $taggedRelease->retag($determinedCategory['tags']);
1035
                        if (config('nntmux.elasticsearch_enabled') === true) {
1036
                            $data = [
1037
                                'body' => [
1038
                                    'doc' => [
1039
                                        'searchname' => $newTitle,
1040
                                    ],
1041
                                ],
1042
1043
                                'index' => 'releases',
1044
                                'id' => $release->releases_id,
1045
                            ];
1046
1047
                            Elasticsearch::update($data);
0 ignored issues
show
Bug introduced by
The type Blacklight\Elasticsearch was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1048
                        } else {
1049
                            $this->sphinx->updateRelease($release->releases_id);
1050
                        }
1051
                    } else {
1052
                        $newTitle = substr($newName, 0, 299);
1053
1054
                        $release->update(
1055
                                [
1056
                                    'videos_id' => 0,
1057
                                    'tv_episodes_id' => 0,
1058
                                    'imdbid' => null,
1059
                                    'musicinfo_id' => null,
1060
                                    'consoleinfo_id' => null,
1061
                                    'bookinfo_id' => null,
1062
                                    'anidbid' => null,
1063
                                    'predb_id' => $preId,
1064
                                    'searchname' => $newTitle,
1065
                                    'categories_id' => $determinedCategory['categories_id'],
1066
                                    'iscategorized' => 1,
1067
                                ]
1068
                            );
1069
                        $taggedRelease->retag($determinedCategory['tags']);
1070
                        if (config('nntmux.elasticsearch_enabled') === true) {
1071
                            $new = Release::query()
1072
                                ->where('releases.id', $release->releases_id)
1073
                                ->leftJoin('release_files as rf', 'releases.id', '=', 'rf.releases_id')
1074
                                ->select(['releases.id', 'releases.name', 'releases.searchname', 'releases.fromname', DB::raw('IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename')])
1075
                                ->groupBy('releases.id')
1076
                                ->first();
1077
                            if ($new !== null) {
1078
                                $data = [
1079
                                    'body' => [
1080
                                        'doc' => [
1081
                                            'searchname' => $newTitle,
1082
                                            'filename' => ! empty($new->filename) ? $new->filename : '',
0 ignored issues
show
Bug introduced by
The property filename does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
1083
                                        ],
1084
                                    ],
1085
1086
                                    'index' => 'releases',
1087
                                    'id' => $release->releases_id,
1088
                                ];
1089
1090
                                Elasticsearch::update($data);
1091
                            }
1092
                        } else {
1093
                            $this->sphinx->updateRelease($release->releases_id);
1094
                        }
1095
                    }
1096
                }
1097
            }
1098
        }
1099
        $this->done = true;
1100
    }
1101
1102
    /**
1103
     * Echo a updated release name to CLI.
1104
     *
1105
     * @param array $data
1106
     *              array(
1107
     *              'new_name'     => (string) The new release search name.
1108
     *              'old_name'     => (string) The old release search name.
1109
     *              'new_category' => (string) The new category name or ID for the release.
1110
     *              'old_category' => (string) The old category name or ID for the release.
1111
     *              'group'        => (string) The group name or ID of the release.
1112
     *              'release_id'   => (int)    The ID of the release.
1113
     *              'method'       => (string) The method used to rename the release.
1114
     *              )
1115
     *
1116
     * @static
1117
     * @void
1118
     */
1119
    public static function echoChangedReleaseName(
1120
        array $data =
1121
        [
1122
            'new_name'     => '',
1123
            'old_name'     => '',
1124
            'new_category' => '',
1125
            'old_category' => '',
1126
            'group'        => '',
1127
            'releases_id'   => 0,
1128
            'method'       => '',
1129
        ]
1130
    ): void {
1131
        $colorCLI = new ColorCLI();
1132
        echo PHP_EOL;
1133
1134
        $colorCLI->header('New name:     ').$colorCLI->primaryOver($data['new_name']).
0 ignored issues
show
Bug introduced by
Are you sure the usage of $colorCLI->primaryOver($data['new_name']) targeting Blacklight\ColorCLI::primaryOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $colorCLI->header('New name: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1134
        /** @scrutinizer ignore-type */ $colorCLI->header('New name:     ').$colorCLI->primaryOver($data['new_name']).
Loading history...
Bug introduced by
Are you sure the usage of $colorCLI->header('New name: ') targeting Blacklight\ColorCLI::header() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1135
            $colorCLI->header('Old name:     ').$colorCLI->primaryOver($data['old_name']).
0 ignored issues
show
Bug introduced by
Are you sure the usage of $colorCLI->header('Old name: ') targeting Blacklight\ColorCLI::header() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $colorCLI->header('Old name: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1135
            /** @scrutinizer ignore-type */ $colorCLI->header('Old name:     ').$colorCLI->primaryOver($data['old_name']).
Loading history...
Bug introduced by
Are you sure $colorCLI->primaryOver($data['old_name']) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1135
            $colorCLI->header('Old name:     ')./** @scrutinizer ignore-type */ $colorCLI->primaryOver($data['old_name']).
Loading history...
Bug introduced by
Are you sure the usage of $colorCLI->primaryOver($data['old_name']) targeting Blacklight\ColorCLI::primaryOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1136
            $colorCLI->header('New category: ').$colorCLI->primaryOver($data['new_category']).
0 ignored issues
show
Bug introduced by
Are you sure the usage of $colorCLI->primaryOver($data['new_category']) targeting Blacklight\ColorCLI::primaryOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $colorCLI->header('New category: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1136
            /** @scrutinizer ignore-type */ $colorCLI->header('New category: ').$colorCLI->primaryOver($data['new_category']).
Loading history...
Bug introduced by
Are you sure $colorCLI->primaryOver($data['new_category']) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1136
            $colorCLI->header('New category: ')./** @scrutinizer ignore-type */ $colorCLI->primaryOver($data['new_category']).
Loading history...
Bug introduced by
Are you sure the usage of $colorCLI->header('New category: ') targeting Blacklight\ColorCLI::header() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1137
            $colorCLI->header('Old category: ').$colorCLI->primaryOver($data['old_category']).
0 ignored issues
show
Bug introduced by
Are you sure the usage of $colorCLI->primaryOver($data['old_category']) targeting Blacklight\ColorCLI::primaryOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $colorCLI->header('Old category: ') targeting Blacklight\ColorCLI::header() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $colorCLI->primaryOver($data['old_category']) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1137
            $colorCLI->header('Old category: ')./** @scrutinizer ignore-type */ $colorCLI->primaryOver($data['old_category']).
Loading history...
Bug introduced by
Are you sure $colorCLI->header('Old category: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1137
            /** @scrutinizer ignore-type */ $colorCLI->header('Old category: ').$colorCLI->primaryOver($data['old_category']).
Loading history...
1138
            $colorCLI->header('Group:        ').$colorCLI->primaryOver($data['group']).
0 ignored issues
show
Bug introduced by
Are you sure $colorCLI->primaryOver($data['group']) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1138
            $colorCLI->header('Group:        ')./** @scrutinizer ignore-type */ $colorCLI->primaryOver($data['group']).
Loading history...
Bug introduced by
Are you sure $colorCLI->header('Group: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1138
            /** @scrutinizer ignore-type */ $colorCLI->header('Group:        ').$colorCLI->primaryOver($data['group']).
Loading history...
Bug introduced by
Are you sure the usage of $colorCLI->header('Group: ') targeting Blacklight\ColorCLI::header() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $colorCLI->primaryOver($data['group']) targeting Blacklight\ColorCLI::primaryOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1139
            $colorCLI->header('Releases ID:   ').$colorCLI->primaryOver($data['releases_id']).
0 ignored issues
show
Bug introduced by
Are you sure $colorCLI->header('Releases ID: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1139
            /** @scrutinizer ignore-type */ $colorCLI->header('Releases ID:   ').$colorCLI->primaryOver($data['releases_id']).
Loading history...
Bug introduced by
Are you sure $colorCLI->primaryOver($data['releases_id']) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1139
            $colorCLI->header('Releases ID:   ')./** @scrutinizer ignore-type */ $colorCLI->primaryOver($data['releases_id']).
Loading history...
Bug introduced by
Are you sure the usage of $colorCLI->primaryOver($data['releases_id']) targeting Blacklight\ColorCLI::primaryOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $colorCLI->header('Releases ID: ') targeting Blacklight\ColorCLI::header() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1140
            $colorCLI->header('Method:       ').$colorCLI->primaryOver($data['method']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $colorCLI->primaryOver($data['method']) targeting Blacklight\ColorCLI::primaryOver() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $colorCLI->header('Method: ') targeting Blacklight\ColorCLI::header() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure $colorCLI->header('Method: ') of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1140
            /** @scrutinizer ignore-type */ $colorCLI->header('Method:       ').$colorCLI->primaryOver($data['method']);
Loading history...
Bug introduced by
Are you sure $colorCLI->primaryOver($data['method']) of type void can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1140
            $colorCLI->header('Method:       ')./** @scrutinizer ignore-type */ $colorCLI->primaryOver($data['method']);
Loading history...
1141
    }
1142
1143
    /**
1144
     * Match a PreDB title to a release name or searchname using an exact full-text match.
1145
     *
1146
     * @param $pre
1147
     * @param $echo
1148
     * @param $nameStatus
1149
     * @param $show
1150
     *
1151
     * @return int
1152
     * @throws \Exception
1153
     */
1154
    public function matchPredbFT($pre, $echo, $nameStatus, $show): int
1155
    {
1156
        $matching = $total = 0;
1157
1158
        $join = $this->_preFTsearchQuery($pre['title']);
1159
1160
        if ($join === '') {
1161
            return $matching;
1162
        }
1163
1164
        //Find release matches with fulltext and then identify exact matches with cleaned LIKE string
1165
        $res = Release::fromQuery(
1166
            sprintf(
1167
                '
1168
				SELECT r.id AS releases_id, r.name, r.searchname,
1169
				r.fromname, r.groups_id, r.categories_id
1170
				FROM releases r
1171
				WHERE r.id IN (%s)
1172
				AND r.predb_id = 0',
1173
                $join
1174
            )
1175
        );
1176
1177
        if (! empty($res)) {
1178
            $total = \count($res);
1179
        }
1180
1181
        // Run if row count is positive, but do not run if row count exceeds 10 (as this is likely a failed title match)
1182
        if ($total > 0 && $total <= 15) {
1183
            foreach ($res as $row) {
1184
                if ($pre['title'] !== $row->searchname) {
1185
                    $this->updateRelease($row, $pre['title'], 'Title Match source: '.$pre['source'], $echo, 'PreDB FT Exact, ', $nameStatus, $show, $pre['predb_id']);
1186
                    $matching++;
1187
                } else {
1188
                    $this->_updateSingleColumn('predb_id', $pre['predb_id'], $row->releases_id);
0 ignored issues
show
Bug introduced by
The property releases_id does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
1189
                }
1190
            }
1191
        } elseif ($total >= 16) {
1192
            $matching = -1;
1193
        }
1194
1195
        return $matching;
1196
    }
1197
1198
    /**
1199
     * @param $preTitle
1200
     *
1201
     * @return string
1202
     */
1203
    protected function _preFTsearchQuery($preTitle): string
1204
    {
1205
        $join = '';
1206
1207
        if (\strlen($preTitle) >= 15 && preg_match(self::PREDB_REGEX, $preTitle)) {
1208
            $titlematch = $this->sphinx->searchIndexes('releases_rt', $preTitle, ['name', 'searchname', 'filename']);
1209
            if (! empty($titlematch)) {
1210
                $join = implode(',', Arr::pluck($titlematch, 'id'));
1211
            }
1212
        }
1213
1214
        return $join;
1215
    }
1216
1217
    /**
1218
     * Retrieves releases and their file names to attempt PreDB matches
1219
     * Runs in a limited mode based on arguments passed or a full mode broken into chunks of entire DB.
1220
     *
1221
     * @param array $args The CLI script arguments
1222
     * @throws \Exception
1223
     */
1224
    public function getPreFileNames(array $args = []): void
1225
    {
1226
        $show = isset($args[2]) && $args[2] === 'show';
1227
1228
        if (isset($args[1]) && is_numeric($args[1])) {
1229
            $limit = 'LIMIT '.$args[1];
1230
            $orderby = 'ORDER BY r.id DESC';
1231
        } else {
1232
            $orderby = 'ORDER BY r.id ASC';
1233
            $limit = 'LIMIT 1000000';
1234
        }
1235
1236
        $this->consoletools->header(PHP_EOL.'Match PreFiles '.$args[1].' Started at '.now());
1237
        $this->consoletools->primary('Matching predb filename to cleaned release_files.name.');
1238
1239
        $counter = $counted = 0;
1240
        $timestart = now();
1241
1242
        $query = Release::fromQuery(
1243
            sprintf(
1244
                "
1245
					SELECT r.id AS releases_id, r.name, r.searchname,
1246
						r.fromname, r.groups_id, r.categories_id,
1247
						GROUP_CONCAT(rf.name ORDER BY LENGTH(rf.name) DESC SEPARATOR '||') AS filename
1248
					FROM releases r
1249
					INNER JOIN release_files rf ON r.id = rf.releases_id
1250
					WHERE rf.name IS NOT NULL
1251
					AND r.predb_id = 0
1252
					AND r.categories_id IN (%s)
1253
					AND r.isrenamed = 0
1254
					GROUP BY r.id
1255
					%s %s",
1256
                implode(',', Category::OTHERS_GROUP),
1257
                $orderby,
1258
                $limit
1259
            )
1260
        );
1261
1262
        if (! empty($query)) {
1263
            $total = \count($query);
1264
1265
            if ($total > 0) {
1266
                $this->consoletools->header(PHP_EOL.number_format($total).' releases to process.');
1267
1268
                foreach ($query as $row) {
1269
                    $success = $this->matchPreDbFiles($row, true, 1, $show);
1270
                    if ($success === 1) {
1271
                        $counted++;
1272
                    }
1273
                    if ($show === 0) {
1274
                        $this->consoletools->overWritePrimary('Renamed Releases: ['.number_format($counted).'] '.$this->consoletools->percentString(++$counter, $total));
1275
                    }
1276
                }
1277
                $this->consoletools->header(PHP_EOL.'Renamed '.number_format($counted).' releases in '.now()->diffInSeconds($timestart).' seconds'.'.');
1278
            } else {
1279
                $this->consoletools->info('Nothing to do.');
1280
            }
1281
        }
1282
    }
1283
1284
    /**
1285
     * Match a release filename to a PreDB filename or title.
1286
     *
1287
     * @param         $release
1288
     * @param bool $echo
1289
     * @param int $nameStatus
1290
     * @param bool $show
1291
     *
1292
     * @return int
1293
     * @throws \Exception
1294
     */
1295
    public function matchPreDbFiles($release, $echo, $nameStatus, $show): int
1296
    {
1297
        $matching = 0;
1298
1299
        foreach (explode('||', $release->filename) as $key => $fileName) {
1300
            $this->_fileName = $fileName;
1301
            $this->_cleanMatchFiles();
1302
            $preMatch = $this->preMatch($this->_fileName);
1303
            if ($preMatch[0] === true) {
1304
                if (config('nntmux.elasticsearch_enabled') === true) {
1305
                    $search = [
1306
                        'index' => 'predb',
1307
                        'body' => [
1308
                            'query' => [
1309
                                'multi_match' => [
1310
                                    'query' => $preMatch[1],
1311
                                    'fields' => ['filename', 'title'],
1312
                                ]
1313
                            ]
1314
                        ]
1315
                    ];
1316
1317
                    $primaryResults = \Elasticsearch::search($search);
1318
1319
                    $results = [];
1320
                    foreach ($primaryResults['hits']['hits'] as $primaryResult) {
1321
                        $results[] = $primaryResult['_source'];
1322
                    }
1323
                } else {
1324
                    $results = $this->sphinx->searchIndexes('predb_rt', $preMatch[1], ['filename', 'title']);
1325
                }
1326
                if (! empty($results)) {
1327
                    foreach ($results as $result) {
1328
                        if (! empty($result)) {
1329
                            $preFtMatch = $this->preMatch($result['filename']);
1330
                            if ($preFtMatch[0] === true) {
1331
                                $this->_fileName = $result['filename'];
1332
                                $release->filename = $this->_fileName;
1333
                                if ($result['title'] !== $release->searchname) {
1334
                                    $this->updateRelease($release, $result['title'], 'file matched source: '.$result['source'], $echo, 'PreDB file match, ', $nameStatus, $show, $result['id']);
1335
                                } else {
1336
                                    $this->_updateSingleColumn('predb_id', $result['id'], $release->releases_id);
1337
                                }
1338
                                $matching++;
1339
                                break;
1340
                            }
1341
                        }
1342
                    }
1343
                }
1344
            }
1345
        }
1346
1347
        return $matching;
1348
    }
1349
1350
    /**
1351
     * Cleans file names for PreDB Match.
1352
     *
1353
     *
1354
     * @return string
1355
     */
1356
    protected function _cleanMatchFiles(): string
1357
    {
1358
1359
        // first strip all non-printing chars  from filename
1360
        $this->_fileName = Utility::stripNonPrintingChars($this->_fileName);
1361
1362
        if ($this->_fileName !== '' && strpos($this->_fileName, '.') !== 0) {
1363
            switch (true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/^\d{2}-/', $this->_fileName) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/\.part\d+$/', $this->_fileName) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/\.vol\d+(\+...?$/', $this->_fileName) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
1364
1365
                case strpos($this->_fileName, '.') !== false:
1366
                    //some filenames start with a period that ends up creating bad matches so we don't process them
1367
                    $this->_fileName = Utility::cutStringUsingLast('.', $this->_fileName, 'left', false);
1368
                    break;
1369
1370
                //if filename has a .part001, send it back to the function to cut the next period
1371
                case preg_match('/\.part\d+$/', $this->_fileName):
1372
                    $this->_fileName = Utility::cutStringUsingLast('.', $this->_fileName, 'left', false);
1373
                    break;
1374
1375
                //if filename has a .vol001, send it back to the function to cut the next period
1376
                case preg_match('/\.vol\d+(\+\d+)?$/', $this->_fileName):
1377
                    $this->_fileName = Utility::cutStringUsingLast('.', $this->_fileName, 'left', false);
1378
                    break;
1379
1380
                //if filename contains a slash, cut the string and keep string to the right of the last slash to remove dir
1381
                case strpos($this->_fileName, '\\') !== false:
1382
                    $this->_fileName = Utility::cutStringUsingLast('\\', $this->_fileName, 'right', false);
1383
                    break;
1384
1385
                // A lot of obscured releases have one NFO file properly named with a track number (Audio) at the front of it
1386
                // This will strip out the track and match it to its pre title
1387
                case preg_match('/^\d{2}-/', $this->_fileName):
1388
                    $this->_fileName = preg_replace('/^\d{2}-/', '', $this->_fileName);
1389
            }
1390
1391
            return trim($this->_fileName);
1392
        }
1393
1394
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the type-hinted return string.
Loading history...
1395
    }
1396
1397
    /**
1398
     * Match a Hash from the predb to a release.
1399
     *
1400
     * @param string $hash
1401
     * @param         $release
1402
     * @param         $echo
1403
     * @param         $nameStatus
1404
     * @param         $show
1405
     *
1406
     * @return int
1407
     * @throws \Exception
1408
     */
1409
    public function matchPredbHash($hash, $release, $echo, $nameStatus, $show): int
1410
    {
1411
        $matching = 0;
1412
        $this->matched = false;
1413
1414
        // Determine MD5 or SHA1
1415
        if (\strlen($hash) === 40) {
1416
            $hashtype = 'SHA1, ';
1417
        } else {
1418
            $hashtype = 'MD5, ';
1419
        }
1420
1421
        $row = Predb::fromQuery(
1422
            sprintf(
1423
                '
1424
						SELECT p.id AS predb_id, p.title, p.source
1425
						FROM predb p INNER JOIN predb_hashes h ON h.predb_id = p.id
1426
						WHERE h.hash = UNHEX(%s)
1427
						LIMIT 1',
1428
                escapeString($hash)
1429
            )
1430
        );
1431
1432
        foreach ($row as $item) {
1433
            if (! empty($item)) {
1434
                if ($item->title !== $release->searchname) {
1435
                    $this->updateRelease($release, $item->title, 'predb hash release name: '.$item->source, $echo, $hashtype, $nameStatus, $show, $item->predb_id);
0 ignored issues
show
Bug introduced by
The property predb_id does not seem to exist on App\Models\Predb. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
1436
                    $matching++;
1437
                }
1438
            } else {
1439
                $this->_updateSingleColumn('dehashstatus', $release->dehashstatus - 1, $release->releases_id);
1440
            }
1441
        }
1442
1443
        return $matching;
1444
    }
1445
1446
    /**
1447
     * Matches the hashes within the predb table to release files and subjects (names) which are hashed.
1448
     *
1449
     * @param $time
1450
     * @param $echo
1451
     * @param $cats
1452
     * @param $nameStatus
1453
     * @param $show
1454
     *
1455
     * @return int
1456
     * @throws \Exception
1457
     */
1458
    public function parseTitles($time, $echo, $cats, $nameStatus, $show): int
1459
    {
1460
        $updated = $checked = 0;
1461
1462
        $tq = '';
1463
        if ($time === 1) {
1464
            $tq = 'AND r.adddate > (NOW() - INTERVAL 3 HOUR) ORDER BY rf.releases_id, rf.size DESC';
1465
        }
1466
        $ct = '';
1467
        if ($cats === 1) {
1468
            $ct = sprintf('AND r.categories_id IN (%s)', $this->othercats);
1469
        }
1470
1471
        if ($this->echooutput) {
1472
            $te = '';
1473
            if ($time === 1) {
1474
                $te = ' in the past 3 hours';
1475
            }
1476
            $this->consoletools->header('Fixing search names'.$te.' using the predb hash.');
1477
        }
1478
        $regex = 'AND (r.ishashed = 1 OR rf.ishashed = 1)';
1479
1480
        if ($cats === 3) {
1481
            $query = sprintf('SELECT r.id AS releases_id, r.name, r.searchname, r.categories_id, r.groups_id, '
1482
                .'dehashstatus, rf.name AS filename FROM releases r '
1483
                .'LEFT OUTER JOIN release_files rf ON r.id = rf.releases_id '
1484
                .'WHERE nzbstatus = 1 AND dehashstatus BETWEEN -6 AND 0 AND predb_id = 0 %s', $regex);
1485
        } else {
1486
            $query = sprintf('SELECT r.id AS releases_id, r.name, r.searchname, r.categories_id, r.groups_id, '
1487
                .'dehashstatus, rf.name AS filename FROM releases r '
1488
                .'LEFT OUTER JOIN release_files rf ON r.id = rf.releases_id '
1489
                .'WHERE nzbstatus = 1 AND isrenamed = 0 AND dehashstatus BETWEEN -6 AND 0 %s %s %s', $regex, $ct, $tq);
1490
        }
1491
1492
        $res = Release::fromQuery($query);
1493
        $total = \count($res);
1494
        $this->consoletools->primary(number_format($total).' releases to process.');
1495
        foreach ($res as $row) {
1496
            if (preg_match('/[a-fA-F0-9]{32,40}/i', $row->name, $matches)) {
1497
                $updated += $this->matchPredbHash($matches[0], $row, $echo, $nameStatus, $show);
1498
            } elseif (preg_match('/[a-fA-F0-9]{32,40}/i', $row->filename, $matches)) {
0 ignored issues
show
Bug introduced by
The property filename does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
1499
                $updated += $this->matchPredbHash($matches[0], $row, $echo, $nameStatus, $show);
1500
            }
1501
            if ($show === 2) {
1502
                $this->consoletools->overWritePrimary('Renamed Releases: ['.number_format($updated).'] '.$this->consoletools->percentString($checked++, $total));
1503
            }
1504
        }
1505
        if ($echo === 1) {
1506
            $this->consoletools->header(PHP_EOL.$updated.' releases have had their names changed out of: '.number_format($checked).' files.');
1507
        } else {
1508
            $this->consoletools->header(PHP_EOL.$updated.' releases could have their names changed. '.number_format($checked).' files were checked.');
1509
        }
1510
1511
        return $updated;
1512
    }
1513
1514
    /**
1515
     * Check the array using regex for a clean name.
1516
     *
1517
     * @param         $release
1518
     * @param bool $echo
1519
     * @param string $type
1520
     * @param int $nameStatus
1521
     * @param bool $show
1522
     * @param bool $preid
1523
     *
1524
     * @return bool
1525
     * @throws \Exception
1526
     */
1527
    public function checkName($release, $echo, $type, $nameStatus, $show, $preid = false): bool
1528
    {
1529
        // Get pre style name from releases.name
1530
        if (preg_match_all(self::PREDB_REGEX, $release->textstring, $matches) && ! preg_match('/Source\s\:/i', $release->textstring)) {
1531
            foreach ($matches as $match) {
1532
                foreach ($match as $val) {
1533
                    $title = Predb::query()->where('title', trim($val))->select(['title', 'id'])->first();
1534
                    if ($title !== null) {
1535
                        $this->updateRelease($release, $title['title'], 'preDB: Match', $echo, $type, $nameStatus, $show, $title['id']);
1536
                        $preid = true;
1537
                    }
1538
                }
1539
            }
1540
        }
1541
1542
        // if only processing for PreDB match skip to return
1543
        if (! $preid) {
1544
            switch ($type) {
1545
                case 'PAR2, ':
1546
                    $this->fileCheck($release, $echo, $type, $nameStatus, $show);
1547
                    break;
1548
                case 'PAR2 hash, ':
1549
                    $this->hashCheck($release, $echo, $type, $nameStatus, $show);
1550
                    break;
1551
                case 'UID, ':
1552
                    $this->uidCheck($release, $echo, $type, $nameStatus, $show);
1553
                    break;
1554
                case 'Mediainfo, ':
1555
                    $this->mediaMovieNameCheck($release, $echo, $type, $nameStatus, $show);
1556
                    break;
1557
                case 'SRR, ':
1558
                    $this->srrNameCheck($release, $echo, $type, $nameStatus, $show);
1559
                    break;
1560
                case 'CRC32, ':
1561
                    $this->crcCheck($release, $echo, $type, $nameStatus, $show);
1562
                    break;
1563
                case 'NFO, ':
1564
                    $this->nfoCheckTV($release, $echo, $type, $nameStatus, $show);
1565
                    $this->nfoCheckMov($release, $echo, $type, $nameStatus, $show);
1566
                    $this->nfoCheckMus($release, $echo, $type, $nameStatus, $show);
1567
                    $this->nfoCheckTY($release, $echo, $type, $nameStatus, $show);
1568
                    $this->nfoCheckG($release, $echo, $type, $nameStatus, $show);
1569
                    break;
1570
                case 'Filenames, ':
1571
                    $this->preDbFileCheck($release, $echo, $type, $nameStatus, $show);
1572
                    $this->preDbTitleCheck($release, $echo, $type, $nameStatus, $show);
1573
                    $this->fileCheck($release, $echo, $type, $nameStatus, $show);
1574
                    break;
1575
                default:
1576
                    $this->tvCheck($release, $echo, $type, $nameStatus, $show);
1577
                    $this->movieCheck($release, $echo, $type, $nameStatus, $show);
1578
                    $this->gameCheck($release, $echo, $type, $nameStatus, $show);
1579
                    $this->appCheck($release, $echo, $type, $nameStatus, $show);
1580
            }
1581
1582
            // set NameFixer process flags after run
1583
            if ($nameStatus === 1 && ! $this->matched) {
1584
                switch ($type) {
1585
                    case 'NFO, ':
1586
                        $this->_updateSingleColumn('proc_nfo', self::PROC_NFO_DONE, $release->releases_id);
1587
                        break;
1588
                    case 'Filenames, ':
1589
                        $this->_updateSingleColumn('proc_files', self::PROC_FILES_DONE, $release->releases_id);
1590
                        break;
1591
                    case 'PAR2, ':
1592
                        $this->_updateSingleColumn('proc_par2', self::PROC_PAR2_DONE, $release->releases_id);
1593
                        break;
1594
                    case 'PAR2 hash, ':
1595
                        $this->_updateSingleColumn('proc_hash16k', self::PROC_HASH16K_DONE, $release->releases_id);
1596
                        break;
1597
                    case 'SRR, ':
1598
                        $this->_updateSingleColumn('proc_srr', self::PROC_SRR_DONE, $release->releases_id);
1599
                        break;
1600
                    case 'UID, ':
1601
                        $this->_updateSingleColumn('proc_uid', self::PROC_UID_DONE, $release->releases_id);
1602
                        break;
1603
                }
1604
            }
1605
        }
1606
1607
        return $this->matched;
1608
    }
1609
1610
    /** This function updates a single variable column in releases
1611
     *  The first parameter is the column to update, the second is the value
1612
     *  The final parameter is the ID of the release to update.
1613
     *
1614
     * @param string  $column
1615
     * @param int $status
1616
     * @param int $id
1617
     */
1618
    public function _updateSingleColumn($column = '', $status = 0, $id = 0): void
1619
    {
1620
        if ((string) $column !== '' && (int) $id !== 0) {
1621
            Release::query()->where('id', $id)->update([$column => $status]);
1622
        }
1623
    }
1624
1625
    /**
1626
     * Look for a TV name.
1627
     *
1628
     * @param         $release
1629
     * @param bool $echo
1630
     * @param string $type
1631
     * @param         $nameStatus
1632
     * @param         $show
1633
     * @throws \Exception
1634
     */
1635
    public function tvCheck($release, $echo, $type, $nameStatus, $show): void
1636
    {
1637
        $result = [];
1638
1639
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1640
            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)) {
1641
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.Text.source.group', $echo, $type, $nameStatus, $show);
1642
            } 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)) {
1643
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.Text.year.group', $echo, $type, $nameStatus, $show);
1644
            } 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)) {
1645
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.Text.resolution.source.vcodec.group', $echo, $type, $nameStatus, $show);
1646
            } 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)) {
1647
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.source.vcodec.group', $echo, $type, $nameStatus, $show);
1648
            } 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)) {
1649
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.acodec.source.res.vcodec.group', $echo, $type, $nameStatus, $show);
1650
            } 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)) {
1651
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.year.###(season/episode).source.group', $echo, $type, $nameStatus, $show);
1652
            } 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)) {
1653
                $this->updateRelease($release, $result['0'], 'tvCheck: Sports', $echo, $type, $nameStatus, $show);
1654
            }
1655
        }
1656
    }
1657
1658
    /**
1659
     * Look for a movie name.
1660
     *
1661
     * @param         $release
1662
     * @param bool $echo
1663
     * @param string $type
1664
     * @param         $nameStatus
1665
     * @param         $show
1666
     * @throws \Exception
1667
     */
1668
    public function movieCheck($release, $echo, $type, $nameStatus, $show): void
1669
    {
1670
        $result = [];
1671
1672
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1673
            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)) {
1674
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.Text.res.vcod.group', $echo, $type, $nameStatus, $show);
1675
            } 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)) {
1676
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.vcodec.res.group', $echo, $type, $nameStatus, $show);
1677
            } 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)) {
1678
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.vcodec.acodec.group', $echo, $type, $nameStatus, $show);
1679
            } 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)) {
1680
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.language.acodec.source.vcodec.group', $echo, $type, $nameStatus, $show);
1681
            } 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)) {
1682
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.resolution.source.acodec.vcodec.group', $echo, $type, $nameStatus, $show);
1683
            } 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)) {
1684
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.resolution.source.vcodec.group', $echo, $type, $nameStatus, $show);
1685
            } 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)) {
1686
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.resolution.acodec.vcodec.group', $echo, $type, $nameStatus, $show);
1687
            } 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)) {
1688
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.resolution.acodec.vcodec.group', $echo, $type, $nameStatus, $show);
1689
            } 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)) {
1690
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.res.group', $echo, $type, $nameStatus, $show);
1691
            } 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)) {
1692
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.eptitle.source.vcodec.group', $echo, $type, $nameStatus, $show);
1693
            } 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)) {
1694
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.resolution.source.acodec.vcodec.group', $echo, $type, $nameStatus, $show);
1695
            } 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)) {
1696
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.resolution.acodec.eptitle.source.year.group', $echo, $type, $nameStatus, $show);
1697
            } 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)) {
1698
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.language.year.acodec.src', $echo, $type, $nameStatus, $show);
1699
            }
1700
        }
1701
    }
1702
1703
    /**
1704
     * Look for a game name.
1705
     *
1706
     * @param         $release
1707
     * @param bool $echo
1708
     * @param string $type
1709
     * @param         $nameStatus
1710
     * @param         $show
1711
     * @throws \Exception
1712
     */
1713
    public function gameCheck($release, $echo, $type, $nameStatus, $show): void
1714
    {
1715
        $result = [];
1716
1717
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1718
            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)) {
1719
                $this->updateRelease($release, $result['0'], 'gameCheck: Videogames 1', $echo, $type, $nameStatus, $show);
1720
            } elseif (preg_match('/\w[\-\w.\',;& ]+(GC|NDS|NGC|PS3|WII|XBOX(360)?)[._ -](DUPLEX|iNSOMNi|OneUp|STRANGE|SWAG|SKY)[\-\w.\',;& ]+\w/i', $release->textstring, $result)) {
1721
                $this->updateRelease($release, $result['0'], 'gameCheck: Videogames 2', $echo, $type, $nameStatus, $show);
1722
            } elseif (preg_match('/\w[\w.\',;-].+-OUTLAWS/i', $release->textstring, $result)) {
1723
                $result = str_replace('OUTLAWS', 'PC GAME OUTLAWS', $result['0']);
1724
                $this->updateRelease($release, $result['0'], 'gameCheck: PC Games -OUTLAWS', $echo, $type, $nameStatus, $show);
1725
            } elseif (preg_match('/\w[\w.\',;-].+\-ALiAS/i', $release->textstring, $result)) {
1726
                $newresult = str_replace('-ALiAS', ' PC GAME ALiAS', $result['0']);
1727
                $this->updateRelease($release, $newresult, 'gameCheck: PC Games -ALiAS', $echo, $type, $nameStatus, $show);
1728
            }
1729
        }
1730
    }
1731
1732
    /**
1733
     * Look for a app name.
1734
     *
1735
     * @param         $release
1736
     * @param bool $echo
1737
     * @param string $type
1738
     * @param         $nameStatus
1739
     * @param         $show
1740
     * @throws \Exception
1741
     */
1742
    public function appCheck($release, $echo, $type, $nameStatus, $show): void
1743
    {
1744
        $result = [];
1745
1746
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1747
            if (preg_match('/\w[\-\w.\',;& ]+(\d{1,10}|Linux|UNIX)[._ -](RPM)?[._ -]?(X64)?[._ -]?(Incl)[._ -](Keygen)[\-\w.\',;& ]+\w/i', $release->textstring, $result)) {
1748
                $this->updateRelease($release, $result['0'], 'appCheck: Apps 1', $echo, $type, $nameStatus, $show);
1749
            } elseif (preg_match('/\w[\-\w.\',;& ]+\d{1,8}[._ -](winall-freeware)[\-\w.\',;& ]+\w/i', $release->textstring, $result)) {
1750
                $this->updateRelease($release, $result['0'], 'appCheck: Apps 2', $echo, $type, $nameStatus, $show);
1751
            }
1752
        }
1753
    }
1754
1755
    /**
1756
     * TV.
1757
     *
1758
     * @param         $release
1759
     * @param bool $echo
1760
     * @param string $type
1761
     * @param         $nameStatus
1762
     * @param         $show
1763
     * @throws \Exception
1764
     */
1765
    public function nfoCheckTV($release, $echo, $type, $nameStatus, $show): void
1766
    {
1767
        $result = [];
1768
1769
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1770
            if (preg_match('/:\s*.*[\\\\\/]([A-Z0-9].+?S\d+[.-_ ]?[ED]\d+.+?)\.\w{2,}\s+/i', $release->textstring, $result)) {
1771
                $this->updateRelease($release, $result['1'], 'nfoCheck: Generic TV 1', $echo, $type, $nameStatus, $show);
1772
            } elseif (preg_match('/(?:(\:\s{1,}))(.+?S\d{1,3}[.-_ ]?[ED]\d{1,3}.+?)(\s{2,}|\r|\n)/i', $release->textstring, $result)) {
1773
                $this->updateRelease($release, $result['2'], 'nfoCheck: Generic TV 2', $echo, $type, $nameStatus, $show);
1774
            }
1775
        }
1776
    }
1777
1778
    /**
1779
     * Movies.
1780
     *
1781
     * @param         $release
1782
     * @param bool $echo
1783
     * @param string $type
1784
     * @param         $nameStatus
1785
     * @param         $show
1786
     * @throws \Exception
1787
     */
1788
    public function nfoCheckMov($release, $echo, $type, $nameStatus, $show): void
1789
    {
1790
        $result = [];
1791
1792
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1793
            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)) {
1794
                $this->updateRelease($release, $result['2'], 'nfoCheck: Generic Movies 1', $echo, $type, $nameStatus, $show);
1795
            } elseif (preg_match('/(?:(\s{2,}))((?!Source).+?[\.\-_ ](19|20)\d\d.+?(BDRip|bluray|DVD(R|Rip)?|XVID).+?)(\s{2,}|\r|\n)/i', $release->textstring, $result)) {
1796
                $this->updateRelease($release, $result['2'], 'nfoCheck: Generic Movies 2', $echo, $type, $nameStatus, $show);
1797
            } elseif (preg_match('/(?:(\s{2,}))(.+?[\.\-_ ](NTSC|MULTi).+?(MULTi|DVDR)[\.\-_ ].+?)(\s{2,}|\r|\n)/i', $release->textstring, $result)) {
1798
                $this->updateRelease($release, $result['2'], 'nfoCheck: Generic Movies 3', $echo, $type, $nameStatus, $show);
1799
            }
1800
        }
1801
    }
1802
1803
    /**
1804
     * @param         $release
1805
     * @param bool $echo
1806
     * @param string $type
1807
     * @param         $nameStatus
1808
     * @param         $show
1809
     * @throws \Exception
1810
     */
1811
    public function nfoCheckMus($release, $echo, $type, $nameStatus, $show): void
1812
    {
1813
        $result = [];
1814
1815
        if (! $this->done && $this->relid !== (int) $release->releases_id && preg_match('/(?:\s{2,})(.+?-FM-\d{2}-\d{2})/i', $release->textstring, $result)) {
1816
            $newname = str_replace('-FM-', '-FM-Radio-MP3-', $result['1']);
1817
            $this->updateRelease($release, $newname, 'nfoCheck: Music FM RADIO', $echo, $type, $nameStatus, $show);
1818
        }
1819
    }
1820
1821
    /**
1822
     * Title (year).
1823
     *
1824
     * @param         $release
1825
     * @param bool $echo
1826
     * @param string $type
1827
     * @param         $nameStatus
1828
     * @param         $show
1829
     * @throws \Exception
1830
     */
1831
    public function nfoCheckTY($release, $echo, $type, $nameStatus, $show): void
1832
    {
1833
        $result = [];
1834
1835
        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)) {
1836
            $releaseName = $result[0];
1837
            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)) {
1838
                switch ($result['lang']) {
1839
                    case 'DE':
1840
                        $result['lang'] = 'DUTCH';
1841
                        break;
1842
                    case 'Englisch':
1843
                        $result['lang'] = 'ENGLISH';
1844
                        break;
1845
                    case 'FR':
1846
                        $result['lang'] = 'FRENCH';
1847
                        break;
1848
                    case 'ES':
1849
                        $result['lang'] = 'SPANISH';
1850
                        break;
1851
                    default:
1852
                        break;
1853
                }
1854
                $releaseName = $releaseName.'.'.$result['lang'];
1855
            }
1856
1857
            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)) {
1858
                switch ($result['res']) {
1859
                    case '272':
1860
                    case '336':
1861
                    case '480':
1862
                    case '494':
1863
                    case '608':
1864
                    case '640':
1865
                    case '(640':
1866
                    case '688':
1867
                    case '704':
1868
                    case '720x480':
1869
                        $result['res'] = '480p';
1870
                        break;
1871
                    case '1280x720':
1872
                    case '1280':
1873
                    case '1280 @':
1874
                        $result['res'] = '720p';
1875
                        break;
1876
                    case '810':
1877
                    case '816':
1878
                    case '820':
1879
                    case '1920':
1880
                    case '1 920':
1881
                    case '1080':
1882
                    case '1 080':
1883
                    case '1920x1080':
1884
                        $result['res'] = '1080p';
1885
                        break;
1886
                    case '2160':
1887
                        $result['res'] = '2160p';
1888
                        break;
1889
                }
1890
1891
                $releaseName = $releaseName.'.'.$result['res'];
1892
            } elseif (preg_match('/(largeur|width).*?(?P<res>(\(?640|688|704|720|1280( \@)?|1 ?920))/i', $release->textstring, $result)) {
1893
                switch ($result['res']) {
1894
                    case '640':
1895
                    case '(640':
1896
                    case '688':
1897
                    case '704':
1898
                    case '720':
1899
                        $result['res'] = '480p';
1900
                        break;
1901
                    case '1280 @':
1902
                    case '1280':
1903
                        $result['res'] = '720p';
1904
                        break;
1905
                    case '1920':
1906
                    case '1 920':
1907
                        $result['res'] = '1080p';
1908
                        break;
1909
                    case '2160':
1910
                        $result['res'] = '2160p';
1911
                        break;
1912
                }
1913
1914
                $releaseName = $releaseName.'.'.$result['res'];
1915
            }
1916
1917
            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)) {
1918
                switch ($result['source']) {
1919
                    case 'BD':
1920
                        $result['source'] = 'Bluray.x264';
1921
                        break;
1922
                    case 'CAMRIP':
1923
                        $result['source'] = 'CAM';
1924
                        break;
1925
                    case 'DBrip':
1926
                        $result['source'] = 'BDRIP';
1927
                        break;
1928
                    case 'DVD R1':
1929
                    case 'NTSC':
1930
                    case 'PAL':
1931
                    case 'VOD':
1932
                        $result['source'] = 'DVD';
1933
                        break;
1934
                    case 'HD':
1935
                        $result['source'] = 'HDTV';
1936
                        break;
1937
                    case 'Ripped ':
1938
                        $result['source'] = 'DVDRIP';
1939
                }
1940
1941
                $releaseName = $releaseName.'.'.$result['source'];
1942
            } 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)) {
1943
                switch ($result['video']) {
1944
                    case 'AVI':
1945
                        $result['video'] = 'DVDRIP';
1946
                        break;
1947
                    case 'DBrip':
1948
                        $result['video'] = 'BDRIP';
1949
                        break;
1950
                    case '(Divx':
1951
                        $result['video'] = 'DIVX';
1952
                        break;
1953
                    case 'h264':
1954
                    case 'h-264':
1955
                    case 'h.264':
1956
                        $result['video'] = 'H264';
1957
                        break;
1958
                    case 'MPEG-4 Visual':
1959
                    case 'x264':
1960
                    case 'x-264':
1961
                    case 'x.264':
1962
                        $result['video'] = 'x264';
1963
                        break;
1964
                    case 'NTSC':
1965
                    case 'PAL':
1966
                        $result['video'] = 'DVD';
1967
                        break;
1968
                }
1969
1970
                $releaseName = $releaseName.'.'.$result['video'];
1971
            }
1972
1973
            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)) {
1974
                switch ($result['audio']) {
1975
                    case '0x0055 MPEG-1 Layer 3':
1976
                        $result['audio'] = 'MP3';
1977
                        break;
1978
                    case 'AC-3':
1979
                    case '(AC3':
1980
                        $result['audio'] = 'AC3';
1981
                        break;
1982
                    case 'AAC LC':
1983
                        $result['audio'] = 'AAC';
1984
                        break;
1985
                    case 'A_DTS':
1986
                    case 'DTS-HD':
1987
                    case 'DTSHD':
1988
                        $result['audio'] = 'DTS';
1989
                }
1990
                $releaseName = $releaseName.'.'.$result['audio'];
1991
            }
1992
            $releaseName .= '-NoGroup';
1993
            $this->updateRelease($release, $releaseName, 'nfoCheck: Title (Year)', $echo, $type, $nameStatus, $show);
1994
        }
1995
    }
1996
1997
    /**
1998
     * Games.
1999
     *
2000
     * @param         $release
2001
     * @param bool $echo
2002
     * @param string $type
2003
     * @param         $nameStatus
2004
     * @param         $show
2005
     * @throws \Exception
2006
     */
2007
    public function nfoCheckG($release, $echo, $type, $nameStatus, $show): void
2008
    {
2009
        $result = [];
2010
2011
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2012
            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)) {
2013
                if (preg_match('/\w[\w.+&*\/\()\',;: -]+\(c\)[\-\w.\',;& ]+\w/i', $release->textstring, $result)) {
2014
                    $releaseName = str_replace(['(c)', '(C)'], '(GAMES) (c)', $result['0']);
2015
                    $this->updateRelease($release, $releaseName, 'nfoCheck: PC Games (c)', $echo, $type, $nameStatus, $show);
2016
                } elseif (preg_match('/\w[\w.+&*\/()\',;: -]+\*ISO\*/i', $release->textstring, $result)) {
2017
                    $releaseName = str_replace('*ISO*', '*ISO* (PC GAMES)', $result['0']);
2018
                    $this->updateRelease($release, $releaseName, 'nfoCheck: PC Games *ISO*', $echo, $type, $nameStatus, $show);
2019
                }
2020
            }
2021
        }
2022
    }
2023
2024
    //
2025
2026
    /**
2027
     * Misc.
2028
     *
2029
     * @param         $release
2030
     * @param bool $echo
2031
     * @param string $type
2032
     * @param         $nameStatus
2033
     * @param         $show
2034
     * @throws \Exception
2035
     */
2036
    public function nfoCheckMisc($release, $echo, $type, $nameStatus, $show): void
2037
    {
2038
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2039
            if (preg_match('/Supplier.+?IGUANA/i', $release->textstring)) {
2040
                $releaseName = '';
2041
                $result = [];
2042
                if (preg_match('/\w[\-\w`~!@#$%^&*()+={}|:"<>?\[\]\\;\',.\/ ]+\s\((19|20)\d\d\)/i', $release->textstring, $result)) {
2043
                    $releaseName = $result[0];
2044
                } elseif (preg_match('/\s\[\*\] (English|Dutch|French|German|Spanish)\b/i', $release->textstring, $result)) {
2045
                    $releaseName = $releaseName.'.'.$result[1];
2046
                } elseif (preg_match('/\s\[\*\] (DT?S [2567][._ -][0-2]( MONO)?)\b/i', $release->textstring, $result)) {
2047
                    $releaseName = $releaseName.'.'.$result[2];
2048
                } elseif (preg_match('/Format.+(DVD([59R])?|[HX][._ -]?264)\b/i', $release->textstring, $result)) {
2049
                    $releaseName = $releaseName.'.'.$result[1];
2050
                } elseif (preg_match('/\[(640x.+|1280x.+|1920x.+)\] Resolution\b/i', $release->textstring, $result)) {
2051
                    if ($result[1] === '640x.+') {
2052
                        $result[1] = '480p';
2053
                    } elseif ($result[1] === '1280x.+') {
2054
                        $result[1] = '720p';
2055
                    } elseif ($result[1] === '1920x.+') {
2056
                        $result[1] = '1080p';
2057
                    }
2058
                    $releaseName = $releaseName.'.'.$result[1];
2059
                }
2060
                $result = $releaseName.'.IGUANA';
2061
                $this->updateRelease($release, $result, 'nfoCheck: IGUANA', $echo, $type, $nameStatus, $show);
2062
            }
2063
        }
2064
    }
2065
2066
    /**
2067
     * Just for filenames.
2068
     *
2069
     * @param         $release
2070
     * @param bool $echo
2071
     * @param string $type
2072
     * @param         $nameStatus
2073
     * @param         $show
2074
     *
2075
     * @return bool
2076
     * @throws \Exception
2077
     */
2078
    public function fileCheck($release, $echo, $type, $nameStatus, $show): bool
2079
    {
2080
        $result = [];
2081
2082
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2083
            switch (true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing \.\-_ [a-z0-9\.\-_]+)\.[a-z]{2,}$/i', $release->textstring, $result)">preg_match('/^([a-z0-9\.\.\-_ [a-z0-9\.\-_]+)\.[a-z]{2,}$/i', $releas">...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/\w[\-\w.',;...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/\w[\-\w.',;...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/3DS_\d{4}.+...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/^(\\|\/)?(....e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/^(.+?(x264|...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing \-_)*(\.part\d*(\.rar)?|\.rar|\.7z)?(\d{1,3}\.rev|\.vol.+?|\.mp4)/', $release->textstring, $result)">preg_match('/^VIDEOOT-[A\-_)*(\.part\d*(\.rar)?|\.rar|\.7z)?(\d{1,3}\.rev|\.vol.+?|\.mp4)/', $releas">...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/.+\\(.+\((1...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/\w.+?\)\.nd...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/\S.*[\w.\-'...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/^(.+?IMAGES...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing ._ -[ip]._ -)?|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._ -?|WMV)[._ -]NhaNC3[\-\w.',;& ]+\w/i', $release->textstring, $result)">preg_match('/\w[\-\w.',;._ -[ip]._ -)?|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._ -?|WMV)[._ -]NhaNC3[\-\w.',;& ]+\w/i', $releas">...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing \.\-_ |[\.\-_ ]\dCD|CDR|FLAC|SAT|WEB).+?(19|20)\d\d.+?)\\.+/i', $release->textstring, $result)">preg_match('/(.+?(\.\-_...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
It seems like you are loosely comparing preg_match('/^.+?SDPORN/...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/\w[\-\w.',;...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/\w.+?\.(epu...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/.+\\(.+\((1...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing ._ -(?=\.(avi|mkv))$/i', $release->textstring, $result)">preg_match('/\wtvp-[\w.\._ -(?=\.(avi|mkv))$/i', $releas">...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/^(.+?(19|20...e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/^(\\|\/)?(....e->textstring, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
2084
                case preg_match('/^(.+?(x264|XviD)\-TVP)\\\\/i', $release->textstring, $result):
2085
                    $this->updateRelease($release, $result['1'], 'fileCheck: TVP', $echo, $type, $nameStatus, $show);
2086
                    break;
2087
                case preg_match('/^(\\\\|\/)?(.+(\\\\|\/))*(.+?S\d{1,3}[.-_ ]?[ED]\d{1,3}.+)\.(.+)$/i', $release->textstring, $result):
2088
                    $this->updateRelease($release, $result['4'], 'fileCheck: Generic TV', $echo, $type, $nameStatus, $show);
2089
                    break;
2090
                case preg_match('/^(\\\\|\/)?(.+(\\\\|\/))*(.+?([\.\-_ ]\d{4}[\.\-_ ].+?(BDRip|bluray|DVDRip|XVID)).+)\.(.+)$/i', $release->textstring, $result):
2091
                    $this->updateRelease($release, $result['4'], 'fileCheck: Generic movie 1', $echo, $type, $nameStatus, $show);
2092
                    break;
2093
                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):
2094
                    $this->updateRelease($release, $result['1'], 'fileCheck: Generic movie 2', $echo, $type, $nameStatus, $show);
2095
                    break;
2096
                case preg_match('/(.+?([\.\-_ ](CD|FM)|[\.\-_ ]\dCD|CDR|FLAC|SAT|WEB).+?(19|20)\d\d.+?)\\\\.+/i', $release->textstring, $result):
2097
                    $this->updateRelease($release, $result['1'], 'fileCheck: Generic music', $echo, $type, $nameStatus, $show);
2098
                    break;
2099
                case preg_match('/^(.+?(19|20)\d\d\-([a-z0-9]{3}|[a-z]{2,}|C4))\\\\/i', $release->textstring, $result):
2100
                    $this->updateRelease($release, $result['1'], 'fileCheck: music groups', $echo, $type, $nameStatus, $show);
2101
                    break;
2102
                case preg_match('/.+\\\\(.+\((19|20)\d\d\)\.avi)$/i', $release->textstring, $result):
2103
                    $newname = str_replace('.avi', ' DVDRip XVID NoGroup', $result['1']);
2104
                    $this->updateRelease($release, $newname, 'fileCheck: Movie (year) avi', $echo, $type, $nameStatus, $show);
2105
                    break;
2106
                case preg_match('/.+\\\\(.+\((19|20)\d\d\)\.iso)$/i', $release->textstring, $result):
2107
                    $newname = str_replace('.iso', ' DVD NoGroup', $result['1']);
2108
                    $this->updateRelease($release, $newname, 'fileCheck: Movie (year) iso', $echo, $type, $nameStatus, $show);
2109
                    break;
2110
                case preg_match('/^(.+?IMAGESET.+?)\\\\.+/i', $release->textstring, $result):
2111
                    $this->updateRelease($release, $result['1'], 'fileCheck: XXX Imagesets', $echo, $type, $nameStatus, $show);
2112
                    break;
2113
                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):
2114
                    $this->updateRelease($release, $result['1'].' XXX DVDRIP XviD-VIDEOOT', 'fileCheck: XXX XviD VIDEOOT', $echo, $type, $nameStatus, $show);
2115
                    break;
2116
                case preg_match('/^.+?SDPORN/i', $release->textstring, $result):
2117
                    $this->updateRelease($release, $result['0'], 'fileCheck: XXX SDPORN', $echo, $type, $nameStatus, $show);
2118
                    break;
2119
                case preg_match('/\w[\-\w.\',;& ]+1080i[._ -]DD5[._ -]1[._ -]MPEG2-R&C(?=\.ts)$/i', $release->textstring, $result):
2120
                    $result = str_replace('MPEG2', 'MPEG2.HDTV', $result['0']);
2121
                    $this->updateRelease($release, $result, 'fileCheck: R&C', $echo, $type, $nameStatus, $show);
2122
                    break;
2123
                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):
2124
                    $this->updateRelease($release, $result['0'], 'fileCheck: NhaNc3', $echo, $type, $nameStatus, $show);
2125
                    break;
2126
                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):
2127
                    $result = str_replace('720p', '720p.HDTV.X264', $result['0']);
2128
                    $result = str_replace('1080p', '1080p.Bluray.X264', $result['0']);
2129
                    $result = str_replace('xvid', 'XVID.DVDrip', $result['0']);
2130
                    $this->updateRelease($release, $result, 'fileCheck: tvp', $echo, $type, $nameStatus, $show);
2131
                    break;
2132
                case preg_match('/\w[\-\w.\',;& ]+\d{3,4}\.hdtv-lol\.(avi|mp4|mkv|ts|nfo|nzb)/i', $release->textstring, $result):
2133
                    $this->updateRelease($release, $result['0'], 'fileCheck: Title.211.hdtv-lol.extension', $echo, $type, $nameStatus, $show);
2134
                    break;
2135
                case preg_match('/\w[\-\w.\',;& ]+-S\d{1,2}[EX]\d{1,2}-XVID-DL.avi/i', $release->textstring, $result):
2136
                    $this->updateRelease($release, $result['0'], 'fileCheck: Title-SxxExx-XVID-DL.avi', $echo, $type, $nameStatus, $show);
2137
                    break;
2138
                case preg_match('/\S.*[\w.\-\',;]+\s\-\ss\d{2}[ex]\d{2}\s\-\s[\w.\-\',;].+\./i', $release->textstring, $result):
2139
                    $this->updateRelease($release, $result['0'], 'fileCheck: Title - SxxExx - Eptitle', $echo, $type, $nameStatus, $show);
2140
                    break;
2141
                case preg_match('/\w.+?\)\.nds$/i', $release->textstring, $result):
2142
                    $this->updateRelease($release, $result['0'], 'fileCheck: ).nds Nintendo DS', $echo, $type, $nameStatus, $show);
2143
                    break;
2144
                case preg_match('/3DS_\d{4}.+\d{4} - (.+?)\.3ds/i', $release->textstring, $result):
2145
                    $this->updateRelease($release, '3DS '.$result['1'], 'fileCheck: .3ds Nintendo 3DS', $echo, $type, $nameStatus, $show);
2146
                    break;
2147
                case preg_match('/\w.+?\.(epub|mobi|azw|opf|fb2|prc|djvu|cb[rz])/i', $release->textstring, $result):
2148
                    $result = str_replace('.'.$result['1'], ' ('.$result['1'].')', $result['0']);
2149
                    $this->updateRelease($release, $result, 'fileCheck: EBook', $echo, $type, $nameStatus, $show);
2150
                    break;
2151
                case preg_match('/\w+[\-\w.\',;& ]+$/i', $release->textstring, $result) && preg_match(self::PREDB_REGEX, $release->textstring):
2152
                    $this->updateRelease($release, $result['0'], 'fileCheck: Folder name', $echo, $type, $nameStatus, $show);
2153
                    break;
2154
                default:
2155
                    return false;
2156
            }
2157
2158
            return true;
2159
        }
2160
2161
        return false;
2162
    }
2163
2164
    /**
2165
     * Look for a name based on mediainfo xml Unique_ID.
2166
     *
2167
     *
2168
     * @param $release
2169
     * @param $echo
2170
     * @param $type
2171
     * @param $nameStatus
2172
     * @param $show
2173
     *
2174
     * @return bool
2175
     * @throws \Exception
2176
     */
2177
    public function uidCheck($release, $echo, $type, $nameStatus, $show): bool
2178
    {
2179
        if (! empty($release->uid) && ! $this->done && $this->relid !== (int) $release->releases_id) {
2180
            $result = Release::fromQuery(sprintf(
2181
                '
2182
				SELECT r.id AS releases_id, r.size AS relsize, r.name AS textstring, r.searchname, r.fromname, r.predb_id
2183
				FROM releases r
2184
				LEFT JOIN release_unique ru ON ru.releases_id = r.id
2185
				WHERE ru.releases_id IS NOT NULL
2186
				AND ru.uniqueid = %s
2187
				AND ru.releases_id != %d
2188
				AND (r.predb_id > 0 OR r.anidbid > 0 OR r.fromname = %s)',
2189
                escapeString($release->uid),
2190
                $release->releases_id,
2191
                escapeString('[email protected] (EF)')
2192
            ));
2193
2194
            foreach ($result as $res) {
2195
                $floor = round(($res['relsize'] - $release->relsize) / $res['relsize'] * 100, 1);
2196
                if ($floor >= -10 && $floor <= 10) {
2197
                    $this->updateRelease(
2198
                            $release,
2199
                            $res->searchname,
2200
                            'uidCheck: Unique_ID',
2201
                            $echo,
2202
                            $type,
2203
                            $nameStatus,
2204
                            $show,
2205
                            $res->predb_id
2206
                        );
2207
2208
                    return true;
2209
                }
2210
            }
2211
        }
2212
        $this->_updateSingleColumn('proc_uid', self::PROC_UID_DONE, $release->releases_id);
2213
2214
        return false;
2215
    }
2216
2217
    /**
2218
     * Look for a name based on mediainfo xml Unique_ID.
2219
     *
2220
     *
2221
     * @param $release
2222
     * @param $echo
2223
     * @param $type
2224
     * @param $nameStatus
2225
     * @param $show
2226
     *
2227
     * @return bool
2228
     * @throws \Exception
2229
     */
2230
    public function mediaMovieNameCheck($release, $echo, $type, $nameStatus, $show): bool
2231
    {
2232
        $newName = '';
2233
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2234
            if (preg_match('/<Movie_name>(.+)<\/Movie_name>/i', $release->mediainfo, $match)) {
2235
                $media = $match[1];
2236
                if (preg_match(self::PREDB_REGEX, $media, $match)) {
2237
                    $newName = $match[1];
2238
                } elseif (preg_match('/(.+)[\,](\sRMZ\.cr)?$/i', $media, $match)) {
2239
                    $newName = $match[1];
2240
                } else {
2241
                    $newName = $media;
2242
                }
2243
            }
2244
2245
            if ($newName !== '') {
2246
                $this->updateRelease($release, $newName, 'MediaInfo: Movie Name', $echo, $type, $nameStatus, $show, $release->predb_id);
2247
2248
                return true;
2249
            }
2250
        }
2251
        $this->_updateSingleColumn('proc_uid', self::PROC_UID_DONE, $release->releases_id);
2252
2253
        return false;
2254
    }
2255
2256
    /**
2257
     * Look for a name based on xxx release filename.
2258
     *
2259
     *
2260
     * @param $release
2261
     * @param $echo
2262
     * @param $type
2263
     * @param $nameStatus
2264
     * @param $show
2265
     *
2266
     * @return bool
2267
     * @throws \Exception
2268
     */
2269
    public function xxxNameCheck($release, $echo, $type, $nameStatus, $show): bool
2270
    {
2271
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2272
            $result = Release::fromQuery(
2273
                sprintf(
2274
                    "
2275
				SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id,
2276
						rf.releases_id AS fileid, rel.id AS releases_id
2277
					FROM releases rel
2278
					INNER JOIN release_files rf ON (rf.releases_id = {$release->releases_id})
2279
					WHERE (rel.isrenamed = %d OR rel.categories_id IN(%d, %d))
2280
					AND rf.name LIKE %s",
2281
                    self::IS_RENAMED_NONE,
2282
                    Category::OTHER_MISC,
2283
                    Category::OTHER_HASHED,
2284
                    escapeString('%SDPORN%')
2285
                )
2286
            );
2287
2288
            foreach ($result as $res) {
2289
                if (preg_match('/^.+?SDPORN/i', $res->textstring, $match)) {
0 ignored issues
show
Bug introduced by
The property textstring does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
2290
                    $this->updateRelease(
2291
                            $release,
2292
                            $match['0'],
2293
                            'fileCheck: XXX SDPORN',
2294
                            $echo,
2295
                            $type,
2296
                            $nameStatus,
2297
                            $show
2298
                        );
2299
2300
                    return true;
2301
                }
2302
            }
2303
        }
2304
        $this->_updateSingleColumn('proc_files', self::PROC_FILES_DONE, $release->releases_id);
2305
2306
        return false;
2307
    }
2308
2309
    /**
2310
     * Look for a name based on .srr release files extension.
2311
     *
2312
     *
2313
     * @param $release
2314
     * @param $echo
2315
     * @param $type
2316
     * @param $nameStatus
2317
     * @param $show
2318
     *
2319
     * @return bool
2320
     * @throws \Exception
2321
     */
2322
    public function srrNameCheck($release, $echo, $type, $nameStatus, $show): bool
2323
    {
2324
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2325
            $result = Release::fromQuery(
2326
                sprintf(
2327
                    "
2328
				    SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id,
2329
						rf.releases_id AS fileid, rel.id AS releases_id
2330
					FROM releases rel
2331
					INNER JOIN release_files rf ON (rf.releases_id = {$release->releases_id})
2332
					WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d))
2333
					AND rf.name LIKE %s",
2334
                    self::IS_RENAMED_NONE,
2335
                    Category::OTHER_MISC,
2336
                    Category::OTHER_HASHED,
2337
                    escapeString('%.srr')
2338
                )
2339
            );
2340
2341
            foreach ($result as $res) {
2342
                if (preg_match('/^(.*)\.srr$/i', $res->textstring, $match)) {
0 ignored issues
show
Bug introduced by
The property textstring does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
2343
                    $this->updateRelease(
2344
                            $release,
2345
                            $match['1'],
2346
                            'fileCheck: SRR extension',
2347
                            $echo,
2348
                            $type,
2349
                            $nameStatus,
2350
                            $show
2351
                        );
2352
2353
                    return true;
2354
                }
2355
            }
2356
        }
2357
        $this->_updateSingleColumn('proc_srr', self::PROC_SRR_DONE, $release->releases_id);
2358
2359
        return false;
2360
    }
2361
2362
    /**
2363
     * Look for a name based on par2 hash_16K block.
2364
     *
2365
     *
2366
     * @param $release
2367
     * @param $echo
2368
     * @param $type
2369
     * @param $nameStatus
2370
     * @param $show
2371
     *
2372
     * @return bool
2373
     * @throws \Exception
2374
     */
2375
    public function hashCheck($release, $echo, $type, $nameStatus, $show): bool
2376
    {
2377
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2378
            $result = Release::fromQuery(sprintf(
2379
                '
2380
				SELECT r.id AS releases_id, r.size AS relsize, r.name AS textstring, r.searchname, r.fromname, r.predb_id
2381
				FROM releases r
2382
				LEFT JOIN par_hashes ph ON ph.releases_id = r.id
2383
				WHERE ph.hash = %s
2384
				AND ph.releases_id != %d
2385
				AND (r.predb_id > 0 OR r.anidbid > 0)',
2386
                escapeString($release->hash),
2387
                $release->releases_id
2388
            ));
2389
2390
            foreach ($result as $res) {
2391
                $floor = round(($res->relsize - $release->relsize) / $res->relsize * 100, 1);
0 ignored issues
show
Bug introduced by
The property relsize does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
2392
                if ($floor >= -5 && $floor <= 5) {
2393
                    $this->updateRelease(
2394
                            $release,
2395
                            $res->searchname,
2396
                            'hashCheck: PAR2 hash_16K',
2397
                            $echo,
2398
                            $type,
2399
                            $nameStatus,
2400
                            $show,
2401
                            $res->predb_id
2402
                        );
2403
2404
                    return true;
2405
                }
2406
            }
2407
        }
2408
        $this->_updateSingleColumn('proc_hash16k', self::PROC_HASH16K_DONE, $release->releases_id);
2409
2410
        return false;
2411
    }
2412
2413
    /**
2414
     * Look for a name based on rar crc32 hash.
2415
     *
2416
     *
2417
     * @param $release
2418
     * @param $echo
2419
     * @param $type
2420
     * @param $nameStatus
2421
     * @param $show
2422
     *
2423
     * @return bool
2424
     * @throws \Exception
2425
     */
2426
    public function crcCheck($release, $echo, $type, $nameStatus, $show): bool
2427
    {
2428
        if (! $this->done && $this->relid !== (int) $release->releases_id && $release->textstring !== '') {
2429
            $result = Release::fromQuery(
2430
                sprintf(
2431
                    '
2432
				    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,
2433
						rf.releases_id AS fileid, rel.id AS releases_id
2434
					FROM releases rel
2435
					LEFT JOIN release_files rf ON rf.releases_id = rel.id
2436
					WHERE rel.predb_id > 0
2437
					AND rf.crc32 = %s',
2438
                    escapeString($release->textstring)
2439
                )
2440
            );
2441
2442
            foreach ($result as $res) {
2443
                $floor = round(($res->relsize - $release->relsize) / $res->relsize * 100, 1);
0 ignored issues
show
Bug introduced by
The property relsize does not seem to exist on App\Models\Release. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
2444
                if ($floor >= -5 && $floor <= 5) {
2445
                    $this->updateRelease(
2446
                        $release,
2447
                        $res->searchname,
2448
                        'crcCheck: CRC32',
2449
                        $echo,
2450
                        $type,
2451
                        $nameStatus,
2452
                        $show,
2453
                        $res->predb_id
2454
                    );
2455
2456
                    return true;
2457
                }
2458
            }
2459
        }
2460
        $this->_updateSingleColumn('proc_crc32', self::PROC_CRC_DONE, $release->releases_id);
2461
2462
        return false;
2463
    }
2464
2465
    /**
2466
     * Resets NameFixer status variables for new processing.
2467
     */
2468
    public function reset(): void
2469
    {
2470
        $this->done = $this->matched = false;
2471
    }
2472
2473
    /**
2474
     * @param string $fileName
2475
     *
2476
     * @return array
2477
     */
2478
    private function preMatch($fileName): array
2479
    {
2480
        $result = preg_match('/(\d{2}\.\d{2}\.\d{2})+([\w\-.]+[\w]$)/i', $fileName, $match);
2481
2482
        return [$result === 1, $match[0] ?? ''];
2483
    }
2484
2485
    /**
2486
     * @param $release
2487
     * @param bool $echo
2488
     * @param string $type
2489
     * @param int $nameStatus
2490
     * @param bool $show
2491
     * @return bool
2492
     * @throws \Exception
2493
     */
2494
    public function preDbFileCheck($release, bool $echo, string $type, int $nameStatus, bool $show): bool
2495
    {
2496
        $this->_fileName = $release->textstring;
2497
        $this->_cleanMatchFiles();
2498
2499
        if (! empty($this->_fileName)) {
2500
            if (config('nntmux.elasticsearch_enabled') === true) {
2501
                $search = [
2502
                    'index' => 'predb',
2503
                    'body' => [
2504
                        'query' => [
2505
                            'multi_match' => [
2506
                                'query' => $this->_fileName,
2507
                                'fields' => ['filename', 'title'],
2508
                            ]
2509
                        ]
2510
                    ]
2511
                ];
2512
2513
                $primaryResults = \Elasticsearch::search($search);
2514
2515
                $results = [];
2516
                foreach ($primaryResults['hits']['hits'] as $primaryResult) {
2517
                    $results[] = $primaryResult['_source'];
2518
                }
2519
2520
                foreach ($results as $match) {
2521
                    if (! empty($match)) {
2522
                        $this->updateRelease($release, $match['title'], 'PreDb: Filename match', $echo, $type, $nameStatus, $show, $match['id']);
2523
2524
                        return true;
2525
                    }
2526
                }
2527
            } else {
2528
                foreach ($this->sphinx->searchIndexes('predb_rt', $this->_fileName, ['filename', 'title']) as $match) {
2529
                    if (! empty($match)) {
2530
                        $this->updateRelease($release, $match['title'], 'PreDb: Filename match', $echo, $type, $nameStatus, $show, $match['id']);
2531
2532
                        return true;
2533
                    }
2534
                }
2535
            }
2536
        }
2537
2538
        return false;
2539
    }
2540
2541
    /**
2542
     * @param $release
2543
     * @param bool $echo
2544
     * @param string $type
2545
     * @param int $nameStatus
2546
     * @param bool $show
2547
     * @return bool
2548
     * @throws \Exception
2549
     */
2550
    public function preDbTitleCheck($release, bool $echo, string $type, int $nameStatus, bool $show): bool
2551
    {
2552
        $this->_fileName = $release->textstring;
2553
        $this->_cleanMatchFiles();
2554
        $this->cleanFileNames();
2555
        if (! empty($this->_fileName)) {
2556
            if (config('nntmux.elasticsearch_enabled') === true) {
2557
                $search = [
2558
                    'index' => 'predb',
2559
                    'body' => [
2560
                        'query' => [
2561
                            'multi_match' => [
2562
                                'query' => $this->_fileName,
2563
                                'fields' => ['filename', 'title'],
2564
                            ]
2565
                        ]
2566
                    ]
2567
                ];
2568
2569
                $primaryResults = \Elasticsearch::search($search);
2570
2571
                $results = [];
2572
                foreach ($primaryResults['hits']['hits'] as $primaryResult) {
2573
                    $results[] = $primaryResult['_source'];
2574
                }
2575
2576
                foreach ($results as $match) {
2577
                    if (! empty($match)) {
2578
                        $this->updateRelease($release, $match['title'], 'PreDb: Title match', $echo, $type, $nameStatus, $show, $match['id']);
2579
2580
                        return true;
2581
                    }
2582
                }
2583
            } else {
2584
                foreach ($this->sphinx->searchIndexes('predb_rt', $this->_fileName, ['title']) as $match) {
2585
                    if (!empty($match)) {
2586
                        $this->updateRelease($release, $match['title'], 'PreDb: Title match', $echo, $type, $nameStatus, $show, $match['id']);
2587
2588
                        return true;
2589
                    }
2590
                }
2591
            }
2592
        }
2593
2594
        return false;
2595
    }
2596
2597
    /**
2598
     * Clean filenames for predb title match.
2599
     *
2600
     *
2601
     * @return string|string[]|null
2602
     */
2603
    private function cleanFileNames()
2604
    {
2605
        if (preg_match('/(\.[a-zA-Z]{2})?(\.4k|\.fullhd|\.hd|\.int|\.\d+)?$/i', $this->_fileName, $match)) {
2606
            if (! empty($match[1]) && preg_match('/\.[a-zA-Z]{2}/i', $match[1])) {
2607
                $this->_fileName = preg_replace('/\.[a-zA-Z]{2}\./i', '.', $this->_fileName);
2608
            }
2609
            if (! empty($match[2])) {
2610
                if (preg_match('/\.4k$/', $match[2])) {
2611
                    $this->_fileName = preg_replace('/\.4k$/', '.2160p', $this->_fileName);
2612
                }
2613
                if (preg_match('/\.fullhd$/i', $match[2])) {
2614
                    $this->_fileName = preg_replace('/\.fullhd$/i', '.1080p', $this->_fileName);
2615
                }
2616
                if (preg_match('/\.hd$/i', $match[2])) {
2617
                    $this->_fileName = preg_replace('/\.hd$/i', '.720p', $this->_fileName);
2618
                }
2619
                if (preg_match('/\.int$/i', $match[2])) {
2620
                    $this->_fileName = preg_replace('/\.int$/i', '.INTERNAL', $this->_fileName);
2621
                }
2622
                if (preg_match('/\.\d+/', $match[2])) {
2623
                    $this->_fileName = preg_replace('/\.\d+$/', '', $this->_fileName);
2624
                }
2625
            }
2626
            if (preg_match('/^[a-zA-Z]{0,7}\./', $this->_fileName)) {
2627
                $this->_fileName = preg_replace('/^[a-zA-Z]{0,7}\./', '', $this->_fileName);
2628
            }
2629
        }
2630
2631
        return $this->_fileName;
2632
    }
2633
}
2634