Conditions | 34 |
Paths | > 20000 |
Total Lines | 131 |
Code Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
64 | public function processSite($groupID, $guidChar, $process, bool $local = false): void |
||
65 | { |
||
66 | $res = $this->getTvReleases($groupID, $guidChar, $process, parent::PROCESS_TVDB); |
||
67 | |||
68 | $tvCount = \count($res); |
||
69 | |||
70 | if ($this->echooutput && $tvCount > 0) { |
||
71 | $this->colorCli->header('Processing TVDB lookup for '.number_format($tvCount).' release(s).', true); |
||
72 | } |
||
73 | $this->titleCache = []; |
||
74 | |||
75 | foreach ($res as $row) { |
||
76 | $tvDbId = false; |
||
77 | $this->posterUrl = ''; |
||
78 | |||
79 | // Clean the show name for better match probability |
||
80 | $release = $this->parseInfo($row['searchname']); |
||
81 | if (\is_array($release) && $release['name'] !== '') { |
||
82 | if (\in_array($release['cleanname'], $this->titleCache, false)) { |
||
83 | if ($this->echooutput) { |
||
84 | $this->colorCli->headerOver('Title: '). |
||
85 | $this->colorCli->warningOver($release['cleanname']). |
||
86 | $this->colorCli->header(' already failed lookup for this site. Skipping.', true); |
||
87 | } |
||
88 | $this->setVideoNotFound(parent::PROCESS_TVMAZE, $row['id']); |
||
89 | |||
90 | continue; |
||
91 | } |
||
92 | |||
93 | // Find the Video ID if it already exists by checking the title. |
||
94 | $videoId = $this->getByTitle($release['cleanname'], parent::TYPE_TV); |
||
95 | |||
96 | if ($videoId !== 0) { |
||
97 | $tvDbId = $this->getSiteByID('tvdb', $videoId); |
||
98 | } |
||
99 | |||
100 | // Force local lookup only |
||
101 | $lookupSetting = true; |
||
102 | if ($local === true || $this->local) { |
||
103 | $lookupSetting = false; |
||
104 | } |
||
105 | |||
106 | if ($tvDbId === false && $lookupSetting) { |
||
107 | // If it doesn't exist locally and lookups are allowed lets try to get it. |
||
108 | if ($this->echooutput) { |
||
109 | $this->colorCli->climate()->error('Video ID for '.$release['cleanname'].' not found in local db, checking web.'); |
||
110 | } |
||
111 | |||
112 | // Check if we have a valid country and set it in the array |
||
113 | $country = ( |
||
114 | isset($release['country']) && \strlen($release['country']) === 2 |
||
115 | ? (string) $release['country'] |
||
116 | : '' |
||
117 | ); |
||
118 | |||
119 | // Get the show from TVDB |
||
120 | $tvdbShow = $this->getShowInfo((string) $release['cleanname']); |
||
121 | |||
122 | if (\is_array($tvdbShow)) { |
||
123 | $tvdbShow['country'] = $country; |
||
124 | $videoId = $this->add($tvdbShow); |
||
125 | $tvDbId = (int) $tvdbShow['tvdb']; |
||
126 | } |
||
127 | } elseif ($this->echooutput && $tvDbId !== false) { |
||
128 | $this->colorCli->climate()->info('Video ID for '.$release['cleanname'].' found in local db, attempting episode match.'); |
||
129 | } |
||
130 | |||
131 | if ((int) $videoId > 0 && (int) $tvDbId > 0) { |
||
132 | if (! empty($tvdbShow['poster'])) { // Use TVDB poster if available |
||
133 | $this->getPoster($videoId); |
||
134 | } else { // Check Fanart.tv for poster |
||
135 | $poster = $this->fanart->getTVFanArt($tvDbId); |
||
136 | if ($poster) { |
||
137 | $this->posterUrl = collect($poster['tvposter'])->sortByDesc('likes')[0]['url']; |
||
138 | $this->getPoster($videoId); |
||
139 | } |
||
140 | } |
||
141 | |||
142 | $seasonNo = (! empty($release['season']) ? preg_replace('/^S0*/i', '', $release['season']) : ''); |
||
143 | $episodeNo = (! empty($release['episode']) ? preg_replace('/^E0*/i', '', $release['episode']) : ''); |
||
144 | |||
145 | if ($episodeNo === 'all') { |
||
146 | // Set the video ID and leave episode 0 |
||
147 | $this->setVideoIdFound($videoId, $row['id'], 0); |
||
148 | $this->colorCli->climate()->info('Found TVDB Match for Full Season!'); |
||
149 | |||
150 | continue; |
||
151 | } |
||
152 | |||
153 | // Download all episodes if new show to reduce API/bandwidth usage |
||
154 | if (! $this->countEpsByVideoID($videoId)) { |
||
155 | $this->getEpisodeInfo($tvDbId, -1, -1, $videoId); |
||
156 | } |
||
157 | |||
158 | // Check if we have the episode for this video ID |
||
159 | $episode = $this->getBySeasonEp($videoId, $seasonNo, $episodeNo, $release['airdate']); |
||
160 | |||
161 | if ($episode === false && $lookupSetting) { |
||
162 | // Send the request for the episode to TVDB |
||
163 | $tvdbEpisode = $this->getEpisodeInfo( |
||
164 | $tvDbId, |
||
165 | (int) $seasonNo, |
||
166 | (int) $episodeNo, |
||
167 | $videoId |
||
168 | ); |
||
169 | |||
170 | if ($tvdbEpisode) { |
||
171 | $episode = $this->addEpisode($videoId, $tvdbEpisode); |
||
172 | } |
||
173 | } |
||
174 | |||
175 | if ($episode !== false && is_numeric($episode) && $episode > 0) { |
||
176 | // Mark the releases video and episode IDs |
||
177 | $this->setVideoIdFound($videoId, $row['id'], $episode); |
||
178 | if ($this->echooutput) { |
||
179 | $this->colorCli->climate()->info('Found TVDB Match!'); |
||
180 | } |
||
181 | } else { |
||
182 | //Processing failed, set the episode ID to the next processing group |
||
183 | $this->setVideoIdFound($videoId, $row['id'], 0); |
||
184 | $this->setVideoNotFound(parent::PROCESS_TVMAZE, $row['id']); |
||
185 | } |
||
186 | } else { |
||
187 | //Processing failed, set the episode ID to the next processing group |
||
188 | $this->setVideoNotFound(parent::PROCESS_TVMAZE, $row['id']); |
||
189 | $this->titleCache[] = $release['cleanname'] ?? null; |
||
190 | } |
||
191 | } else { |
||
192 | //Parsing failed, take it out of the queue for examination |
||
193 | $this->setVideoNotFound(parent::FAILED_PARSE, $row['id']); |
||
194 | $this->titleCache[] = $release['cleanname'] ?? null; |
||
195 | } |
||
443 |