|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Services\TvProcessing; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Passable object that travels through the TV processing pipeline. |
|
7
|
|
|
*/ |
|
8
|
|
|
class TvProcessingPassable |
|
9
|
|
|
{ |
|
10
|
|
|
public TvReleaseContext $context; |
|
11
|
|
|
public TvProcessingResult $result; |
|
12
|
|
|
public bool $debug; |
|
13
|
|
|
public array $providerResults = []; |
|
14
|
|
|
public ?array $parsedInfo = null; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct(TvReleaseContext $context, bool $debug = false) |
|
17
|
|
|
{ |
|
18
|
|
|
$this->context = $context; |
|
19
|
|
|
$this->debug = $debug; |
|
20
|
|
|
$this->result = TvProcessingResult::pending(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Check if we should stop processing (match found). |
|
25
|
|
|
*/ |
|
26
|
|
|
public function shouldStopProcessing(): bool |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->result->isMatched(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Update the result from a provider. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function updateResult(TvProcessingResult $result, string $providerName): void |
|
35
|
|
|
{ |
|
36
|
|
|
if ($this->debug) { |
|
37
|
|
|
$this->providerResults[$providerName] = [ |
|
38
|
|
|
'status' => $result->status, |
|
39
|
|
|
'video_id' => $result->videoId, |
|
40
|
|
|
'episode_id' => $result->episodeId, |
|
41
|
|
|
'debug' => $result->debug, |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// Update if we got a match |
|
46
|
|
|
if ($result->isMatched()) { |
|
47
|
|
|
$this->result = $result; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Set the parsed release info. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function setParsedInfo(?array $info): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->parsedInfo = $info; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get the parsed release info. |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getParsedInfo(): ?array |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->parsedInfo; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Check if we have valid parsed info. |
|
69
|
|
|
*/ |
|
70
|
|
|
public function hasValidParsedInfo(): bool |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->parsedInfo !== null |
|
73
|
|
|
&& ! empty($this->parsedInfo['name']) |
|
74
|
|
|
&& isset($this->parsedInfo['season'], $this->parsedInfo['episode']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Build the final result array. |
|
79
|
|
|
*/ |
|
80
|
|
|
public function toArray(): array |
|
81
|
|
|
{ |
|
82
|
|
|
$returnValue = [ |
|
83
|
|
|
'status' => $this->result->status, |
|
84
|
|
|
'video_id' => $this->result->videoId, |
|
85
|
|
|
'episode_id' => $this->result->episodeId, |
|
86
|
|
|
'provider' => $this->result->providerName, |
|
87
|
|
|
]; |
|
88
|
|
|
|
|
89
|
|
|
if ($this->debug) { |
|
90
|
|
|
$returnValue['debug'] = [ |
|
91
|
|
|
'release_id' => $this->context->releaseId, |
|
92
|
|
|
'search_name' => $this->context->searchName, |
|
93
|
|
|
'parsed_info' => $this->parsedInfo, |
|
94
|
|
|
'provider_results' => $this->providerResults, |
|
95
|
|
|
]; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $returnValue; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|