Skip to content

Commit

Permalink
Update Movie class, fetch movie info from IMDb first before trying ot…
Browse files Browse the repository at this point in the history
…her sources
  • Loading branch information
DariusIII committed Sep 19, 2018
1 parent 8cb7f14 commit 47c61ba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
54 changes: 34 additions & 20 deletions Blacklight/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Imdb\Title;
use Imdb\Config;
use Imdb\TitleSearch;
use Tmdb\ApiToken;
use aharen\OMDbAPI;
use GuzzleHttp\Client;
Expand Down Expand Up @@ -910,13 +911,13 @@ public function fetchTMDBProperties($imdbId, $text = false)
public function fetchIMDBProperties($imdbId)
{
$result = new Title($imdbId, $this->config);
if (! empty($result->title())) {
similar_text($this->currentTitle, $result->title(), $percent);
if (! empty($result->orig_title())) {
similar_text($this->currentTitle, $result->orig_title(), $percent);
if ($percent > self::MATCH_PERCENT) {
similar_text($this->currentYear, $result->year(), $percent);
if ($percent >= self::YEAR_MATCH_PERCENT) {
$ret = [
'title' => $result->title(),
'title' => $result->orig_title(),
'tagline' => $result->tagline(),
'plot' => array_get($result->plot_split(), '0.plot'),
'rating' => ! empty($result->rating()) ? $result->rating() : '',
Expand All @@ -928,7 +929,7 @@ public function fetchIMDBProperties($imdbId)
];

if ($this->echooutput) {
ColorCLI::doEcho(ColorCLI::headerOver('IMDb Found ').ColorCLI::primaryOver($result->title()), true);
ColorCLI::doEcho(ColorCLI::headerOver('IMDb Found ').ColorCLI::primaryOver($result->orig_title()), true);
}

return $ret;
Expand Down Expand Up @@ -1160,6 +1161,23 @@ public function processMovieReleases($groupID = '', $guidChar = '', $lookupIMDB
}
}

// Check on IMDb first
if ($movieUpdated === false) {
$imdbSearch = new TitleSearch($this->config);
foreach ($imdbSearch->search($this->currentTitle, [TitleSearch::MOVIE]) as $imdbTitle) {
if (! empty($imdbTitle->orig_title())) {
similar_text($imdbTitle->orig_title(), $this->currentTitle, $percent);
if ($percent >= self::MATCH_PERCENT) {
$getIMDBid = $imdbTitle->imdbid();
$imdbID = $this->doMovieUpdate('tt'.$getIMDBid, 'IMDb', $arr['id']);
if ($imdbID !== false) {
$movieUpdated = true;
}
}
}
}
}

// Check on OMDbAPI
if ($movieUpdated === false) {
$omdbTitle = strtolower(str_replace(' ', '_', $this->currentTitle));
Expand Down Expand Up @@ -1196,26 +1214,22 @@ public function processMovieReleases($groupID = '', $guidChar = '', $lookupIMDB
// Check on The Movie Database.
if ($movieUpdated === false) {
$data = $this->tmdbclient->getSearchApi()->searchMovies($this->currentTitle);
if ($data['total_results'] > 0) {
if (! empty($data['results'])) {
foreach ($data['results'] as $result) {
if (! empty($result['id'])) {
similar_text($this->currentYear, Carbon::parse($result['release_date'])->year, $percent);
if ($percent > 80) {
$ret = $this->fetchTMDBProperties($result['id'], true);
if ($ret !== false && ! empty($ret['imdbid'])) {
$imdbID = $this->doMovieUpdate('tt'.$ret['imdbid'], 'TMDB', $arr['id']);
if ($imdbID !== false) {
$movieUpdated = true;
}
if (($data['total_results'] > 0) && ! empty($data['results'])) {
foreach ($data['results'] as $result) {
if (! empty($result['id'])) {
similar_text($this->currentYear, Carbon::parse($result['release_date'])->year, $percent);
if ($percent > 80) {
$ret = $this->fetchTMDBProperties($result['id'], true);
if ($ret !== false && ! empty($ret['imdbid'])) {
$imdbID = $this->doMovieUpdate('tt'.$ret['imdbid'], 'TMDB', $arr['id']);
if ($imdbID !== false) {
$movieUpdated = true;
}
}
} else {
$movieUpdated = false;
}
} else {
$movieUpdated = false;
}
} else {
$movieUpdated = false;
}
} else {
$movieUpdated = false;
Expand Down
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
2018-09-19 DariusIII
* Chg: Update Movie class, fetch movie info from IMDb first before trying other sources
* Chg: Try to prevent foreign key erros in ReleaseFile model
* Chg: Use dirape/token to generate tokens and passwords for users
2018-09-18 DariusIII
Expand Down

0 comments on commit 47c61ba

Please sign in to comment.