Пример #1
0
 /**
  * Adds a complete TmdbInfo object with all its
  * children but removes it first.
  *
  * @param Dto_TmdbInfo $tmdb
  */
 function addInfo(Dto_TmdbInfo $tmdb)
 {
     $parameters = array(':tmdb_id' => array($tmdb->getTmdbId(), PDO::PARAM_INT), ':tmdb_collection_id' => array($tmdb->getTmdbCollectionId(), PDO::PARAM_INT), ':tmdb_collection_name' => array($tmdb->getTmdbCollectionName(), PDO::PARAM_STR), ':budget' => array($tmdb->getBudget(), PDO::PARAM_INT), ':homepage' => array($tmdb->getHomepage(), PDO::PARAM_STR), ':imdb_id' => array($tmdb->getImdbId(), PDO::PARAM_STR), ':tmdb_title' => array($tmdb->getTmdbTitle(), PDO::PARAM_STR), ':overview' => array($tmdb->getOverview(), PDO::PARAM_STR), ':popularity' => array($tmdb->getPopularity(), PDO::PARAM_INT), ':release_date' => array($tmdb->getReleaseDate(), PDO::PARAM_STR), ':revenue' => array($tmdb->getRevenue(), PDO::PARAM_INT), ':runtime' => array($tmdb->getRuntime(), PDO::PARAM_INT), ':tagline' => array($tmdb->getTagline(), PDO::PARAM_STR), ':vote_average' => array($tmdb->getVoteAverage(), PDO::PARAM_INT), ':vote_count' => array($tmdb->getVoteCount(), PDO::PARAM_INT), ':last_retrieve' => array(time(), PDO::PARAM_INT));
     $this->_conn->sqlInsert('tmdb_info', $parameters);
     foreach ($tmdb->getTrailerList() as $trailer) {
         $this->addTrailer($trailer);
     }
     // foreach
     foreach ($tmdb->getCastList() as $cast) {
         $this->addCast($cast);
     }
     // foreach
     foreach ($tmdb->getCrewList() as $crew) {
         $this->addCrew($crew);
     }
     // foreach
     foreach ($tmdb->getImageList() as $image) {
         $this->addImage($image);
     }
     // foreach
 }
 protected function queryTmdbApi()
 {
     $mediaInfo = new Dto_TmdbInfo();
     /*
      * Create URL to retriev info from, for this provider
      */
     $baseUrl = 'http://api.themoviedb.org/3/movie/' . (int) $this->getSearchid() . '?api_key=' . $this->_settings->get('tmdb_api_key') . '&append_to_response=trailers,credits,images,external_ids&language=en&include_image_language=en,null';
     list($http_code, $tmdb) = $this->_httpProvider->performCachedGet($baseUrl, false, 365 * 24 * 60 * 60);
     if (empty($tmdb)) {
         return null;
     }
     # if
     /*
      * Parse the results as JSON
      */
     $tmdb = json_decode($tmdb);
     $mediaInfo->setTmdbId($tmdb->id);
     /* Movie collections from TMDB */
     if (!empty($tmdb->belongs_to_collection)) {
         $mediaInfo->setTmdbCollectionId($tmdb->belongs_to_collection->id);
         $mediaInfo->setTmdbCollectionName($tmdb->belongs_to_collection->name);
     } else {
         $mediaInfo->setTmdbCollectionId(null);
         $mediaInfo->setTmdbCollectionName(null);
     }
     // else
     $mediaInfo->setBudget($tmdb->budget);
     $mediaInfo->setHomepage($tmdb->homepage);
     $mediaInfo->setImdbId($tmdb->imdb_id);
     if (!empty($mediaInfo->external_ids->imdb_id)) {
         $mediaInfo->setImdbId($tmdb->imdb_id);
     }
     // if
     if (!empty($mediaInfo->external_ids->tvrage_id)) {
         $mediaInfo->setTvRageId($tmdb->tvrage_id);
     }
     // if
     $mediaInfo->setTmdbTitle($tmdb->original_title);
     $mediaInfo->setOverview($tmdb->overview);
     $mediaInfo->setPopularity($tmdb->popularity);
     $mediaInfo->setReleaseDate($tmdb->release_date);
     $mediaInfo->setRevenue($tmdb->revenue);
     $mediaInfo->setRuntime($tmdb->runtime);
     $mediaInfo->setTagline($tmdb->tagline);
     $mediaInfo->setVoteAverage($tmdb->vote_average);
     $mediaInfo->setVoteCount($tmdb->vote_count);
     $mediaInfo->setLastretrieve(time());
     /*
      * Parse the list of trailers as individual trailers
      */
     foreach (array('quicktime', 'youtube') as $trailerType) {
         foreach ($tmdb->trailers->{$trailerType} as $trailers) {
             $trailerDto = new Dto_TmdbTrailer();
             $trailerDto->setName($trailers->name);
             $trailerDto->setTmdbId($mediaInfo->getTmdbId());
             $trailerDto->setType($trailerType);
             /*
              * Sometimes we do not get a sources array back, but a single
              * source
              */
             if (!isset($trailers->sources)) {
                 $trailerDto->setSize($trailers->size);
                 $trailerDto->setSource($trailers->source);
                 $mediaInfo->addTrailer($trailerDto);
             } else {
                 foreach ($trailers->sources as $source) {
                     // need to clone the object to prvent overwriting ourselves
                     $trailerDto = clone $trailerDto;
                     $trailerDto->setSize($source->size);
                     $trailerDto->setSource($source->source);
                     $mediaInfo->addTrailer($trailerDto);
                 }
                 // foreach
             }
         }
         // foreach
     }
     // foreach
     /*
      * And do the same for the movies' cast
      */
     foreach ($tmdb->credits->cast as $crew) {
         $castDto = new Dto_TmdbCast();
         $castDto->setTmdbCastId($crew->cast_id);
         $castDto->setTmdbId($mediaInfo->getTmdbId());
         $castDto->setTmdbCreditId($crew->id);
         $castDto->setName($crew->name);
         $castDto->setSortOrder($crew->order);
         $castDto->setCharacterName($crew->character);
         $castDto->setProfilePath($crew->profile_path);
         $mediaInfo->addCastMember($castDto);
     }
     // foreach
     /*
      * And do the same for the credits
      */
     foreach ($tmdb->credits->crew as $crew) {
         $crewDto = new Dto_TmdbCrew();
         $crewDto->setTmdbCreditId($crew->id);
         $crewDto->setTmdbId($mediaInfo->getTmdbId());
         $crewDto->setName($crew->name);
         $crewDto->setDepartment($crew->department);
         $crewDto->setJob($crew->job);
         $crewDto->setProfilePath($crew->profile_path);
         $mediaInfo->addCrewMember($crewDto);
     }
     // foreach
     /*
      * And eventually, the images. In the JSON object we get,
      * we get most images seperately, but some are contained in the
      * info object, so we fake add them.
      */
     $imageDto = new Dto_TmdbImage('backdrops', $tmdb->backdrop_path);
     $mediaInfo->addImage($imageDto);
     $imageDto = new Dto_TmdbImage('posters', $tmdb->poster_path);
     $mediaInfo->addImage($imageDto);
     /*
      * Parse the list of trailers as individual trailers
      */
     foreach (array('backdrops', 'posters') as $imageType) {
         foreach ($tmdb->images->{$imageType} as $image) {
             $imageDto = new Dto_TmdbImage();
             $imageDto->setTmdbCreditId(null);
             $imageDto->setTmdbId($mediaInfo->getTmdbId());
             $imageDto->setAspectRatio($image->aspect_ratio);
             $imageDto->setFilePath($image->file_path);
             $imageDto->setHeight($image->height);
             $imageDto->setWidth($image->width);
             $imageDto->setImageType($imageType);
             $mediaInfo->addImage($imageDto);
         }
         // foreach
     }
     // foreach
     return $mediaInfo;
 }