forked from shafat-96/animeworld
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.html
More file actions
431 lines (389 loc) · 16.3 KB
/
demo.html
File metadata and controls
431 lines (389 loc) · 16.3 KB
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AnimeWorld India API Demo</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
h1, h2, h3 {
color: #333;
}
.search-container {
margin-bottom: 20px;
}
input[type="text"] {
padding: 8px;
width: 300px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
padding: 8px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.results-container {
display: flex;
flex-wrap: wrap;
gap: 15px;
}
.anime-card {
width: 200px;
border: 1px solid #ddd;
border-radius: 5px;
overflow: hidden;
transition: transform 0.3s;
}
.anime-card:hover {
transform: translateY(-5px);
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.anime-card img {
width: 100%;
height: 280px;
object-fit: cover;
}
.anime-info {
padding: 10px;
}
.anime-title {
font-weight: bold;
margin-bottom: 5px;
}
.anime-rating {
color: #f39c12;
}
.series-container, .player-container {
display: none;
margin-top: 20px;
}
.episodes-list {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.season-selector {
margin-bottom: 20px;
}
.season-button {
padding: 8px 15px;
margin-right: 5px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.active-season {
background-color: #f39c12;
}
.episode-item {
width: 150px;
border: 1px solid #ddd;
border-radius: 5px;
overflow: hidden;
cursor: pointer;
}
.episode-item img {
width: 100%;
height: 85px;
object-fit: cover;
}
.episode-info {
padding: 5px;
font-size: 14px;
}
.player-frame {
width: 100%;
height: 500px;
border: none;
}
.server-button {
margin: 5px;
padding: 8px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.active-server {
background-color: #f39c12;
}
.back-button {
background-color: #2196F3;
margin-bottom: 10px;
}
.loading {
text-align: center;
padding: 20px;
display: none;
}
</style>
</head>
<body>
<div class="container">
<h1>AnimeWorld India API Demo</h1>
<div class="search-container">
<input type="text" id="search-input" placeholder="Search for anime...">
<button id="search-button">Search</button>
</div>
<div class="loading" id="loading">
<h3>Loading...</h3>
</div>
<div id="search-results">
<h2>Search Results</h2>
<div class="results-container" id="results-container"></div>
</div>
<div class="series-container" id="series-container">
<button class="back-button" id="back-to-search">Back to Search</button>
<div id="series-details"></div>
<h3>Episodes</h3>
<div class="episodes-list" id="episodes-list"></div>
</div>
<div class="player-container" id="player-container">
<button class="back-button" id="back-to-series">Back to Series</button>
<h2 id="episode-title">Episode</h2>
<div id="player-frame-container"></div>
</div>
</div>
<script src="api-client.js"></script>
<script>
// Initialize API client
const api = new AnimeWorldAPI();
// DOM elements
const searchInput = document.getElementById('search-input');
const searchButton = document.getElementById('search-button');
const resultsContainer = document.getElementById('results-container');
const searchResults = document.getElementById('search-results');
const seriesContainer = document.getElementById('series-container');
const seriesDetails = document.getElementById('series-details');
const episodesList = document.getElementById('episodes-list');
const playerContainer = document.getElementById('player-container');
const episodeTitle = document.getElementById('episode-title');
const playerFrameContainer = document.getElementById('player-frame-container');
const backToSearch = document.getElementById('back-to-search');
const backToSeries = document.getElementById('back-to-series');
const loading = document.getElementById('loading');
let currentSeries = null;
// Search for anime
searchButton.addEventListener('click', async () => {
const query = searchInput.value.trim();
if (!query) return;
try {
showLoading();
const results = await api.search(query);
displaySearchResults(results);
} catch (error) {
console.error('Search error:', error);
alert('Error searching for anime. Please try again.');
} finally {
hideLoading();
}
});
// Allow search on Enter key
searchInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
searchButton.click();
}
});
// Display search results
function displaySearchResults(results) {
resultsContainer.innerHTML = '';
if (results.length === 0) {
resultsContainer.innerHTML = '<p>No results found.</p>';
return;
}
results.forEach(anime => {
const card = document.createElement('div');
card.className = 'anime-card';
card.innerHTML = `
<img src="${anime.poster}" alt="${anime.title}" onerror="this.src='https://via.placeholder.com/200x280?text=No+Image'">
<div class="anime-info">
<div class="anime-title">${anime.title}</div>
<div class="anime-rating">Rating: ${anime.rating || 'N/A'}</div>
</div>
`;
card.addEventListener('click', () => loadSeries(anime.id));
resultsContainer.appendChild(card);
});
showSection(searchResults);
}
// Load series details and episodes
async function loadSeries(id) {
try {
showLoading();
const seriesData = await api.getSeries(id);
currentSeries = seriesData;
// Display series details
seriesDetails.innerHTML = `
<div style="display: flex; margin-bottom: 20px;">
<img src="${seriesData.poster}" alt="${seriesData.title}" style="width: 200px; height: 280px; object-fit: cover; margin-right: 20px;">
<div>
<h2>${seriesData.title}</h2>
<p><strong>Rating:</strong> ${seriesData.rating || 'N/A'}</p>
<p>${seriesData.description || 'No description available.'}</p>
<div>
${Object.entries(seriesData.metadata || {}).map(([key, value]) => `<p><strong>${key.charAt(0).toUpperCase() + key.slice(1)}:</strong> ${value}</p>`).join('')}
</div>
</div>
</div>
`;
// Create season selector if multiple seasons exist
let seasonSelectorHtml = '';
if (seriesData.seasons && seriesData.seasons.length > 1) {
seasonSelectorHtml = `
<div class="season-selector">
<h3>Seasons</h3>
<div>
${seriesData.seasons.map((season, index) => `
<button class="season-button ${index === 0 ? 'active-season' : ''}" data-season="${season.number}">
${season.name}
</button>
`).join('')}
</div>
</div>
`;
}
// Insert season selector before episodes list
const seasonSelectorContainer = document.createElement('div');
seasonSelectorContainer.innerHTML = seasonSelectorHtml;
episodesList.parentNode.insertBefore(seasonSelectorContainer, episodesList);
// Function to display episodes for a specific season
function displayEpisodesForSeason(seasonNumber) {
// Find the season
const season = seriesData.seasons.find(s => s.number === seasonNumber) || seriesData.seasons[0];
const episodesToDisplay = season.episodes || seriesData.episodes;
// Update season buttons
document.querySelectorAll('.season-button').forEach(button => {
if (parseInt(button.dataset.season) === seasonNumber) {
button.classList.add('active-season');
} else {
button.classList.remove('active-season');
}
});
// Display episodes
episodesList.innerHTML = '';
episodesToDisplay.forEach(episode => {
const episodeItem = document.createElement('div');
episodeItem.className = 'episode-item';
episodeItem.innerHTML = `
<img src="${episode.image}" alt="Episode ${episode.number}" onerror="this.src='https://via.placeholder.com/150x85?text=No+Image'">
<div class="episode-info">
<div>${episode.number}</div>
<div>${episode.title || `Episode ${episode.number}`}</div>
</div>
`;
episodeItem.addEventListener('click', () => loadPlayer(episode.id, episode.number, episode.title));
episodesList.appendChild(episodeItem);
});
}
// Display episodes for the first season by default
const defaultSeason = seriesData.seasons && seriesData.seasons.length > 0 ? seriesData.seasons[0].number : 1;
displayEpisodesForSeason(defaultSeason);
// Add event listeners to season buttons
document.querySelectorAll('.season-button').forEach(button => {
button.addEventListener('click', () => {
const seasonNumber = parseInt(button.dataset.season);
displayEpisodesForSeason(seasonNumber);
});
});
showSection(seriesContainer);
} catch (error) {
console.error('Error loading series:', error);
alert('Error loading series details. Please try again.');
} finally {
hideLoading();
}
}
// Load player for an episode
async function loadPlayer(id, number, title) {
try {
showLoading();
const playerData = await api.getPlayer(id);
episodeTitle.textContent = `${currentSeries.title} - ${title || `Episode ${number}`}`;
// Store all sources for reference
const allSources = [
{ server: 0, src: playerData.iframe },
...(playerData.sources || [])
];
// Create the player frame with the active source
playerFrameContainer.innerHTML = `
<iframe id="player-iframe" class="player-frame" src="${playerData.iframe}" frameborder="0" scrolling="no" allow="autoplay; encrypted-media" allowfullscreen></iframe>
${playerData.servers && playerData.servers.length > 0 ? `
<div style="margin-top: 10px;" class="server-buttons">
<strong>Servers:</strong>
${playerData.servers.map((server, index) => `
<button class="server-button ${server.active ? 'active-server' : ''}" data-index="${index}">${server.name}</button>
`).join('')}
</div>
` : ''}
`;
// Add event listeners to server buttons
const serverButtons = document.querySelectorAll('.server-button');
serverButtons.forEach((button, index) => {
button.addEventListener('click', () => {
// Find the source for this server
const source = allSources.find(s => s.server === index + 1) || allSources[0];
// Update the iframe source
const iframe = document.getElementById('player-iframe');
if (iframe && source && source.src) {
iframe.src = source.src;
// Update active state
serverButtons.forEach(btn => btn.classList.remove('active-server'));
button.classList.add('active-server');
}
});
});
showSection(playerContainer);
} catch (error) {
console.error('Error loading player:', error);
alert('Error loading video player. Please try again.');
} finally {
hideLoading();
}
}
// Navigation buttons
backToSearch.addEventListener('click', () => {
showSection(searchResults);
});
backToSeries.addEventListener('click', () => {
showSection(seriesContainer);
});
// Helper functions
function showSection(section) {
searchResults.style.display = 'none';
seriesContainer.style.display = 'none';
playerContainer.style.display = 'none';
section.style.display = 'block';
}
function showLoading() {
loading.style.display = 'block';
}
function hideLoading() {
loading.style.display = 'none';
}
</script>
</body>
</html>