-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] Added getMovieInfo Modules to search for the movies
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |