-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
248 lines (226 loc) · 9.04 KB
/
index.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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Let's Watch!</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #121212;
color: #ffffff;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
}
#search-input {
width: calc(100% - 120px);
padding: 10px;
margin-right: 10px;
border: none;
border-radius: 5px;
}
#search-button {
padding: 10px 20px;
border: none;
border-radius: 5px;
background-color: #ff9900;
color: white;
cursor: pointer;
}
.section-title {
font-size: 24px;
font-weight: bold;
margin-top: 20px;
display: none;
}
#movies-results, #series-results {
margin-top: 20px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.movie-item {
width: 200px;
padding: 10px;
border: 1px solid #333;
margin: 10px;
text-align: center;
background-color: #1e1e1e;
border-radius: 5px;
}
.movie-title {
font-size: 18px;
font-weight: bold;
margin-top: 10px;
}
.play-button {
background-color: #ff9900;
color: white;
border: none;
padding: 10px 0;
cursor: pointer;
margin-top: 10px;
width: 100%;
border-radius: 5px;
}
.movie-poster {
width: 100%;
height: 300px;
object-fit: cover;
border-radius: 5px;
}
.pagination {
text-align: center;
margin-top: 20px;
}
.pagination button, .pagination span {
background-color: transparent;
color: #ff9900;
border: none;
cursor: pointer;
padding: 5px 10px;
margin: 0 2px;
}
.pagination .active {
background-color: white;
color: #000;
border-radius: 5px;
padding: 5px 10px;
}
</style>
</head>
<body>
<h1>Search Movies & TV</h1>
<div style="text-align: center;">
<input type="text" id="search-input" placeholder="Enter movie or TV show title" />
<button id="search-button">Search</button>
</div>
<div class="section-title" id="movies-title">Movies</div>
<div id="movies-results"></div>
<div class="pagination" id="movies-pagination"></div>
<div class="section-title" id="series-title">TV Series</div>
<div id="series-results"></div>
<div class="pagination" id="series-pagination"></div>
<script>
const apiKey = '250ff9ec7e817d6a95d10b822de9e227'; // TMDB API key
const imageUrl = 'https://image.tmdb.org/t/p/w500'; // TMDB image base URL
let currentPageMovies = 1;
let currentPageSeries = 1;
let totalPagesMovies = 1;
let totalPagesSeries = 1;
let pageGroupSize = 10; // The number of pages per pagination group
// Function to search for movies and series
function searchMovies(query) {
const movieUrl = `/api/searchMovies?q=${encodeURIComponent(query)}&page=${currentPageMovies}`;
const seriesUrl = `/api/searchSeries?q=${encodeURIComponent(query)}&page=${currentPageSeries}`;
// Fetch movies
$.get(movieUrl, function(data) {
totalPagesMovies = data.total_pages;
if (data.results.length > 0) {
displayResults(data.results, 'movies');
$('#movies-title').show(); // Show the Movies section title
updatePagination('movies');
} else {
$('#movies-results').html('<p>No movies found</p>');
}
});
// Fetch series
$.get(seriesUrl, function(data) {
totalPagesSeries = data.total_pages;
if (data.results.length > 0) {
displayResults(data.results, 'series');
$('#series-title').show(); // Show the TV Series section title
updatePagination('series');
} else {
$('#series-results').html('<p>No series found</p>');
}
});
}
// Function to display the search results
function displayResults(results, category) {
const container = category === 'movies' ? '#movies-results' : '#series-results';
$(container).html(''); // Clear previous results
results.forEach(result => {
const id = result.id;
const title = category === 'movies' ? result.title : result.name;
const year = category === 'movies' ? result.release_date.split('-')[0] : result.first_air_date.split('-')[0];
const poster = result.poster_path ? `${imageUrl}${result.poster_path}` : 'https://via.placeholder.com/200x300?text=No+Image';
const resultHtml = `
<div class="movie-item">
<img src="${poster}" alt="${title} poster" class="movie-poster">
<div class="movie-title">${title} (${year})</div>
<button class="play-button" onclick="playItem('${id}', '${category}')">Play</button>
${category === 'series' ? `<button class="play-button" onclick="viewSeasons('${id}')">View Seasons</button>` : ''}
</div>
`;
$(container).append(resultHtml);
});
}
// Function to handle Play button click
function playItem(id, category) {
const playUrl = category === 'movies' ? `https://moviee.tv/embed/movie/${id}` : `https://moviee.tv/embed/tv/${id}`;
window.open(playUrl, '_blank');
}
// Redirect to seasons page for series
function viewSeasons(id) {
window.location.href = `seasons.html?id=${id}`;
}
// Function to update pagination
function updatePagination(category) {
const paginationContainer = category === 'movies' ? '#movies-pagination' : '#series-pagination';
const currentPage = category === 'movies' ? currentPageMovies : currentPageSeries;
const totalPages = category === 'movies' ? totalPagesMovies : totalPagesSeries;
let startPage = Math.floor((currentPage - 1) / pageGroupSize) * pageGroupSize + 1;
let endPage = Math.min(startPage + pageGroupSize - 1, totalPages);
let paginationHtml = `<button onclick="changePage('${category}', 1)"><<</button>`;
if (startPage > 1) {
paginationHtml += `<button onclick="changePage('${category}', ${startPage - 1})"><</button>`;
}
for (let i = startPage; i <= endPage; i++) {
paginationHtml += `<button class="${i === currentPage ? 'active' : ''}" onclick="changePage('${category}', ${i})">${i}</button>`;
}
if (endPage < totalPages) {
paginationHtml += `<button onclick="changePage('${category}', ${endPage + 1})">></button>`;
}
paginationHtml += `<button onclick="changePage('${category}', ${totalPages})">>></button>`;
$(paginationContainer).html(paginationHtml);
}
// Function to change pages
function changePage(category, page) {
if (category === 'movies') {
currentPageMovies = page;
} else {
currentPageSeries = page;
}
const query = $('#search-input').val();
if (query) {
searchMovies(query);
}
}
// Search button click handler
$('#search-button').on('click', function() {
const query = $('#search-input').val();
if (query) {
currentPageMovies = 1;
currentPageSeries = 1;
searchMovies(query);
}
});
// Enter key press handler
$('#search-input').on('keydown', function(event) {
if (event.key === 'Enter') {
const query = $('#search-input').val();
if (query) {
currentPageMovies = 1;
currentPageSeries = 1;
searchMovies(query);
}
}
});
</script>
</body>
</html>