diff --git a/index.js b/index.js index e26f241..de21615 100644 --- a/index.js +++ b/index.js @@ -108,8 +108,8 @@ function login() { } /* This will need to be stored somewhere else at some point for security reasons */ -const API_KEY = 'api_key=bb1d4e0661af455e02af1ea99fb85fcb'; const BASE_URL = 'https://api.themoviedb.org/3/'; +const API_KEY = 'api_key=bb1d4e0661af455e02af1ea99fb85fcb'; const SEARCH_QUERY = '&query=searchTerm'; /* This can be formatted to include whatever you want -- 'movie/upcoming' is just a placeholder for now */ //const API_URL_ = BASE_URL + '/movie/popular?/similar' + API_KEY + '&language=en-US&page=1'; @@ -777,10 +777,8 @@ function getTrendingMovies(url) { movie.id + '?' + API_KEY + - '&language=en-US&append_to_response=videos,credits,similar,images'; + '&language=en-US&append_to_response=videos,reviews,similar,credits,similar,images,watch/providers'; - const TRAILER_URL = - BASE_URL + 'movie/' + movie.id + 'videos?' + API_KEY; fetch(DETAIL_URL) .then(res => res.json()) .then(data => { @@ -788,6 +786,7 @@ function getTrendingMovies(url) { }); }); }) + .catch(error => { console.log(error); }); @@ -795,25 +794,63 @@ function getTrendingMovies(url) { /* Passed a movie, which will contain all of the needed information about the individual movie (runtime, videos, etc) */ function displayTrendingMovies(data) { - console.log("Movie -- ", data); - const { - title, + const { + title, poster_path, vote_average, overview, backdrop_path, release_date, runtime, + reviews, budget, revenue, genres, status, tagline, + videos, + credits, + similar, id } = data; - + const backdrop_url = POSTER_URL + backdrop_path; const specialChar = title + id; + const specialCharReviews = id + title; + const specialCharSimilar = id + title + '&'; + const specialCharCast = id + title + '/'; + const specialCharWatchProviders = id + title + '.'; + + let movieGenre = ''; + let formattedRevenue = ''; + let formattedBudget = ''; + + /* Formats the revenue and budget into USD */ + const formatter= new Intl.NumberFormat('en-US', { + style: 'currency', + currency: 'USD', + }) + + genres.forEach(genre => { + movieGenre += genre.name + ", "; + }) + + if (revenue == 0) { + formattedRevenue = "N/A"; + } else { + formattedRevenue = formatter.format(revenue); + } + + if (budget == 0) { + formattedBudget = "N/A"; + + } else { + formattedBudget = formatter.format(budget); + } + + genres.forEach(genre => { + movieGenre += genre.name + ", "; + }) const movieEl = `