-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
230 lines (189 loc) · 8.77 KB
/
script.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
document.addEventListener('DOMContentLoaded', function() {
const filmGallery = document.getElementById('film-gallery');
const serieGallery = document.getElementById('serie-gallery');
const videoPlayerContainer = document.getElementById('video-player-container');
const videoPlayer = document.getElementById('video-player');
const closeBtn = document.getElementById('close-btn');
const serieDetails = document.getElementById('serie-details');
const serieTitle = document.getElementById('serie-title');
const seasonSelect = document.getElementById('season-select');
const episodeList = document.getElementById('episode-list');
const searchInput = document.getElementById('search');
const playPauseBtn = document.getElementById('play-pause-btn');
const expandBtn = document.getElementById('expand-button');
const pipBtn = document.getElementById('pip-button');
const speedBtn = document.getElementById('speed-btn');
const backBtn = document.getElementById('back-btn');
const forwardBtn = document.getElementById('forward-btn');
const downloadBtn = document.getElementById('download-btn');
let currentVideoUrl = ''; // Pour stocker l'URL de la vidéo en cours
let pipMode = false; // Indicateur pour le mode PIP
let playbackRate = 1; // Taux de lecture initial
function loadContent() {
loadMovies(movies, filmGallery);
loadSeries(series, serieGallery);
}
function loadMovies(content, gallery) {
gallery.innerHTML = ''; // Nettoyage
content.forEach(item => {
const movieContainer = document.createElement('div');
movieContainer.classList.add('movie-item');
const img = document.createElement('img');
img.src = item.thumbnail;
img.alt = item.title;
img.classList.add('movie-thumbnail');
img.addEventListener('click', () => {
playVideo(item.videoUrl, 'movie');
});
const movieInfo = document.createElement('div');
movieInfo.classList.add('movie-info');
const title = document.createElement('h3');
title.textContent = item.title;
const description = document.createElement('p');
description.textContent = item.description;
const rating = document.createElement('p');
rating.textContent = `Note : ${item.rating} / 100`;
const ageRating = document.createElement('p');
ageRating.textContent = `Âge : ${item.ageRating}`;
movieInfo.appendChild(title);
movieInfo.appendChild(description);
movieInfo.appendChild(rating);
movieInfo.appendChild(ageRating);
movieContainer.appendChild(img);
movieContainer.appendChild(movieInfo);
gallery.appendChild(movieContainer);
});
}
function loadSeries(content, gallery) {
gallery.innerHTML = ''; // Nettoyage
content.forEach(item => {
const serieContainer = document.createElement('div');
serieContainer.classList.add('serie-item');
const img = document.createElement('img');
img.src = item.thumbnail;
img.alt = item.title;
img.classList.add('serie-thumbnail');
img.addEventListener('click', () => {
showSerieDetails(item);
});
const serieInfo = document.createElement('div');
serieInfo.classList.add('serie-info');
const title = document.createElement('h3');
title.textContent = item.title;
const description = document.createElement('p');
description.textContent = item.description;
const rating = document.createElement('p');
rating.textContent = `Note : ${item.rating} / 100`;
const ageRating = document.createElement('p');
ageRating.textContent = `Âge : ${item.ageRating}`;
serieInfo.appendChild(title);
serieInfo.appendChild(description);
serieInfo.appendChild(rating);
serieInfo.appendChild(ageRating);
serieContainer.appendChild(img);
serieContainer.appendChild(serieInfo);
gallery.appendChild(serieContainer);
});
}
function showSerieDetails(serie) {
serieTitle.textContent = serie.title;
seasonSelect.innerHTML = ''; // Nettoyage du sélecteur de saison
episodeList.innerHTML = ''; // Nettoyage de la liste d'épisodes
serie.seasons.forEach(season => {
const option = document.createElement('option');
option.value = season.seasonNumber;
option.textContent = `Saison ${season.seasonNumber}`;
seasonSelect.appendChild(option);
});
displayEpisodes(serie.seasons[0].episodes);
seasonSelect.addEventListener('change', function() {
const selectedSeason = serie.seasons.find(season => season.seasonNumber == this.value);
displayEpisodes(selectedSeason.episodes);
});
videoPlayerContainer.classList.add('active');
serieDetails.classList.remove('hidden');
}
function displayEpisodes(episodes) {
episodeList.innerHTML = ''; // Nettoyage
episodes.forEach(episode => {
const li = document.createElement('li');
li.textContent = episode.title;
li.addEventListener('click', () => {
playVideo(episode.videoUrl, 'serie');
});
episodeList.appendChild(li);
});
}
function playVideo(url, type) {
currentVideoUrl = url;
videoPlayer.src = url;
videoPlayer.play();
videoPlayerContainer.classList.add('active');
// Masquer ou afficher les détails des séries selon le type
if (type === 'movie') {
serieDetails.classList.add('hidden');
} else {
serieDetails.classList.remove('hidden');
}
}
closeBtn.addEventListener('click', () => {
videoPlayer.pause();
videoPlayerContainer.classList.remove('active');
serieDetails.classList.add('hidden');
});
playPauseBtn.addEventListener('click', () => {
if (videoPlayer.paused) {
videoPlayer.play();
playPauseBtn.innerHTML = '<i class="fas fa-pause"></i>';
} else {
videoPlayer.pause();
playPauseBtn.innerHTML = '<i class="fas fa-play"></i>';
}
});
expandBtn.addEventListener('click', () => {
if (!document.fullscreenElement) {
videoPlayer.requestFullscreen().catch(err => {
alert(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
});
}
});
pipBtn.addEventListener('click', () => {
if (videoPlayer.requestPictureInPicture) {
videoPlayer.requestPictureInPicture().catch(err => console.log(err));
} else {
pipMode = !pipMode;
videoPlayer.style.position = pipMode ? 'absolute' : 'relative';
videoPlayer.style.width = pipMode ? '300px' : '100%';
videoPlayer.style.height = pipMode ? '200px' : 'auto';
}
});
speedBtn.addEventListener('click', () => {
playbackRate = playbackRate === 1 ? 1.5 : 1; // Alterner entre 1x et 1.5x
videoPlayer.playbackRate = playbackRate;
speedBtn.innerHTML = playbackRate === 1 ? '<i class="fas fa-tachometer-alt"></i>' : '<i class="fas fa-tachometer-alt" style="color: #ff0;"></i>';
});
backBtn.addEventListener('click', () => {
videoPlayer.currentTime -= 10; // Reculer de 10 secondes
});
forwardBtn.addEventListener('click', () => {
videoPlayer.currentTime += 10; // Avancer de 10 secondes
});
downloadBtn.addEventListener('click', () => {
if (currentVideoUrl) {
const link = document.createElement('a');
link.href = currentVideoUrl;
link.download = 'video.mp4';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
});
searchInput.addEventListener('input', function() {
const query = searchInput.value.toLowerCase();
const filteredMovies = movies.filter(movie => movie.title.toLowerCase().includes(query));
const filteredSeries = series.filter(serie => serie.title.toLowerCase().includes(query));
loadMovies(filteredMovies, filmGallery);
loadSeries(filteredSeries, serieGallery);
});
loadContent();
});