From b1cc81773bf3d5568e25f9bc37efd8842ec5610c Mon Sep 17 00:00:00 2001 From: Darko Date: Fri, 11 Sep 2015 15:36:06 +0200 Subject: [PATCH] Add support for traktid into releaseas and movies. Add script to populate traktid for existing releases with imdbid and rageid. --- misc/testing/DB/populateTraktID.php | 48 ++++++++++++++++++++++++++ misc/testing/refreshMovie.php | 16 ++++----- newznab/build/newznab.xml | 4 +-- newznab/controllers/Movie.php | 20 ++++++++++- resources/db/patches/0186~releases.sql | 1 + 5 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 misc/testing/DB/populateTraktID.php create mode 100644 resources/db/patches/0186~releases.sql diff --git a/misc/testing/DB/populateTraktID.php b/misc/testing/DB/populateTraktID.php new file mode 100644 index 000000000..f082dacee --- /dev/null +++ b/misc/testing/DB/populateTraktID.php @@ -0,0 +1,48 @@ + $pdo]); + +$mreleases = $pdo->queryDirect(sprintf('SELECT id, imdbid FROM releases WHERE traktid = 0 AND imdbid IS NOT NULL AND imdbid != 0000000 ORDER BY id ASC')); +$treleases = $pdo->queryDirect(sprintf('SELECT id, rageid FROM releases WHERE traktid = 0 AND rageid NOT IN(0,-1,-2)')); +$mtotal = $mreleases->rowCount(); +$ttotal = $treleases->rowCount(); +$mcount = 0; +if ($mtotal > 0) { + echo $pdo->log->header("Updating Trakt ID for " . number_format($mtotal) . " movies."); + foreach ($mreleases as $rel) { + $mcount++; + $data = $trakt->movieSummary('tt' . $rel['imdbid'], 'min'); + if ($data != false) { + if (isset($data['ids']['trakt'])) { + $pdo->queryExec(sprintf('UPDATE releases SET traktid = %s WHERE id = %s', $pdo->escapeString($data['ids']['trakt']), $pdo->escapeString($rel['id']))); + echo $pdo->log->info('Updated ' . $data['title'] . ' with Trakt ID:' . $data['ids']['trakt']); + } + } + } + echo $pdo->log->header('Updated ' . $mcount . ' movie(s).'); +} else { + echo $pdo->log->info('No movies need updating'); +} + +$tcount = 0; +if ($ttotal > 0) { + echo $pdo->log->header("Updating Trakt ID for " . number_format($ttotal) . " shows."); + foreach ($treleases as $rel) { + $tcount++; + $data = $trakt->showSummary($rel['rageid'], 'min'); + if ($data != false) { + if (isset($data['ids']['trakt'])) { + $pdo->queryExec(sprintf('UPDATE releases SET traktid = %s WHERE id = %s', $pdo->escapeString($data['ids']['trakt']), $pdo->escapeString($rel['id']))); + echo $pdo->log->info('Updated ' . $data['title'] . ' with Trakt ID:' . $data['ids']['trakt']); + } + } + } + echo $pdo->log->header('Updated ' . $tcount . ' show(s).'); +} else { + exit($pdo->log->info('No shows need updating')); +} \ No newline at end of file diff --git a/misc/testing/refreshMovie.php b/misc/testing/refreshMovie.php index 11cdbb351..e53aad697 100644 --- a/misc/testing/refreshMovie.php +++ b/misc/testing/refreshMovie.php @@ -4,8 +4,8 @@ require_once dirname(__FILE__) . '/../../www/config.php'; use newznab\db\Settings; -$movie = new Movie(true); $db = new Settings(); +$movie = new Movie(['Echo' => true, 'Settings' => $pdo]); $movies = []; $counter = 1; $sleepsecsbetweenscrape = 1; @@ -14,19 +14,19 @@ $sleepsecsbetweenscrape = 1; //print_r($movie->fetchImdbProperties("1375666")); // CASE 1 - UPDATE ALL RECORDS -//$movies = $db->query("SELECT imdbID from movieinfo"); +//$movies = $db->query("SELECT imdbid from movieinfo"); // CASE 2 - UPDATE ALL WITH A BLANK TITLE -//$movies = $db->query("SELECT imdbID from movieinfo where title = ''"); +//$movies = $db->query("SELECT imdbid from movieinfo where title = ''"); // CASE 3 - UPDATE ALL RECORDS NOT UPDATED IN THE LAST 6 MONTHS -//$movies = $db->query("SELECT imdbID from movieinfo where updateddate < DATE_ADD(NOW(), INTERVAL -6 MONTH)"); +//$movies = $db->query("SELECT imdbid from movieinfo where updateddate < DATE_ADD(NOW(), INTERVAL -6 MONTH)"); // CASE 4 - UPDATE ALL RECORDS WHERE COVER IS EMPTY -//$movies = $db->query("SELECT imdbID from movieinfo where cover = 0"); +//$movies = $db->query("SELECT imdbid from movieinfo where cover = 0"); // CASE 5 - UPDATE ALL WITH NO TRAILER -//$movies = $db->query("SELECT imdbID from movieinfo where trailer is null and tmdbid is not null"); +//$movies = $db->query("SELECT imdbid from movieinfo where trailer is null and tmdbid is not null"); if (count($movies) == 0) @@ -37,7 +37,7 @@ if (count($movies) == 0) echo "Updating ".count($movies)." records - Sleep interval ".$sleepsecsbetweenscrape." second(s)\n"; foreach ($movies as $mov) { - echo "Updating ".$mov['imdbID']." (".$counter++."/".count($movies).")\n"; - $mov = $movie->updateMovieInfo($mov['imdbID']); + echo "Updating ".$mov['imdbid']." (".$counter++."/".count($movies).")\n"; + $mov = $movie->updateMovieInfo($mov['imdbid']); sleep($sleepsecsbetweenscrape); } \ No newline at end of file diff --git a/newznab/build/newznab.xml b/newznab/build/newznab.xml index 4404f8588..6f7252430 100644 --- a/newznab/build/newznab.xml +++ b/newznab/build/newznab.xml @@ -2,8 +2,8 @@ - 185 - 185 + 186 + 186 0.4.1 diff --git a/newznab/controllers/Movie.php b/newznab/controllers/Movie.php index ac5eb5e01..1e02a1e3b 100644 --- a/newznab/controllers/Movie.php +++ b/newznab/controllers/Movie.php @@ -1020,7 +1020,7 @@ class Movie /** * Update a release with a IMDB id. * - * @param string $buffer Data to parse a IMDB id from. + * @param string $buffer Data to parse a IMDB id/Trakt Id from. * @param string $service Method that called this method. * @param int $id id of the release. * @param int $processImdb To get IMDB info on this IMDB id or not. @@ -1033,6 +1033,18 @@ class Movie if (is_string($buffer) && preg_match('/(?:imdb.*?)?(?:tt|Title\?)(?P\d{5,7})/i', $buffer, $matches)) { $imdbID = $matches['imdbid']; } + $traktID = false; + if (is_string($buffer) && preg_match('/(?:trakt.*?)/i', $buffer, $matches)) { + $traktID = $matches['trakt']; + } + + if ($traktID !== false){ + if ($this->echooutput && $this->service !== '') { + $this->pdo->log->doEcho($this->pdo->log->headerOver($service . ' found Trakt id: ') . $this->pdo->log->primary($traktID)); + } + + $this->pdo->queryExec(sprintf('UPDATE releases SET traktid = %d WHERE id = %d', $this->pdo->escapeString($traktID), $id)); + } if ($imdbID !== false) { $this->service = $service; @@ -1155,6 +1167,12 @@ class Movie continue; } } + if (isset($data['ids']['trakt'])) { + $traktID = $this->doMovieUpdate($data['ids']['trakt'], 'Trakt', $arr['id']); + if ($traktID !== false) { + continue; + } + } } // Try on search engines. diff --git a/resources/db/patches/0186~releases.sql b/resources/db/patches/0186~releases.sql new file mode 100644 index 000000000..27c71e55d --- /dev/null +++ b/resources/db/patches/0186~releases.sql @@ -0,0 +1 @@ +ALTER TABLE releases ADD traktid INT(10) UNSIGNED NOT NULL DEFAULT 0; \ No newline at end of file