-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
46 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
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
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 |
---|---|---|
@@ -1,52 +1,44 @@ | ||
const api_key = "5e750355564957a2353604d8a9344e94"; | ||
const img_path = "https://image.tmdb.org/t/p/w1280"; | ||
|
||
const ID = JSON.parse(localStorage.getItem("cast-id")); | ||
|
||
const castHeader = document.getElementById("castHeader"); | ||
const profileImg = document.getElementById("profileImg"); | ||
const castName = document.querySelector(".cast-name"); | ||
const castInfo = document.querySelector(".cast-info"); | ||
|
||
async function fetchData(url) { | ||
const response = await fetch(url); | ||
const data = await response.json(); | ||
return data; | ||
} | ||
|
||
async function getPersonCombinedCredits(id) { | ||
const url = `https://api.themoviedb.org/3/person/${id}/combined_credits?api_key=${api_key}`; | ||
const data = await fetchData(url); | ||
console.log("Combined credits", data); | ||
} | ||
|
||
async function getPersonMovies(id) { | ||
const url = `https://api.themoviedb.org/3/person/${id}/movie_credits?api_key=${api_key}`; | ||
const data = await fetchData(url); | ||
console.log("Similar Movies:", data); | ||
} | ||
|
||
async function getPersonImages(id) { | ||
const url = `https://api.themoviedb.org/3/person/${id}/images?api_key=${api_key}`; | ||
const data = await fetchData(url); | ||
console.log("Person Images:", data); | ||
} | ||
|
||
async function getPersonDetails(details_id) { | ||
const url = `https://api.themoviedb.org/3/person/${details_id}?api_key=${api_key}`; | ||
const data = await fetchData(url); | ||
console.log("Person Details:", data); | ||
} | ||
|
||
async function getPersonMovieCredits(id) { | ||
const url = `https://api.themoviedb.org/3/person/${id}/movie_credits?api_key=${api_key}`; | ||
const data = await fetchData(url); | ||
console.log("Person Credits", data); | ||
return data; | ||
} | ||
|
||
async function main() { | ||
try { | ||
await getPersonImages(ID); | ||
await getPersonDetails(ID); | ||
await getPersonMovies(ID); | ||
await getPersonMovieCredits(ID); | ||
await getPersonCombinedCredits(ID); | ||
} catch (error) { | ||
console.error("An error occurred:", error); | ||
} | ||
getCastInfo(ID); | ||
async function getCastInfo(id) { | ||
const castDetailsURL = `https://api.themoviedb.org/3/person/${id}?api_key=${api_key}`; | ||
const castImgsURL = `https://api.themoviedb.org/3/person/${id}/images?api_key=${api_key}`; | ||
const castMovieURL = `https://api.themoviedb.org/3/person/${id}/movie_credits?api_key=${api_key}`; | ||
const castCreditsURL = `https://api.themoviedb.org/3/person/${id}/movie_credits?api_key=${api_key}`; | ||
const combCreditsURL = `https://api.themoviedb.org/3/person/${id}/combined_credits?api_key=${api_key}`; | ||
|
||
const castImgsDATA = await fetchData(castImgsURL); | ||
const castMovieDATA = await fetchData(castMovieURL); | ||
const castCreditsDATA = await fetchData(castCreditsURL); | ||
const combCreditsDATA = await fetchData(combCreditsURL); | ||
const castDetailsDATA = await fetchData(castDetailsURL); | ||
|
||
console.log(castImgsDATA); | ||
console.log(castMovieDATA); | ||
console.log(castCreditsDATA); | ||
console.log(combCreditsDATA); | ||
console.log(castDetailsDATA); | ||
|
||
// console.log(castDetailsDATA); | ||
|
||
castName.innerHTML = castDetailsDATA.name; | ||
birth.innerHTML = castDetailsDATA.place_of_birth; | ||
job.innerHTML = castDetailsDATA.known_for_department; | ||
profileImg.src = img_path + castImgsDATA.profiles[0].file_path; | ||
} | ||
|
||
main(); |