Beispiel #1
0
 /**
  * Fetch info for IMDB id from TMDB.
  *
  * @param string  $imdbId
  * @param boolean $text
  *
  * @return array|bool
  */
 public function fetchTMDBProperties($imdbId, $text = false)
 {
     $lookupId = $text === false ? 'tt' . $imdbId : $imdbId;
     try {
         $tmdbLookup = $this->tmdb->getMovie($lookupId);
     } catch (\Exception $e) {
         return false;
     }
     if (!$tmdbLookup || isset($tmdbLookup['status_code']) && $tmdbLookup['status_code'] !== 1) {
         return false;
     }
     $ret = [];
     $ret['title'] = $tmdbLookup['title'];
     if ($this->currentTitle !== '') {
         // Check the similarity.
         similar_text($this->currentTitle, $ret['title'], $percent);
         if ($percent < 40) {
             if ($this->debug) {
                 $this->debugging->log(get_class(), __FUNCTION__, 'Found (' . $ret['title'] . ') from TMDB, but it\'s only ' . $percent . '% similar to (' . $this->currentTitle . ')', Logger::LOG_INFO);
             }
             return false;
         }
     }
     $ret['tmdb_id'] = $tmdbLookup['id'];
     $ImdbID = str_replace('tt', '', $tmdbLookup['imdb_id']);
     $ret['imdb_id'] = $ImdbID;
     if (isset($tmdbLookup['vote_average'])) {
         $ret['rating'] = $tmdbLookup['vote_average'] == 0 ? '' : $tmdbLookup['vote_average'];
     }
     if (isset($tmdbLookup['overview'])) {
         $ret['plot'] = $tmdbLookup['overview'];
     }
     if (isset($tmdbLookup['tagline'])) {
         $ret['tagline'] = $tmdbLookup['tagline'];
     }
     if (isset($tmdbLookup['release_date'])) {
         $ret['year'] = date("Y", strtotime($tmdbLookup['release_date']));
     }
     if (isset($tmdbLookup['genres']) && sizeof($tmdbLookup['genres']) > 0) {
         $genres = [];
         foreach ($tmdbLookup['genres'] as $genre) {
             $genres[] = $genre['name'];
         }
         $ret['genre'] = $genres;
     }
     if (isset($tmdbLookup['poster_path']) && sizeof($tmdbLookup['poster_path']) > 0) {
         $ret['cover'] = "http://image.tmdb.org/t/p/w185" . $tmdbLookup['poster_path'];
     }
     if (isset($tmdbLookup['backdrop_path']) && sizeof($tmdbLookup['backdrop_path']) > 0) {
         $ret['backdrop'] = "http://image.tmdb.org/t/p/original" . $tmdbLookup['backdrop_path'];
     }
     if ($this->echooutput) {
         $this->pdo->log->doEcho($this->pdo->log->primaryOver("TMDb Found ") . $this->pdo->log->headerOver($ret['title']), true);
     }
     return $ret;
 }
Beispiel #2
0
 public function fetchTmdbProperties($imdbId)
 {
     $tmdb = new TMDb($this->apikey);
     $lookupId = 'tt' . $imdbId;
     $tmdbLookup = json_decode($tmdb->getMovie($lookupId, TMDb::IMDB));
     if (!$tmdbLookup) {
         return false;
     }
     $movie = array_shift($tmdbLookup);
     if ($movie == 'Nothing found.') {
         return false;
     }
     $ret = array();
     $ret['title'] = $movie->name;
     $ret['tmdb_id'] = $movie->id;
     $ret['imdb_id'] = $imdbId;
     $ret['rating'] = $movie->rating == 0 ? '' : $movie->rating;
     $ret['plot'] = $movie->overview;
     $ret['year'] = date("Y", strtotime($movie->released));
     if (isset($movie->genres) && sizeof($movie->genres) > 0) {
         $genres = array();
         foreach ($movie->genres as $genre) {
             $genres[] = $genre->name;
         }
         $ret['genre'] = $genres;
     }
     if (isset($movie->posters) && sizeof($movie->posters) > 0) {
         foreach ($movie->posters as $poster) {
             if ($poster->image->size == 'cover') {
                 $ret['cover'] = $poster->image->url;
                 break;
             }
         }
     }
     if (isset($movie->backdrops) && sizeof($movie->backdrops) > 0) {
         foreach ($movie->backdrops as $backdrop) {
             if ($backdrop->image->size == 'original') {
                 $ret['backdrop'] = $backdrop->image->url;
                 break;
             }
         }
     }
     return $ret;
 }
Beispiel #3
0
    $cats[] = "2040";
    $m = new Movie(false);
    $mi = $m->getMovieInfo($_REQUEST["add"]);
    if (!$mi) {
        $m->updateMovieInfo($_REQUEST["add"]);
    }
    $usermovies = $um->addMovie($users->currentUserId(), $_REQUEST["add"], $cats);
} else {
    if (!isset($_REQUEST["id"])) {
        $page->show404();
    }
    $s = new Sites();
    $site = $s->get();
    $tmdb = new TMDb($site->tmdbkey);
    if (is_numeric($_REQUEST["id"])) {
        $obj = json_decode($tmdb->getMovie($_REQUEST["id"], TMDb::IMDB));
    } else {
        $obj = json_decode($tmdb->searchMovie($_REQUEST["id"]));
    }
    $imdbids = array();
    if (count($obj) > 0) {
        foreach ($obj as $movie) {
            if (isset($movie->name) && isset($movie->imdb_id)) {
                $imdbids[] = str_replace("tt", "", $movie->imdb_id);
                if (isset($movie->posters) && sizeof($movie->posters) > 0) {
                    foreach ($movie->posters as $poster) {
                        if ($poster->image->size == 'cover') {
                            $movie->coverimg = $poster->image->url;
                            break;
                        }
                    }
Beispiel #4
0
 /**
  * Lookup a movie on tmdb by id
  */
 public function fetchTmdbProperties($id, $isImdbId = true)
 {
     $tmdb = new TMDb($this->apikey, $this->lookuplanguage);
     $lookupId = $isImdbId ? 'tt' . $id : $id;
     try {
         $movie = $tmdb->getMovie($lookupId);
     } catch (Exception $e) {
         return false;
     }
     if (!$movie || !is_array($movie)) {
         return false;
     }
     if (isset($movie['status_code']) && $movie['status_code'] > 1) {
         return false;
     }
     $ret = array();
     $ret['title'] = $movie['title'];
     $ret['tmdb_id'] = $movie['id'];
     $ret['imdb_id'] = str_replace('tt', '', $movie['imdb_id']);
     $ret['rating'] = $movie['vote_average'] == 0 ? '' : $movie['vote_average'];
     $ret['plot'] = $movie['overview'];
     if (isset($movie['tagline'])) {
         $ret['tagline'] = $movie['tagline'];
     }
     if (isset($movie['release_date'])) {
         $ret['year'] = date("Y", strtotime($movie['release_date']));
     }
     if (isset($movie['genres']) && sizeof($movie['genres']) > 0) {
         $genres = array();
         foreach ($movie['genres'] as $genre) {
             $genres[] = $genre['name'];
         }
         $ret['genre'] = $genres;
     }
     if (isset($movie['trailers']) && isset($movie['trailers']['youtube']) && sizeof($movie['trailers']['youtube']) > 0) {
         foreach ($movie['trailers']['youtube'] as $trailer) {
             $ret['trailer'] = $trailer['source'];
             break;
         }
     }
     if (isset($movie['poster_path'])) {
         $ret['cover'] = $tmdb->getImageUrl($movie['poster_path'], TMDb::IMAGE_POSTER, "w185");
     }
     if (isset($movie['backdrop_path'])) {
         $ret['backdrop'] = $tmdb->getImageUrl($movie['backdrop_path'], TMDb::IMAGE_BACKDROP, "w300");
     }
     return $ret;
 }
gensession.php" class="btn">request token</a><?php 
} else {
    if (empty($_SESSION['tmdb_id'])) {
        $account = $tmdb->getAccount($_SESSION['tmdb_session_id']);
        $_SESSION['tmdb_username'] = $account['username'];
        $_SESSION['tmdb_id'] = $account['id'];
        $_SESSION['tmdb_language'] = $account['iso_3166_1'];
    }
    if (isset($_GET["action"])) {
        if ($_GET["action"] == 'updategenres') {
            $query = "SELECT * from movies";
            $result = mysql_query($query) or die('Query failed: ' . mysql_error());
            ob_flush();
            flush();
            while ($row = mysql_fetch_assoc($result)) {
                $movie = $tmdb->getMovie($row['tmdb_id']);
                updateMovieGenres($movie["genres"], $row['tmdb_id']);
                echo "movie " . $row['title'] . " has " . count($movie["genres"]) . " genres updated<br>";
            }
        } elseif ($_GET["action"] == 'importall') {
            ob_end_flush();
            $movies = $tmdb->getMoviesByGenre('28');
            echo "<pre>";
            var_dump($movies);
        } elseif ($_GET["action"] == 'sanatizeall') {
            $query = "SELECT * from movies";
            $result = mysql_query($query) or die('Query failed: ' . mysql_error());
            $i = 0;
            while ($row = mysql_fetch_assoc($result)) {
                $query = "\n\t\t\t\t\t\tUPDATE `flamestr`.`movies` \n\t\t\t\t\t\tSET\n\t\t\t\t\t\turl = '" . sanitize($row['title'] . "-" . $row['tmdb_id']) . "'\n\t\t\t\t\t\tWHERE id = '" . $row['id'] . "'";
                mysql_query($query) or die('Query failed: ' . mysql_error());
 /**
  * Get movie by ID. Load casts and images too.
  * 
  * Return a JSON string containing fetched data. Apply some filtering
  * to extract specific crew jobs like director or producer.
  *
  * @since    1.0
  * 
  * @param    string    $id Id to search in the TMDb database
  * @param    string    $lang Lang to use in the query
  * @param    int       $post_id Related Post ID
  *
  * @return   string    JSON formatted results.
  */
 public static function _get_movie_by_id($id, $lang, $post_id = null)
 {
     $tmdb = new TMDb();
     $data = array('movie' => $tmdb->getMovie($id, $lang), 'casts' => $tmdb->getMovieCast($id), 'images' => $tmdb->getMovieImages($id, ''), 'release' => $tmdb->getMovieRelease($id));
     foreach ($data as $d) {
         if (is_wp_error($d)) {
             return $d;
         }
     }
     extract($data, EXTR_SKIP);
     $poster_path = $movie['poster_path'];
     $movie = apply_filters('wpmoly_filter_meta_data', $movie);
     $casts = apply_filters('wpmoly_filter_crew_data', $casts);
     $meta = array_merge($movie, $casts);
     $meta['tmdb_id'] = $id;
     $meta['certification'] = '';
     if (isset($release['countries'])) {
         $certification_alt = '';
         foreach ($release['countries'] as $country) {
             if ($country['iso_3166_1'] == wpmoly_o('api-country')) {
                 $meta['certification'] = $country['certification'];
                 $meta['local_release_date'] = $country['release_date'];
             } else {
                 if ($country['iso_3166_1'] == wpmoly_o('api-country-alt')) {
                     $certification_alt = $country['certification'];
                 }
             }
         }
         if ('' == $meta['certification']) {
             $meta['certification'] = $certification_alt;
         }
         if ('' == $meta['local_release_date']) {
             $meta['local_release_date'] = '';
         }
     }
     if (is_null($poster_path)) {
         $poster_path = str_replace('{size}', '-medium', WPMOLY_DEFAULT_POSTER_URL);
     }
     if (is_null($poster_path)) {
         $poster = $poster_path;
     } else {
         $poster = self::get_image_url($poster_path, 'poster', 'small');
     }
     $_images = array('images' => $images['backdrops']);
     $_full = array_merge($movie, $casts, $images);
     $_movie = array('_id' => $post_id, '_tmdb_id' => $id, 'meta' => $meta, 'images' => $images, 'poster' => $poster, 'poster_path' => $poster_path, '_result' => 'movie', '_full' => $_full);
     $_movie['taxonomy'] = array();
     // Prepare Custom Taxonomy
     if (1 == wpmoly_o('actor-autocomplete')) {
         $_movie['taxonomy']['actors'] = array();
         if (!empty($casts['cast']) && 1 == wpmoly_o('enable-actor')) {
             foreach ($casts['cast'] as $actor) {
                 $_movie['taxonomy']['actors'][] = $actor;
             }
         }
     }
     // Prepare Custom Taxonomy
     if (1 == wpmoly_o('genre-autocomplete')) {
         $_movie['taxonomy']['genres'] = array();
         if (!empty($movie['genres']) && 1 == wpmoly_o('enable-genre')) {
             foreach ($movie['genres'] as $genre) {
                 $_movie['taxonomy']['genres'][] = $genre;
             }
         }
     }
     return $_movie;
 }