/**
  * 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;
 }