|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Services\TvProcessing\Pipes; |
|
4
|
|
|
|
|
5
|
|
|
use App\Services\TvProcessing\TvProcessingPassable; |
|
6
|
|
|
use App\Services\TvProcessing\TvProcessingResult; |
|
7
|
|
|
use Blacklight\processing\tv\LocalDB; |
|
8
|
|
|
use Closure; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Initial pipe that parses the release name into structured info. |
|
12
|
|
|
* This must run before any provider pipes. |
|
13
|
|
|
*/ |
|
14
|
|
|
class ParseInfoPipe extends AbstractTvProviderPipe |
|
15
|
|
|
{ |
|
16
|
|
|
protected int $priority = 1; |
|
17
|
|
|
private ?LocalDB $localDb = null; |
|
18
|
|
|
|
|
19
|
|
|
public function getName(): string |
|
20
|
|
|
{ |
|
21
|
|
|
return 'ParseInfo'; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function getStatusCode(): int |
|
25
|
|
|
{ |
|
26
|
|
|
return 0; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get or create the LocalDB instance for parsing. |
|
31
|
|
|
*/ |
|
32
|
|
|
private function getLocalDb(): LocalDB |
|
33
|
|
|
{ |
|
34
|
|
|
if ($this->localDb === null) { |
|
35
|
|
|
$this->localDb = new LocalDB(); |
|
36
|
|
|
} |
|
37
|
|
|
return $this->localDb; |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Override handle to perform parsing before the standard processing flow. |
|
42
|
|
|
*/ |
|
43
|
|
|
public function handle(TvProcessingPassable $passable, Closure $next): TvProcessingPassable |
|
44
|
|
|
{ |
|
45
|
|
|
$parsedInfo = $this->getLocalDb()->parseInfo($passable->context->searchName); |
|
46
|
|
|
|
|
47
|
|
|
if ($parsedInfo === false || empty($parsedInfo['name'])) { |
|
48
|
|
|
// Mark as parse failed |
|
49
|
|
|
$passable->setParsedInfo(null); |
|
50
|
|
|
$passable->updateResult( |
|
51
|
|
|
TvProcessingResult::parseFailed(['search_name' => $passable->context->searchName]), |
|
52
|
|
|
$this->getName() |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
if ($this->echoOutput) { |
|
56
|
|
|
$this->colorCli->error(sprintf( |
|
57
|
|
|
' ✗ Parse failed: %s', |
|
58
|
|
|
mb_substr($passable->context->searchName, 0, 50) |
|
59
|
|
|
)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// Don't continue to other pipes - can't process without parsed info |
|
63
|
|
|
return $passable; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$passable->setParsedInfo($parsedInfo); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
return $next($passable); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function process(TvProcessingPassable $passable): TvProcessingResult |
|
72
|
|
|
{ |
|
73
|
|
|
// Not used - we override handle() instead |
|
74
|
|
|
return TvProcessingResult::pending(); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|