Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to Fanart.tv poster if none was provided by TVDB #1298

Merged
merged 1 commit into from Apr 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Blacklight/processing/tv/TVDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Blacklight\processing\tv;

use Blacklight\ReleaseImage;
use Blacklight\libraries\FanartTV;
use CanIHaveSomeCoffee\TheTVDbAPI\Exception\ParseException;
use CanIHaveSomeCoffee\TheTVDbAPI\Exception\ResourceNotFoundException;
use CanIHaveSomeCoffee\TheTVDbAPI\Exception\UnauthorizedException;
Expand Down Expand Up @@ -32,6 +33,10 @@ class TVDB extends TV
* @bool Do a local lookup only if server is down
*/
private bool $local;

private FanartTV $fanart;

private mixed $fanartapikey;

/**
* TVDB constructor.
Expand All @@ -57,6 +62,11 @@ public function __construct(array $options = [])
if ($this->token !== '') {
$this->client->setToken($this->token);
}

$this->fanartapikey = config('nntmux_api.fanarttv_api_key');
if ($this->fanartapikey !== null) {
$this->fanart = new FanartTV($this->fanartapikey);
}
}

/**
Expand Down Expand Up @@ -131,7 +141,11 @@ public function processSite($groupID, $guidChar, $process, bool $local = false):
}

if ((int) $videoId > 0 && (int) $tvDbId > 0) {
if (! empty($tvdbShow['poster'])) {
if (! empty($tvdbShow['poster'])) { // Use TVDB poster if available
$this->getPoster($videoId);
} else { // Check Fanart.tv for poster
$poster = $this->fanart->getTVFanart($tvDbId);
$this->posterUrl = collect($poster['tvposter'])->sortByDesc('likes')[0]['url'];
$this->getPoster($videoId);
}

Expand Down