Skip to content

Commit

Permalink
[New] Added getMovieInfo Modules to search for the movies
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Oct 18, 2021
1 parent 9d42a98 commit f07ec30
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions modules/getMovieInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const fetch = require("node-fetch");
const { TMDb } = require("../config.json");

/**
* Searches for the Movie and returns its ID
* @param {String} searchParam
* @param {String} year
* @returns Movie ID
*/
module.exports.getMovieID = async (searchParam, year) => {
try {
const apiCall = await fetch(
`https://api.themoviedb.org/3/search/movie?api_key=${TMDb}&language=en-US&query=${searchParam}&page=1&include_adult=false&year=${year}`
);
const convertResponeToJson = await apiCall.json();
if (!convertResponeToJson.total_results)
throw new Error(`${"Nothing found with this name!"}`);

return convertResponeToJson.results[0].id;
} catch (err) {
throw err;
}
};

module.exports.getDetails = async (id) => {
try {
const apiCall = await fetch(
`https://api.themoviedb.org/3/movie/${id}?api_key=${TMDb}&language=en-US`
);
const convertRes = await apiCall.json();
return convertRes;
} catch (err) {
throw err;
}
};

0 comments on commit f07ec30

Please sign in to comment.