-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie.html
73 lines (64 loc) · 2.31 KB
/
movie.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movie Details</title>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="movie-style.css">
</head>
<body>
<div id="moviePage" class="container">
<div class="movie-details">
<div class="movie-image">
<img id="movieImage" src="" alt="">
</div>
<div class="movie-info">
<h1 id="movieTitle"></h1>
<p id="movieOverview"></p>
<p id="voteAverage"></p>
<p id="voteCount"></p>
<button id="bookmarkButton">Bookmark</button>
</div>
</div>
</div>
<script>
// Function to fetch movie details from TMDB API
async function fetchMovieDetails(movieId) {
const apiKey = '8dd735e87f128347ce5e73da06811ded'; // Replace with your TMDB API key
const response = await fetch(`https://api.themoviedb.org/3/movie/${movieId}?api_key=${apiKey}`);
const data = await response.json();
return data;
}
// Function to display movie details on the page
function displayMovieDetails(movie) {
const movieImage = document.getElementById('movieImage');
const movieTitle = document.getElementById('movieTitle');
const movieOverview = document.getElementById('movieOverview');
const voteAverage = document.getElementById('voteAverage');
const voteCount = document.getElementById('voteCount');
movieImage.src = `https://image.tmdb.org/t/p/w500/${movie.poster_path}`;
movieImage.alt = movie.original_title;
movieTitle.textContent = movie.original_title;
movieOverview.textContent = movie.overview;
voteAverage.textContent = `Vote Average: ${movie.vote_average}`;
voteCount.textContent = `Vote Count: ${movie.vote_count}`;
}
// Function to extract movie ID from URL
function getMovieIdFromURL() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get("id");
}
// Get movie ID from URL
const movieId = getMovieIdFromURL();
// Fetch movie details and display them on the page
fetchMovieDetails(movieId)
.then((movie) => {
displayMovieDetails(movie);
})
.catch((error) => {
console.log(error);
});
</script>
</body>
</html>