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