Completed
Push — dev ( 6be538...8cc9c3 )
by Darko
07:39
created

NameFixer::escapeString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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);
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
                                'simple_query_string' => [
1310
                                    'query' => $this->escapeString($preMatch[1]),
1311
                                    'fields' => ['title', 'filename'],
1312
                                    'analyze_wildcard' => true,
1313
                                    'default_operator' => 'and',
1314
                                ],
1315
                            ],
1316
                        ],
1317
                    ];
1318
1319
                    $primaryResults = \Elasticsearch::search($search);
1320
1321
                    $results = [];
1322
                    foreach ($primaryResults['hits']['hits'] as $primaryResult) {
1323
                        $results[] = $primaryResult['_source'];
1324
                    }
1325
                } else {
1326
                    $results = $this->sphinx->searchIndexes('predb_rt', $preMatch[1], ['filename', 'title']);
1327
                }
1328
                if (! empty($results)) {
1329
                    foreach ($results as $result) {
1330
                        if (! empty($result)) {
1331
                            $preFtMatch = $this->preMatch($result['filename']);
1332
                            if ($preFtMatch[0] === true) {
1333
                                $this->_fileName = $result['filename'];
1334
                                $release->filename = $this->_fileName;
1335
                                if ($result['title'] !== $release->searchname) {
1336
                                    $this->updateRelease($release, $result['title'], 'file matched source: '.$result['source'], $echo, 'PreDB file match, ', $nameStatus, $show, $result['id']);
1337
                                } else {
1338
                                    $this->_updateSingleColumn('predb_id', $result['id'], $release->releases_id);
1339
                                }
1340
                                $matching++;
1341
                                break;
1342
                            }
1343
                        }
1344
                    }
1345
                }
1346
            }
1347
        }
1348
1349
        return $matching;
1350
    }
1351
1352
    /**
1353
     * Cleans file names for PreDB Match.
1354
     *
1355
     *
1356
     * @return string
1357
     */
1358
    protected function _cleanMatchFiles(): string
1359
    {
1360
1361
        // first strip all non-printing chars  from filename
1362
        $this->_fileName = Utility::stripNonPrintingChars($this->_fileName);
1363
1364
        if ($this->_fileName !== '' && strpos($this->_fileName, '.') !== 0) {
1365
            switch (true) {
0 ignored issues
show
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...
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...
1366
1367
                case strpos($this->_fileName, '.') !== false:
1368
                    //some filenames start with a period that ends up creating bad matches so we don't process them
1369
                    $this->_fileName = Utility::cutStringUsingLast('.', $this->_fileName, 'left', false);
1370
                    break;
1371
1372
                //if filename has a .part001, send it back to the function to cut the next period
1373
                case preg_match('/\.part\d+$/', $this->_fileName):
1374
                    $this->_fileName = Utility::cutStringUsingLast('.', $this->_fileName, 'left', false);
1375
                    break;
1376
1377
                //if filename has a .vol001, send it back to the function to cut the next period
1378
                case preg_match('/\.vol\d+(\+\d+)?$/', $this->_fileName):
1379
                    $this->_fileName = Utility::cutStringUsingLast('.', $this->_fileName, 'left', false);
1380
                    break;
1381
1382
                //if filename contains a slash, cut the string and keep string to the right of the last slash to remove dir
1383
                case strpos($this->_fileName, '\\') !== false:
1384
                    $this->_fileName = Utility::cutStringUsingLast('\\', $this->_fileName, 'right', false);
1385
                    break;
1386
1387
                // A lot of obscured releases have one NFO file properly named with a track number (Audio) at the front of it
1388
                // This will strip out the track and match it to its pre title
1389
                case preg_match('/^\d{2}-/', $this->_fileName):
1390
                    $this->_fileName = preg_replace('/^\d{2}-/', '', $this->_fileName);
1391
            }
1392
1393
            return trim($this->_fileName);
1394
        }
1395
1396
        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...
1397
    }
1398
1399
    /**
1400
     * Match a Hash from the predb to a release.
1401
     *
1402
     * @param string $hash
1403
     * @param         $release
1404
     * @param         $echo
1405
     * @param         $nameStatus
1406
     * @param         $show
1407
     *
1408
     * @return int
1409
     * @throws \Exception
1410
     */
1411
    public function matchPredbHash($hash, $release, $echo, $nameStatus, $show): int
1412
    {
1413
        $matching = 0;
1414
        $this->matched = false;
1415
1416
        // Determine MD5 or SHA1
1417
        if (\strlen($hash) === 40) {
1418
            $hashtype = 'SHA1, ';
1419
        } else {
1420
            $hashtype = 'MD5, ';
1421
        }
1422
1423
        $row = Predb::fromQuery(
1424
            sprintf(
1425
                '
1426
						SELECT p.id AS predb_id, p.title, p.source
1427
						FROM predb p INNER JOIN predb_hashes h ON h.predb_id = p.id
1428
						WHERE h.hash = UNHEX(%s)
1429
						LIMIT 1',
1430
                escapeString($hash)
1431
            )
1432
        );
1433
1434
        foreach ($row as $item) {
1435
            if (! empty($item)) {
1436
                if ($item->title !== $release->searchname) {
1437
                    $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...
1438
                    $matching++;
1439
                }
1440
            } else {
1441
                $this->_updateSingleColumn('dehashstatus', $release->dehashstatus - 1, $release->releases_id);
1442
            }
1443
        }
1444
1445
        return $matching;
1446
    }
1447
1448
    /**
1449
     * Matches the hashes within the predb table to release files and subjects (names) which are hashed.
1450
     *
1451
     * @param $time
1452
     * @param $echo
1453
     * @param $cats
1454
     * @param $nameStatus
1455
     * @param $show
1456
     *
1457
     * @return int
1458
     * @throws \Exception
1459
     */
1460
    public function parseTitles($time, $echo, $cats, $nameStatus, $show): int
1461
    {
1462
        $updated = $checked = 0;
1463
1464
        $tq = '';
1465
        if ($time === 1) {
1466
            $tq = 'AND r.adddate > (NOW() - INTERVAL 3 HOUR) ORDER BY rf.releases_id, rf.size DESC';
1467
        }
1468
        $ct = '';
1469
        if ($cats === 1) {
1470
            $ct = sprintf('AND r.categories_id IN (%s)', $this->othercats);
1471
        }
1472
1473
        if ($this->echooutput) {
1474
            $te = '';
1475
            if ($time === 1) {
1476
                $te = ' in the past 3 hours';
1477
            }
1478
            $this->consoletools->header('Fixing search names'.$te.' using the predb hash.');
1479
        }
1480
        $regex = 'AND (r.ishashed = 1 OR rf.ishashed = 1)';
1481
1482
        if ($cats === 3) {
1483
            $query = sprintf('SELECT r.id AS releases_id, r.name, r.searchname, r.categories_id, r.groups_id, '
1484
                .'dehashstatus, rf.name AS filename FROM releases r '
1485
                .'LEFT OUTER JOIN release_files rf ON r.id = rf.releases_id '
1486
                .'WHERE nzbstatus = 1 AND dehashstatus BETWEEN -6 AND 0 AND predb_id = 0 %s', $regex);
1487
        } else {
1488
            $query = sprintf('SELECT r.id AS releases_id, r.name, r.searchname, r.categories_id, r.groups_id, '
1489
                .'dehashstatus, rf.name AS filename FROM releases r '
1490
                .'LEFT OUTER JOIN release_files rf ON r.id = rf.releases_id '
1491
                .'WHERE nzbstatus = 1 AND isrenamed = 0 AND dehashstatus BETWEEN -6 AND 0 %s %s %s', $regex, $ct, $tq);
1492
        }
1493
1494
        $res = Release::fromQuery($query);
1495
        $total = \count($res);
1496
        $this->consoletools->primary(number_format($total).' releases to process.');
1497
        foreach ($res as $row) {
1498
            if (preg_match('/[a-fA-F0-9]{32,40}/i', $row->name, $matches)) {
1499
                $updated += $this->matchPredbHash($matches[0], $row, $echo, $nameStatus, $show);
1500
            } 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...
1501
                $updated += $this->matchPredbHash($matches[0], $row, $echo, $nameStatus, $show);
1502
            }
1503
            if ($show === 2) {
1504
                $this->consoletools->overWritePrimary('Renamed Releases: ['.number_format($updated).'] '.$this->consoletools->percentString($checked++, $total));
1505
            }
1506
        }
1507
        if ($echo === 1) {
1508
            $this->consoletools->header(PHP_EOL.$updated.' releases have had their names changed out of: '.number_format($checked).' files.');
1509
        } else {
1510
            $this->consoletools->header(PHP_EOL.$updated.' releases could have their names changed. '.number_format($checked).' files were checked.');
1511
        }
1512
1513
        return $updated;
1514
    }
1515
1516
    /**
1517
     * Check the array using regex for a clean name.
1518
     *
1519
     * @param         $release
1520
     * @param bool $echo
1521
     * @param string $type
1522
     * @param int $nameStatus
1523
     * @param bool $show
1524
     * @param bool $preid
1525
     *
1526
     * @return bool
1527
     * @throws \Exception
1528
     */
1529
    public function checkName($release, $echo, $type, $nameStatus, $show, $preid = false): bool
1530
    {
1531
        // Get pre style name from releases.name
1532
        if (preg_match_all(self::PREDB_REGEX, $release->textstring, $matches) && ! preg_match('/Source\s\:/i', $release->textstring)) {
1533
            foreach ($matches as $match) {
1534
                foreach ($match as $val) {
1535
                    $title = Predb::query()->where('title', trim($val))->select(['title', 'id'])->first();
1536
                    if ($title !== null) {
1537
                        $this->updateRelease($release, $title['title'], 'preDB: Match', $echo, $type, $nameStatus, $show, $title['id']);
1538
                        $preid = true;
1539
                    }
1540
                }
1541
            }
1542
        }
1543
1544
        // if only processing for PreDB match skip to return
1545
        if (! $preid) {
1546
            switch ($type) {
1547
                case 'PAR2, ':
1548
                    $this->fileCheck($release, $echo, $type, $nameStatus, $show);
1549
                    break;
1550
                case 'PAR2 hash, ':
1551
                    $this->hashCheck($release, $echo, $type, $nameStatus, $show);
1552
                    break;
1553
                case 'UID, ':
1554
                    $this->uidCheck($release, $echo, $type, $nameStatus, $show);
1555
                    break;
1556
                case 'Mediainfo, ':
1557
                    $this->mediaMovieNameCheck($release, $echo, $type, $nameStatus, $show);
1558
                    break;
1559
                case 'SRR, ':
1560
                    $this->srrNameCheck($release, $echo, $type, $nameStatus, $show);
1561
                    break;
1562
                case 'CRC32, ':
1563
                    $this->crcCheck($release, $echo, $type, $nameStatus, $show);
1564
                    break;
1565
                case 'NFO, ':
1566
                    $this->nfoCheckTV($release, $echo, $type, $nameStatus, $show);
1567
                    $this->nfoCheckMov($release, $echo, $type, $nameStatus, $show);
1568
                    $this->nfoCheckMus($release, $echo, $type, $nameStatus, $show);
1569
                    $this->nfoCheckTY($release, $echo, $type, $nameStatus, $show);
1570
                    $this->nfoCheckG($release, $echo, $type, $nameStatus, $show);
1571
                    break;
1572
                case 'Filenames, ':
1573
                    $this->preDbFileCheck($release, $echo, $type, $nameStatus, $show);
1574
                    $this->preDbTitleCheck($release, $echo, $type, $nameStatus, $show);
1575
                    $this->fileCheck($release, $echo, $type, $nameStatus, $show);
1576
                    break;
1577
                default:
1578
                    $this->tvCheck($release, $echo, $type, $nameStatus, $show);
1579
                    $this->movieCheck($release, $echo, $type, $nameStatus, $show);
1580
                    $this->gameCheck($release, $echo, $type, $nameStatus, $show);
1581
                    $this->appCheck($release, $echo, $type, $nameStatus, $show);
1582
            }
1583
1584
            // set NameFixer process flags after run
1585
            if ($nameStatus === 1 && ! $this->matched) {
1586
                switch ($type) {
1587
                    case 'NFO, ':
1588
                        $this->_updateSingleColumn('proc_nfo', self::PROC_NFO_DONE, $release->releases_id);
1589
                        break;
1590
                    case 'Filenames, ':
1591
                        $this->_updateSingleColumn('proc_files', self::PROC_FILES_DONE, $release->releases_id);
1592
                        break;
1593
                    case 'PAR2, ':
1594
                        $this->_updateSingleColumn('proc_par2', self::PROC_PAR2_DONE, $release->releases_id);
1595
                        break;
1596
                    case 'PAR2 hash, ':
1597
                        $this->_updateSingleColumn('proc_hash16k', self::PROC_HASH16K_DONE, $release->releases_id);
1598
                        break;
1599
                    case 'SRR, ':
1600
                        $this->_updateSingleColumn('proc_srr', self::PROC_SRR_DONE, $release->releases_id);
1601
                        break;
1602
                    case 'UID, ':
1603
                        $this->_updateSingleColumn('proc_uid', self::PROC_UID_DONE, $release->releases_id);
1604
                        break;
1605
                }
1606
            }
1607
        }
1608
1609
        return $this->matched;
1610
    }
1611
1612
    /** This function updates a single variable column in releases
1613
     *  The first parameter is the column to update, the second is the value
1614
     *  The final parameter is the ID of the release to update.
1615
     *
1616
     * @param string  $column
1617
     * @param int $status
1618
     * @param int $id
1619
     */
1620
    public function _updateSingleColumn($column = '', $status = 0, $id = 0): void
1621
    {
1622
        if ((string) $column !== '' && (int) $id !== 0) {
1623
            Release::query()->where('id', $id)->update([$column => $status]);
1624
        }
1625
    }
1626
1627
    /**
1628
     * Look for a TV name.
1629
     *
1630
     * @param         $release
1631
     * @param bool $echo
1632
     * @param string $type
1633
     * @param         $nameStatus
1634
     * @param         $show
1635
     * @throws \Exception
1636
     */
1637
    public function tvCheck($release, $echo, $type, $nameStatus, $show): void
1638
    {
1639
        $result = [];
1640
1641
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1642
            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)) {
1643
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.Text.source.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.\',;& ]+((19|20)\d\d)[\-\w.\',;& ]+\w/i', $release->textstring, $result)) {
1645
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.Text.year.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})[\-\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)) {
1647
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.Text.resolution.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})[._ -](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)) {
1649
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.source.vcodec.group', $echo, $type, $nameStatus, $show);
1650
            } 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)) {
1651
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.SxxExx.acodec.source.res.vcodec.group', $echo, $type, $nameStatus, $show);
1652
            } 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)) {
1653
                $this->updateRelease($release, $result['0'], 'tvCheck: Title.year.###(season/episode).source.group', $echo, $type, $nameStatus, $show);
1654
            } 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)) {
1655
                $this->updateRelease($release, $result['0'], 'tvCheck: Sports', $echo, $type, $nameStatus, $show);
1656
            }
1657
        }
1658
    }
1659
1660
    /**
1661
     * Look for a movie name.
1662
     *
1663
     * @param         $release
1664
     * @param bool $echo
1665
     * @param string $type
1666
     * @param         $nameStatus
1667
     * @param         $show
1668
     * @throws \Exception
1669
     */
1670
    public function movieCheck($release, $echo, $type, $nameStatus, $show): void
1671
    {
1672
        $result = [];
1673
1674
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1675
            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)) {
1676
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.Text.res.vcod.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)[._ -](480|720|1080)[ip][\-\w.\',;& ]+\w/i', $release->textstring, $result)) {
1678
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.vcodec.res.group', $echo, $type, $nameStatus, $show);
1679
            } 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)) {
1680
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.vcodec.acodec.group', $echo, $type, $nameStatus, $show);
1681
            } 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)) {
1682
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.language.acodec.source.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)[._ -](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)) {
1684
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.resolution.source.acodec.vcodec.group', $echo, $type, $nameStatus, $show);
1685
            } 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)) {
1686
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.resolution.source.vcodec.group', $echo, $type, $nameStatus, $show);
1687
            } 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)) {
1688
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.resolution.acodec.vcodec.group', $echo, $type, $nameStatus, $show);
1689
            } 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)) {
1690
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.resolution.acodec.vcodec.group', $echo, $type, $nameStatus, $show);
1691
            } 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)) {
1692
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.source.res.group', $echo, $type, $nameStatus, $show);
1693
            } 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)) {
1694
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.year.eptitle.source.vcodec.group', $echo, $type, $nameStatus, $show);
1695
            } 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)) {
1696
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.resolution.source.acodec.vcodec.group', $echo, $type, $nameStatus, $show);
1697
            } 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)) {
1698
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.resolution.acodec.eptitle.source.year.group', $echo, $type, $nameStatus, $show);
1699
            } 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)) {
1700
                $this->updateRelease($release, $result['0'], 'movieCheck: Title.language.year.acodec.src', $echo, $type, $nameStatus, $show);
1701
            }
1702
        }
1703
    }
1704
1705
    /**
1706
     * Look for a game name.
1707
     *
1708
     * @param         $release
1709
     * @param bool $echo
1710
     * @param string $type
1711
     * @param         $nameStatus
1712
     * @param         $show
1713
     * @throws \Exception
1714
     */
1715
    public function gameCheck($release, $echo, $type, $nameStatus, $show): void
1716
    {
1717
        $result = [];
1718
1719
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1720
            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)) {
1721
                $this->updateRelease($release, $result['0'], 'gameCheck: Videogames 1', $echo, $type, $nameStatus, $show);
1722
            } elseif (preg_match('/\w[\-\w.\',;& ]+(GC|NDS|NGC|PS3|WII|XBOX(360)?)[._ -](DUPLEX|iNSOMNi|OneUp|STRANGE|SWAG|SKY)[\-\w.\',;& ]+\w/i', $release->textstring, $result)) {
1723
                $this->updateRelease($release, $result['0'], 'gameCheck: Videogames 2', $echo, $type, $nameStatus, $show);
1724
            } elseif (preg_match('/\w[\w.\',;-].+-OUTLAWS/i', $release->textstring, $result)) {
1725
                $result = str_replace('OUTLAWS', 'PC GAME OUTLAWS', $result['0']);
1726
                $this->updateRelease($release, $result['0'], 'gameCheck: PC Games -OUTLAWS', $echo, $type, $nameStatus, $show);
1727
            } elseif (preg_match('/\w[\w.\',;-].+\-ALiAS/i', $release->textstring, $result)) {
1728
                $newresult = str_replace('-ALiAS', ' PC GAME ALiAS', $result['0']);
1729
                $this->updateRelease($release, $newresult, 'gameCheck: PC Games -ALiAS', $echo, $type, $nameStatus, $show);
1730
            }
1731
        }
1732
    }
1733
1734
    /**
1735
     * Look for a app name.
1736
     *
1737
     * @param         $release
1738
     * @param bool $echo
1739
     * @param string $type
1740
     * @param         $nameStatus
1741
     * @param         $show
1742
     * @throws \Exception
1743
     */
1744
    public function appCheck($release, $echo, $type, $nameStatus, $show): void
1745
    {
1746
        $result = [];
1747
1748
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1749
            if (preg_match('/\w[\-\w.\',;& ]+(\d{1,10}|Linux|UNIX)[._ -](RPM)?[._ -]?(X64)?[._ -]?(Incl)[._ -](Keygen)[\-\w.\',;& ]+\w/i', $release->textstring, $result)) {
1750
                $this->updateRelease($release, $result['0'], 'appCheck: Apps 1', $echo, $type, $nameStatus, $show);
1751
            } elseif (preg_match('/\w[\-\w.\',;& ]+\d{1,8}[._ -](winall-freeware)[\-\w.\',;& ]+\w/i', $release->textstring, $result)) {
1752
                $this->updateRelease($release, $result['0'], 'appCheck: Apps 2', $echo, $type, $nameStatus, $show);
1753
            }
1754
        }
1755
    }
1756
1757
    /**
1758
     * TV.
1759
     *
1760
     * @param         $release
1761
     * @param bool $echo
1762
     * @param string $type
1763
     * @param         $nameStatus
1764
     * @param         $show
1765
     * @throws \Exception
1766
     */
1767
    public function nfoCheckTV($release, $echo, $type, $nameStatus, $show): void
1768
    {
1769
        $result = [];
1770
1771
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1772
            if (preg_match('/:\s*.*[\\\\\/]([A-Z0-9].+?S\d+[.-_ ]?[ED]\d+.+?)\.\w{2,}\s+/i', $release->textstring, $result)) {
1773
                $this->updateRelease($release, $result['1'], 'nfoCheck: Generic TV 1', $echo, $type, $nameStatus, $show);
1774
            } elseif (preg_match('/(?:(\:\s{1,}))(.+?S\d{1,3}[.-_ ]?[ED]\d{1,3}.+?)(\s{2,}|\r|\n)/i', $release->textstring, $result)) {
1775
                $this->updateRelease($release, $result['2'], 'nfoCheck: Generic TV 2', $echo, $type, $nameStatus, $show);
1776
            }
1777
        }
1778
    }
1779
1780
    /**
1781
     * Movies.
1782
     *
1783
     * @param         $release
1784
     * @param bool $echo
1785
     * @param string $type
1786
     * @param         $nameStatus
1787
     * @param         $show
1788
     * @throws \Exception
1789
     */
1790
    public function nfoCheckMov($release, $echo, $type, $nameStatus, $show): void
1791
    {
1792
        $result = [];
1793
1794
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
1795
            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)) {
1796
                $this->updateRelease($release, $result['2'], 'nfoCheck: Generic Movies 1', $echo, $type, $nameStatus, $show);
1797
            } elseif (preg_match('/(?:(\s{2,}))((?!Source).+?[\.\-_ ](19|20)\d\d.+?(BDRip|bluray|DVD(R|Rip)?|XVID).+?)(\s{2,}|\r|\n)/i', $release->textstring, $result)) {
1798
                $this->updateRelease($release, $result['2'], 'nfoCheck: Generic Movies 2', $echo, $type, $nameStatus, $show);
1799
            } elseif (preg_match('/(?:(\s{2,}))(.+?[\.\-_ ](NTSC|MULTi).+?(MULTi|DVDR)[\.\-_ ].+?)(\s{2,}|\r|\n)/i', $release->textstring, $result)) {
1800
                $this->updateRelease($release, $result['2'], 'nfoCheck: Generic Movies 3', $echo, $type, $nameStatus, $show);
1801
            }
1802
        }
1803
    }
1804
1805
    /**
1806
     * @param         $release
1807
     * @param bool $echo
1808
     * @param string $type
1809
     * @param         $nameStatus
1810
     * @param         $show
1811
     * @throws \Exception
1812
     */
1813
    public function nfoCheckMus($release, $echo, $type, $nameStatus, $show): void
1814
    {
1815
        $result = [];
1816
1817
        if (! $this->done && $this->relid !== (int) $release->releases_id && preg_match('/(?:\s{2,})(.+?-FM-\d{2}-\d{2})/i', $release->textstring, $result)) {
1818
            $newname = str_replace('-FM-', '-FM-Radio-MP3-', $result['1']);
1819
            $this->updateRelease($release, $newname, 'nfoCheck: Music FM RADIO', $echo, $type, $nameStatus, $show);
1820
        }
1821
    }
1822
1823
    /**
1824
     * Title (year).
1825
     *
1826
     * @param         $release
1827
     * @param bool $echo
1828
     * @param string $type
1829
     * @param         $nameStatus
1830
     * @param         $show
1831
     * @throws \Exception
1832
     */
1833
    public function nfoCheckTY($release, $echo, $type, $nameStatus, $show): void
1834
    {
1835
        $result = [];
1836
1837
        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)) {
1838
            $releaseName = $result[0];
1839
            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)) {
1840
                switch ($result['lang']) {
1841
                    case 'DE':
1842
                        $result['lang'] = 'DUTCH';
1843
                        break;
1844
                    case 'Englisch':
1845
                        $result['lang'] = 'ENGLISH';
1846
                        break;
1847
                    case 'FR':
1848
                        $result['lang'] = 'FRENCH';
1849
                        break;
1850
                    case 'ES':
1851
                        $result['lang'] = 'SPANISH';
1852
                        break;
1853
                    default:
1854
                        break;
1855
                }
1856
                $releaseName = $releaseName.'.'.$result['lang'];
1857
            }
1858
1859
            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)) {
1860
                switch ($result['res']) {
1861
                    case '272':
1862
                    case '336':
1863
                    case '480':
1864
                    case '494':
1865
                    case '608':
1866
                    case '640':
1867
                    case '(640':
1868
                    case '688':
1869
                    case '704':
1870
                    case '720x480':
1871
                        $result['res'] = '480p';
1872
                        break;
1873
                    case '1280x720':
1874
                    case '1280':
1875
                    case '1280 @':
1876
                        $result['res'] = '720p';
1877
                        break;
1878
                    case '810':
1879
                    case '816':
1880
                    case '820':
1881
                    case '1920':
1882
                    case '1 920':
1883
                    case '1080':
1884
                    case '1 080':
1885
                    case '1920x1080':
1886
                        $result['res'] = '1080p';
1887
                        break;
1888
                    case '2160':
1889
                        $result['res'] = '2160p';
1890
                        break;
1891
                }
1892
1893
                $releaseName = $releaseName.'.'.$result['res'];
1894
            } elseif (preg_match('/(largeur|width).*?(?P<res>(\(?640|688|704|720|1280( \@)?|1 ?920))/i', $release->textstring, $result)) {
1895
                switch ($result['res']) {
1896
                    case '640':
1897
                    case '(640':
1898
                    case '688':
1899
                    case '704':
1900
                    case '720':
1901
                        $result['res'] = '480p';
1902
                        break;
1903
                    case '1280 @':
1904
                    case '1280':
1905
                        $result['res'] = '720p';
1906
                        break;
1907
                    case '1920':
1908
                    case '1 920':
1909
                        $result['res'] = '1080p';
1910
                        break;
1911
                    case '2160':
1912
                        $result['res'] = '2160p';
1913
                        break;
1914
                }
1915
1916
                $releaseName = $releaseName.'.'.$result['res'];
1917
            }
1918
1919
            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)) {
1920
                switch ($result['source']) {
1921
                    case 'BD':
1922
                        $result['source'] = 'Bluray.x264';
1923
                        break;
1924
                    case 'CAMRIP':
1925
                        $result['source'] = 'CAM';
1926
                        break;
1927
                    case 'DBrip':
1928
                        $result['source'] = 'BDRIP';
1929
                        break;
1930
                    case 'DVD R1':
1931
                    case 'NTSC':
1932
                    case 'PAL':
1933
                    case 'VOD':
1934
                        $result['source'] = 'DVD';
1935
                        break;
1936
                    case 'HD':
1937
                        $result['source'] = 'HDTV';
1938
                        break;
1939
                    case 'Ripped ':
1940
                        $result['source'] = 'DVDRIP';
1941
                }
1942
1943
                $releaseName = $releaseName.'.'.$result['source'];
1944
            } 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)) {
1945
                switch ($result['video']) {
1946
                    case 'AVI':
1947
                        $result['video'] = 'DVDRIP';
1948
                        break;
1949
                    case 'DBrip':
1950
                        $result['video'] = 'BDRIP';
1951
                        break;
1952
                    case '(Divx':
1953
                        $result['video'] = 'DIVX';
1954
                        break;
1955
                    case 'h264':
1956
                    case 'h-264':
1957
                    case 'h.264':
1958
                        $result['video'] = 'H264';
1959
                        break;
1960
                    case 'MPEG-4 Visual':
1961
                    case 'x264':
1962
                    case 'x-264':
1963
                    case 'x.264':
1964
                        $result['video'] = 'x264';
1965
                        break;
1966
                    case 'NTSC':
1967
                    case 'PAL':
1968
                        $result['video'] = 'DVD';
1969
                        break;
1970
                }
1971
1972
                $releaseName = $releaseName.'.'.$result['video'];
1973
            }
1974
1975
            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)) {
1976
                switch ($result['audio']) {
1977
                    case '0x0055 MPEG-1 Layer 3':
1978
                        $result['audio'] = 'MP3';
1979
                        break;
1980
                    case 'AC-3':
1981
                    case '(AC3':
1982
                        $result['audio'] = 'AC3';
1983
                        break;
1984
                    case 'AAC LC':
1985
                        $result['audio'] = 'AAC';
1986
                        break;
1987
                    case 'A_DTS':
1988
                    case 'DTS-HD':
1989
                    case 'DTSHD':
1990
                        $result['audio'] = 'DTS';
1991
                }
1992
                $releaseName = $releaseName.'.'.$result['audio'];
1993
            }
1994
            $releaseName .= '-NoGroup';
1995
            $this->updateRelease($release, $releaseName, 'nfoCheck: Title (Year)', $echo, $type, $nameStatus, $show);
1996
        }
1997
    }
1998
1999
    /**
2000
     * Games.
2001
     *
2002
     * @param         $release
2003
     * @param bool $echo
2004
     * @param string $type
2005
     * @param         $nameStatus
2006
     * @param         $show
2007
     * @throws \Exception
2008
     */
2009
    public function nfoCheckG($release, $echo, $type, $nameStatus, $show): void
2010
    {
2011
        $result = [];
2012
2013
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2014
            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)) {
2015
                if (preg_match('/\w[\w.+&*\/\()\',;: -]+\(c\)[\-\w.\',;& ]+\w/i', $release->textstring, $result)) {
2016
                    $releaseName = str_replace(['(c)', '(C)'], '(GAMES) (c)', $result['0']);
2017
                    $this->updateRelease($release, $releaseName, 'nfoCheck: PC Games (c)', $echo, $type, $nameStatus, $show);
2018
                } elseif (preg_match('/\w[\w.+&*\/()\',;: -]+\*ISO\*/i', $release->textstring, $result)) {
2019
                    $releaseName = str_replace('*ISO*', '*ISO* (PC GAMES)', $result['0']);
2020
                    $this->updateRelease($release, $releaseName, 'nfoCheck: PC Games *ISO*', $echo, $type, $nameStatus, $show);
2021
                }
2022
            }
2023
        }
2024
    }
2025
2026
    //
2027
2028
    /**
2029
     * Misc.
2030
     *
2031
     * @param         $release
2032
     * @param bool $echo
2033
     * @param string $type
2034
     * @param         $nameStatus
2035
     * @param         $show
2036
     * @throws \Exception
2037
     */
2038
    public function nfoCheckMisc($release, $echo, $type, $nameStatus, $show): void
2039
    {
2040
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2041
            if (preg_match('/Supplier.+?IGUANA/i', $release->textstring)) {
2042
                $releaseName = '';
2043
                $result = [];
2044
                if (preg_match('/\w[\-\w`~!@#$%^&*()+={}|:"<>?\[\]\\;\',.\/ ]+\s\((19|20)\d\d\)/i', $release->textstring, $result)) {
2045
                    $releaseName = $result[0];
2046
                } elseif (preg_match('/\s\[\*\] (English|Dutch|French|German|Spanish)\b/i', $release->textstring, $result)) {
2047
                    $releaseName = $releaseName.'.'.$result[1];
2048
                } elseif (preg_match('/\s\[\*\] (DT?S [2567][._ -][0-2]( MONO)?)\b/i', $release->textstring, $result)) {
2049
                    $releaseName = $releaseName.'.'.$result[2];
2050
                } elseif (preg_match('/Format.+(DVD([59R])?|[HX][._ -]?264)\b/i', $release->textstring, $result)) {
2051
                    $releaseName = $releaseName.'.'.$result[1];
2052
                } elseif (preg_match('/\[(640x.+|1280x.+|1920x.+)\] Resolution\b/i', $release->textstring, $result)) {
2053
                    if ($result[1] === '640x.+') {
2054
                        $result[1] = '480p';
2055
                    } elseif ($result[1] === '1280x.+') {
2056
                        $result[1] = '720p';
2057
                    } elseif ($result[1] === '1920x.+') {
2058
                        $result[1] = '1080p';
2059
                    }
2060
                    $releaseName = $releaseName.'.'.$result[1];
2061
                }
2062
                $result = $releaseName.'.IGUANA';
2063
                $this->updateRelease($release, $result, 'nfoCheck: IGUANA', $echo, $type, $nameStatus, $show);
2064
            }
2065
        }
2066
    }
2067
2068
    /**
2069
     * Just for filenames.
2070
     *
2071
     * @param         $release
2072
     * @param bool $echo
2073
     * @param string $type
2074
     * @param         $nameStatus
2075
     * @param         $show
2076
     *
2077
     * @return bool
2078
     * @throws \Exception
2079
     */
2080
    public function fileCheck($release, $echo, $type, $nameStatus, $show): bool
2081
    {
2082
        $result = [];
2083
2084
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2085
            switch (true) {
0 ignored issues
show
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('/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 ._ -(?=\.(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 \-_)*(\.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('/\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('/^(.+?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 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('/^(\\|\/)?(....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('/^(.+?(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('/\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 ._ -[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 \.\-_ [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('/.+\\(.+\((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.+?\.(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('/\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('/\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('/^(.+?(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...
2086
                case preg_match('/^(.+?(x264|XviD)\-TVP)\\\\/i', $release->textstring, $result):
2087
                    $this->updateRelease($release, $result['1'], 'fileCheck: TVP', $echo, $type, $nameStatus, $show);
2088
                    break;
2089
                case preg_match('/^(\\\\|\/)?(.+(\\\\|\/))*(.+?S\d{1,3}[.-_ ]?[ED]\d{1,3}.+)\.(.+)$/i', $release->textstring, $result):
2090
                    $this->updateRelease($release, $result['4'], 'fileCheck: Generic TV', $echo, $type, $nameStatus, $show);
2091
                    break;
2092
                case preg_match('/^(\\\\|\/)?(.+(\\\\|\/))*(.+?([\.\-_ ]\d{4}[\.\-_ ].+?(BDRip|bluray|DVDRip|XVID)).+)\.(.+)$/i', $release->textstring, $result):
2093
                    $this->updateRelease($release, $result['4'], 'fileCheck: Generic movie 1', $echo, $type, $nameStatus, $show);
2094
                    break;
2095
                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):
2096
                    $this->updateRelease($release, $result['1'], 'fileCheck: Generic movie 2', $echo, $type, $nameStatus, $show);
2097
                    break;
2098
                case preg_match('/(.+?([\.\-_ ](CD|FM)|[\.\-_ ]\dCD|CDR|FLAC|SAT|WEB).+?(19|20)\d\d.+?)\\\\.+/i', $release->textstring, $result):
2099
                    $this->updateRelease($release, $result['1'], 'fileCheck: Generic music', $echo, $type, $nameStatus, $show);
2100
                    break;
2101
                case preg_match('/^(.+?(19|20)\d\d\-([a-z0-9]{3}|[a-z]{2,}|C4))\\\\/i', $release->textstring, $result):
2102
                    $this->updateRelease($release, $result['1'], 'fileCheck: music groups', $echo, $type, $nameStatus, $show);
2103
                    break;
2104
                case preg_match('/.+\\\\(.+\((19|20)\d\d\)\.avi)$/i', $release->textstring, $result):
2105
                    $newname = str_replace('.avi', ' DVDRip XVID NoGroup', $result['1']);
2106
                    $this->updateRelease($release, $newname, 'fileCheck: Movie (year) avi', $echo, $type, $nameStatus, $show);
2107
                    break;
2108
                case preg_match('/.+\\\\(.+\((19|20)\d\d\)\.iso)$/i', $release->textstring, $result):
2109
                    $newname = str_replace('.iso', ' DVD NoGroup', $result['1']);
2110
                    $this->updateRelease($release, $newname, 'fileCheck: Movie (year) iso', $echo, $type, $nameStatus, $show);
2111
                    break;
2112
                case preg_match('/^(.+?IMAGESET.+?)\\\\.+/i', $release->textstring, $result):
2113
                    $this->updateRelease($release, $result['1'], 'fileCheck: XXX Imagesets', $echo, $type, $nameStatus, $show);
2114
                    break;
2115
                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):
2116
                    $this->updateRelease($release, $result['1'].' XXX DVDRIP XviD-VIDEOOT', 'fileCheck: XXX XviD VIDEOOT', $echo, $type, $nameStatus, $show);
2117
                    break;
2118
                case preg_match('/^.+?SDPORN/i', $release->textstring, $result):
2119
                    $this->updateRelease($release, $result['0'], 'fileCheck: XXX SDPORN', $echo, $type, $nameStatus, $show);
2120
                    break;
2121
                case preg_match('/\w[\-\w.\',;& ]+1080i[._ -]DD5[._ -]1[._ -]MPEG2-R&C(?=\.ts)$/i', $release->textstring, $result):
2122
                    $result = str_replace('MPEG2', 'MPEG2.HDTV', $result['0']);
2123
                    $this->updateRelease($release, $result, 'fileCheck: R&C', $echo, $type, $nameStatus, $show);
2124
                    break;
2125
                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):
2126
                    $this->updateRelease($release, $result['0'], 'fileCheck: NhaNc3', $echo, $type, $nameStatus, $show);
2127
                    break;
2128
                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):
2129
                    $result = str_replace('720p', '720p.HDTV.X264', $result['0']);
2130
                    $result = str_replace('1080p', '1080p.Bluray.X264', $result['0']);
2131
                    $result = str_replace('xvid', 'XVID.DVDrip', $result['0']);
2132
                    $this->updateRelease($release, $result, 'fileCheck: tvp', $echo, $type, $nameStatus, $show);
2133
                    break;
2134
                case preg_match('/\w[\-\w.\',;& ]+\d{3,4}\.hdtv-lol\.(avi|mp4|mkv|ts|nfo|nzb)/i', $release->textstring, $result):
2135
                    $this->updateRelease($release, $result['0'], 'fileCheck: Title.211.hdtv-lol.extension', $echo, $type, $nameStatus, $show);
2136
                    break;
2137
                case preg_match('/\w[\-\w.\',;& ]+-S\d{1,2}[EX]\d{1,2}-XVID-DL.avi/i', $release->textstring, $result):
2138
                    $this->updateRelease($release, $result['0'], 'fileCheck: Title-SxxExx-XVID-DL.avi', $echo, $type, $nameStatus, $show);
2139
                    break;
2140
                case preg_match('/\S.*[\w.\-\',;]+\s\-\ss\d{2}[ex]\d{2}\s\-\s[\w.\-\',;].+\./i', $release->textstring, $result):
2141
                    $this->updateRelease($release, $result['0'], 'fileCheck: Title - SxxExx - Eptitle', $echo, $type, $nameStatus, $show);
2142
                    break;
2143
                case preg_match('/\w.+?\)\.nds$/i', $release->textstring, $result):
2144
                    $this->updateRelease($release, $result['0'], 'fileCheck: ).nds Nintendo DS', $echo, $type, $nameStatus, $show);
2145
                    break;
2146
                case preg_match('/3DS_\d{4}.+\d{4} - (.+?)\.3ds/i', $release->textstring, $result):
2147
                    $this->updateRelease($release, '3DS '.$result['1'], 'fileCheck: .3ds Nintendo 3DS', $echo, $type, $nameStatus, $show);
2148
                    break;
2149
                case preg_match('/\w.+?\.(epub|mobi|azw|opf|fb2|prc|djvu|cb[rz])/i', $release->textstring, $result):
2150
                    $result = str_replace('.'.$result['1'], ' ('.$result['1'].')', $result['0']);
2151
                    $this->updateRelease($release, $result, 'fileCheck: EBook', $echo, $type, $nameStatus, $show);
2152
                    break;
2153
                case preg_match('/\w+[\-\w.\',;& ]+$/i', $release->textstring, $result) && preg_match(self::PREDB_REGEX, $release->textstring):
2154
                    $this->updateRelease($release, $result['0'], 'fileCheck: Folder name', $echo, $type, $nameStatus, $show);
2155
                    break;
2156
                default:
2157
                    return false;
2158
            }
2159
2160
            return true;
2161
        }
2162
2163
        return false;
2164
    }
2165
2166
    /**
2167
     * Look for a name based on mediainfo xml Unique_ID.
2168
     *
2169
     *
2170
     * @param $release
2171
     * @param $echo
2172
     * @param $type
2173
     * @param $nameStatus
2174
     * @param $show
2175
     *
2176
     * @return bool
2177
     * @throws \Exception
2178
     */
2179
    public function uidCheck($release, $echo, $type, $nameStatus, $show): bool
2180
    {
2181
        if (! empty($release->uid) && ! $this->done && $this->relid !== (int) $release->releases_id) {
2182
            $result = Release::fromQuery(sprintf(
2183
                '
2184
				SELECT r.id AS releases_id, r.size AS relsize, r.name AS textstring, r.searchname, r.fromname, r.predb_id
2185
				FROM releases r
2186
				LEFT JOIN release_unique ru ON ru.releases_id = r.id
2187
				WHERE ru.releases_id IS NOT NULL
2188
				AND ru.uniqueid = %s
2189
				AND ru.releases_id != %d
2190
				AND (r.predb_id > 0 OR r.anidbid > 0 OR r.fromname = %s)',
2191
                escapeString($release->uid),
2192
                $release->releases_id,
2193
                escapeString('[email protected] (EF)')
2194
            ));
2195
2196
            foreach ($result as $res) {
2197
                $floor = round(($res['relsize'] - $release->relsize) / $res['relsize'] * 100, 1);
2198
                if ($floor >= -10 && $floor <= 10) {
2199
                    $this->updateRelease(
2200
                            $release,
2201
                            $res->searchname,
2202
                            'uidCheck: Unique_ID',
2203
                            $echo,
2204
                            $type,
2205
                            $nameStatus,
2206
                            $show,
2207
                            $res->predb_id
2208
                        );
2209
2210
                    return true;
2211
                }
2212
            }
2213
        }
2214
        $this->_updateSingleColumn('proc_uid', self::PROC_UID_DONE, $release->releases_id);
2215
2216
        return false;
2217
    }
2218
2219
    /**
2220
     * Look for a name based on mediainfo xml Unique_ID.
2221
     *
2222
     *
2223
     * @param $release
2224
     * @param $echo
2225
     * @param $type
2226
     * @param $nameStatus
2227
     * @param $show
2228
     *
2229
     * @return bool
2230
     * @throws \Exception
2231
     */
2232
    public function mediaMovieNameCheck($release, $echo, $type, $nameStatus, $show): bool
2233
    {
2234
        $newName = '';
2235
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2236
            if (preg_match('/<Movie_name>(.+)<\/Movie_name>/i', $release->mediainfo, $match)) {
2237
                $media = $match[1];
2238
                if (preg_match(self::PREDB_REGEX, $media, $match)) {
2239
                    $newName = $match[1];
2240
                } elseif (preg_match('/(.+)[\,](\sRMZ\.cr)?$/i', $media, $match)) {
2241
                    $newName = $match[1];
2242
                } else {
2243
                    $newName = $media;
2244
                }
2245
            }
2246
2247
            if ($newName !== '') {
2248
                $this->updateRelease($release, $newName, 'MediaInfo: Movie Name', $echo, $type, $nameStatus, $show, $release->predb_id);
2249
2250
                return true;
2251
            }
2252
        }
2253
        $this->_updateSingleColumn('proc_uid', self::PROC_UID_DONE, $release->releases_id);
2254
2255
        return false;
2256
    }
2257
2258
    /**
2259
     * Look for a name based on xxx release filename.
2260
     *
2261
     *
2262
     * @param $release
2263
     * @param $echo
2264
     * @param $type
2265
     * @param $nameStatus
2266
     * @param $show
2267
     *
2268
     * @return bool
2269
     * @throws \Exception
2270
     */
2271
    public function xxxNameCheck($release, $echo, $type, $nameStatus, $show): bool
2272
    {
2273
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2274
            $result = Release::fromQuery(
2275
                sprintf(
2276
                    "
2277
				SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id,
2278
						rf.releases_id AS fileid, rel.id AS releases_id
2279
					FROM releases rel
2280
					INNER JOIN release_files rf ON (rf.releases_id = {$release->releases_id})
2281
					WHERE (rel.isrenamed = %d OR rel.categories_id IN(%d, %d))
2282
					AND rf.name LIKE %s",
2283
                    self::IS_RENAMED_NONE,
2284
                    Category::OTHER_MISC,
2285
                    Category::OTHER_HASHED,
2286
                    escapeString('%SDPORN%')
2287
                )
2288
            );
2289
2290
            foreach ($result as $res) {
2291
                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...
2292
                    $this->updateRelease(
2293
                            $release,
2294
                            $match['0'],
2295
                            'fileCheck: XXX SDPORN',
2296
                            $echo,
2297
                            $type,
2298
                            $nameStatus,
2299
                            $show
2300
                        );
2301
2302
                    return true;
2303
                }
2304
            }
2305
        }
2306
        $this->_updateSingleColumn('proc_files', self::PROC_FILES_DONE, $release->releases_id);
2307
2308
        return false;
2309
    }
2310
2311
    /**
2312
     * Look for a name based on .srr release files extension.
2313
     *
2314
     *
2315
     * @param $release
2316
     * @param $echo
2317
     * @param $type
2318
     * @param $nameStatus
2319
     * @param $show
2320
     *
2321
     * @return bool
2322
     * @throws \Exception
2323
     */
2324
    public function srrNameCheck($release, $echo, $type, $nameStatus, $show): bool
2325
    {
2326
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2327
            $result = Release::fromQuery(
2328
                sprintf(
2329
                    "
2330
				    SELECT rf.name AS textstring, rel.categories_id, rel.name, rel.searchname, rel.fromname, rel.groups_id,
2331
						rf.releases_id AS fileid, rel.id AS releases_id
2332
					FROM releases rel
2333
					INNER JOIN release_files rf ON (rf.releases_id = {$release->releases_id})
2334
					WHERE (rel.isrenamed = %d OR rel.categories_id IN (%d, %d))
2335
					AND rf.name LIKE %s",
2336
                    self::IS_RENAMED_NONE,
2337
                    Category::OTHER_MISC,
2338
                    Category::OTHER_HASHED,
2339
                    escapeString('%.srr')
2340
                )
2341
            );
2342
2343
            foreach ($result as $res) {
2344
                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...
2345
                    $this->updateRelease(
2346
                            $release,
2347
                            $match['1'],
2348
                            'fileCheck: SRR extension',
2349
                            $echo,
2350
                            $type,
2351
                            $nameStatus,
2352
                            $show
2353
                        );
2354
2355
                    return true;
2356
                }
2357
            }
2358
        }
2359
        $this->_updateSingleColumn('proc_srr', self::PROC_SRR_DONE, $release->releases_id);
2360
2361
        return false;
2362
    }
2363
2364
    /**
2365
     * Look for a name based on par2 hash_16K block.
2366
     *
2367
     *
2368
     * @param $release
2369
     * @param $echo
2370
     * @param $type
2371
     * @param $nameStatus
2372
     * @param $show
2373
     *
2374
     * @return bool
2375
     * @throws \Exception
2376
     */
2377
    public function hashCheck($release, $echo, $type, $nameStatus, $show): bool
2378
    {
2379
        if (! $this->done && $this->relid !== (int) $release->releases_id) {
2380
            $result = Release::fromQuery(sprintf(
2381
                '
2382
				SELECT r.id AS releases_id, r.size AS relsize, r.name AS textstring, r.searchname, r.fromname, r.predb_id
2383
				FROM releases r
2384
				LEFT JOIN par_hashes ph ON ph.releases_id = r.id
2385
				WHERE ph.hash = %s
2386
				AND ph.releases_id != %d
2387
				AND (r.predb_id > 0 OR r.anidbid > 0)',
2388
                escapeString($release->hash),
2389
                $release->releases_id
2390
            ));
2391
2392
            foreach ($result as $res) {
2393
                $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...
2394
                if ($floor >= -5 && $floor <= 5) {
2395
                    $this->updateRelease(
2396
                            $release,
2397
                            $res->searchname,
2398
                            'hashCheck: PAR2 hash_16K',
2399
                            $echo,
2400
                            $type,
2401
                            $nameStatus,
2402
                            $show,
2403
                            $res->predb_id
2404
                        );
2405
2406
                    return true;
2407
                }
2408
            }
2409
        }
2410
        $this->_updateSingleColumn('proc_hash16k', self::PROC_HASH16K_DONE, $release->releases_id);
2411
2412
        return false;
2413
    }
2414
2415
    /**
2416
     * Look for a name based on rar crc32 hash.
2417
     *
2418
     *
2419
     * @param $release
2420
     * @param $echo
2421
     * @param $type
2422
     * @param $nameStatus
2423
     * @param $show
2424
     *
2425
     * @return bool
2426
     * @throws \Exception
2427
     */
2428
    public function crcCheck($release, $echo, $type, $nameStatus, $show): bool
2429
    {
2430
        if (! $this->done && $this->relid !== (int) $release->releases_id && $release->textstring !== '') {
2431
            $result = Release::fromQuery(
2432
                sprintf(
2433
                    '
2434
				    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,
2435
						rf.releases_id AS fileid, rel.id AS releases_id
2436
					FROM releases rel
2437
					LEFT JOIN release_files rf ON rf.releases_id = rel.id
2438
					WHERE rel.predb_id > 0
2439
					AND rf.crc32 = %s',
2440
                    escapeString($release->textstring)
2441
                )
2442
            );
2443
2444
            foreach ($result as $res) {
2445
                $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...
2446
                if ($floor >= -5 && $floor <= 5) {
2447
                    $this->updateRelease(
2448
                        $release,
2449
                        $res->searchname,
2450
                        'crcCheck: CRC32',
2451
                        $echo,
2452
                        $type,
2453
                        $nameStatus,
2454
                        $show,
2455
                        $res->predb_id
2456
                    );
2457
2458
                    return true;
2459
                }
2460
            }
2461
        }
2462
        $this->_updateSingleColumn('proc_crc32', self::PROC_CRC_DONE, $release->releases_id);
2463
2464
        return false;
2465
    }
2466
2467
    /**
2468
     * Resets NameFixer status variables for new processing.
2469
     */
2470
    public function reset(): void
2471
    {
2472
        $this->done = $this->matched = false;
2473
    }
2474
2475
    /**
2476
     * @param string $fileName
2477
     *
2478
     * @return array
2479
     */
2480
    private function preMatch($fileName): array
2481
    {
2482
        $result = preg_match('/(\d{2}\.\d{2}\.\d{2})+([\w\-.]+[\w]$)/i', $fileName, $match);
2483
2484
        return [$result === 1, $match[0] ?? ''];
2485
    }
2486
2487
    /**
2488
     * @param $release
2489
     * @param bool $echo
2490
     * @param string $type
2491
     * @param int $nameStatus
2492
     * @param bool $show
2493
     * @return bool
2494
     * @throws \Exception
2495
     */
2496
    public function preDbFileCheck($release, bool $echo, string $type, int $nameStatus, bool $show): bool
2497
    {
2498
        $this->_fileName = $release->textstring;
2499
        $this->_cleanMatchFiles();
2500
2501
        if (! empty($this->_fileName)) {
2502
            if (config('nntmux.elasticsearch_enabled') === true) {
2503
                $search = [
2504
                    'index' => 'predb',
2505
                    'body' => [
2506
                        'query' => [
2507
                            'simple_query_string' => [
2508
                                'query' => $this->escapeString($this->_fileName),
2509
                                'fields' => ['title', 'filename'],
2510
                                'analyze_wildcard' => true,
2511
                                'default_operator' => 'and',
2512
                            ],
2513
                        ],
2514
                    ],
2515
                ];
2516
2517
                $primaryResults = \Elasticsearch::search($search);
2518
2519
                $results = [];
2520
                foreach ($primaryResults['hits']['hits'] as $primaryResult) {
2521
                    $results[] = $primaryResult['_source'];
2522
                }
2523
2524
                foreach ($results as $match) {
2525
                    if (! empty($match)) {
2526
                        $this->updateRelease($release, $match['title'], 'PreDb: Filename match', $echo, $type, $nameStatus, $show, $match['id']);
2527
2528
                        return true;
2529
                    }
2530
                }
2531
            } else {
2532
                foreach ($this->sphinx->searchIndexes('predb_rt', $this->_fileName, ['filename', 'title']) as $match) {
2533
                    if (! empty($match)) {
2534
                        $this->updateRelease($release, $match['title'], 'PreDb: Filename match', $echo, $type, $nameStatus, $show, $match['id']);
2535
2536
                        return true;
2537
                    }
2538
                }
2539
            }
2540
        }
2541
2542
        return false;
2543
    }
2544
2545
    /**
2546
     * @param $release
2547
     * @param bool $echo
2548
     * @param string $type
2549
     * @param int $nameStatus
2550
     * @param bool $show
2551
     * @return bool
2552
     * @throws \Exception
2553
     */
2554
    public function preDbTitleCheck($release, bool $echo, string $type, int $nameStatus, bool $show): bool
2555
    {
2556
        $this->_fileName = $release->textstring;
2557
        $this->_cleanMatchFiles();
2558
        $this->cleanFileNames();
2559
        if (! empty($this->_fileName)) {
2560
            $this->_fileName = str_replace('/', '\/', $this->_fileName);
2561
            if (config('nntmux.elasticsearch_enabled') === true) {
2562
                $search = [
2563
                    'index' => 'predb',
2564
                    'body' => [
2565
                        'query' => [
2566
                            'query_string' => [
2567
                                'query' => $this->_fileName,
2568
                                'fields' => ['title', 'filename'],
2569
                                'analyze_wildcard' => true,
2570
                                'default_operator' => 'and',
2571
                            ],
2572
                        ],
2573
                    ],
2574
                ];
2575
2576
                $primaryResults = \Elasticsearch::search($search);
2577
2578
                $results = [];
2579
                foreach ($primaryResults['hits']['hits'] as $primaryResult) {
2580
                    $results[] = $primaryResult['_source'];
2581
                }
2582
2583
                foreach ($results as $match) {
2584
                    if (! empty($match)) {
2585
                        $this->updateRelease($release, $match['title'], 'PreDb: Title match', $echo, $type, $nameStatus, $show, $match['id']);
2586
2587
                        return true;
2588
                    }
2589
                }
2590
            } else {
2591
                foreach ($this->sphinx->searchIndexes('predb_rt', $this->_fileName, ['title']) as $match) {
2592
                    if (! empty($match)) {
2593
                        $this->updateRelease($release, $match['title'], 'PreDb: Title match', $echo, $type, $nameStatus, $show, $match['id']);
2594
2595
                        return true;
2596
                    }
2597
                }
2598
            }
2599
        }
2600
2601
        return false;
2602
    }
2603
2604
    /**
2605
     * Clean filenames for predb title match.
2606
     *
2607
     *
2608
     * @return string|string[]|null
2609
     */
2610
    private function cleanFileNames()
2611
    {
2612
        if (preg_match('/(\.[a-zA-Z]{2})?(\.4k|\.fullhd|\.hd|\.int|\.\d+)?$/i', $this->_fileName, $match)) {
2613
            if (! empty($match[1]) && preg_match('/\.[a-zA-Z]{2}/i', $match[1])) {
2614
                $this->_fileName = preg_replace('/\.[a-zA-Z]{2}\./i', '.', $this->_fileName);
2615
            }
2616
            if (! empty($match[2])) {
2617
                if (preg_match('/\.4k$/', $match[2])) {
2618
                    $this->_fileName = preg_replace('/\.4k$/', '.2160p', $this->_fileName);
2619
                }
2620
                if (preg_match('/\.fullhd$/i', $match[2])) {
2621
                    $this->_fileName = preg_replace('/\.fullhd$/i', '.1080p', $this->_fileName);
2622
                }
2623
                if (preg_match('/\.hd$/i', $match[2])) {
2624
                    $this->_fileName = preg_replace('/\.hd$/i', '.720p', $this->_fileName);
2625
                }
2626
                if (preg_match('/\.int$/i', $match[2])) {
2627
                    $this->_fileName = preg_replace('/\.int$/i', '.INTERNAL', $this->_fileName);
2628
                }
2629
                if (preg_match('/\.\d+/', $match[2])) {
2630
                    $this->_fileName = preg_replace('/\.\d+$/', '', $this->_fileName);
2631
                }
2632
            }
2633
            if (preg_match('/^[a-zA-Z]{0,7}\./', $this->_fileName)) {
2634
                $this->_fileName = preg_replace('/^[a-zA-Z]{0,7}\./', '', $this->_fileName);
2635
            }
2636
        }
2637
2638
        return $this->_fileName;
2639
    }
2640
2641
    /**
2642
     * @param $string
2643
     * @return string|string[]
2644
     */
2645
    private function escapeString($string) {
2646
        $from = ["+", "-", "=", "&&", "|", "!", "(", ")", "{", "}", "[", "]", "^", '"', "~", "*", "?", ":", "\\", "/"];
2647
        $to = ["\+", "\-", "\=", "\&&", "\|", "\!", "\(", "\)", "\{", "\}", "\[", "\]", "\^", '\"', "\~", "\*", "\?", "\:", "\\\\", "\/"];
2648
2649
        return str_replace($from, $to, $string);
2650
    }
2651
}
2652