-
Notifications
You must be signed in to change notification settings - Fork 1
/
watch.html
261 lines (210 loc) · 6.73 KB
/
watch.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AniTeams - Watch</title>
<link rel="stylesheet" href="styles.css">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
.container {
width: 100vw;
height: 100vh;
display: flex;
justify-content: center; /* Center horizontally */
align-items: center; /* Center vertically */
background: #000; /* Background color if needed */
}
.artplayer-app {
width: 100%;
height: 100%;
max-width: 1240px; /* Maximum width of the player */
max-height: 605px; /* Maximum height of the player */
background: #000; /* Background color */
box-sizing: border-box; /* Include padding and border in element's total width and height */
}
/* Media queries for different screen sizes */
@media (max-width: 768px) {
.container {
padding: 10px; /* Optional padding for smaller screens */
}
.artplayer-app {
max-width: 100%;
max-height: 100%;
}
}
@media (max-width: 1024px) {
.container {
padding: 10px; /* Optional padding for medium screens */
}
.artplayer-app {
max-width: 100%;
max-height: 100%;
}
}
</style>
</head>
<body>
<div class="artplayer-app"></div>
<script src="https://cdn.jsdelivr.net/npm/artplayer/dist/artplayer.js"></script>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/artplayer-plugin-chromecast/dist/artplayer-plugin-chromecast.js"></script>
<script src="scripts.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const baseApiUrl = 'https://aniwatch-api-net.vercel.app/anime/episode-srcs'; // Base URL for the API
let category = 'sub'; // Default category
let art = null; // Variable to store the Artplayer instance
// Function to extract query parameters from the URL
const getQueryParam = (param) => {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
};
// Get the ID from the URL
const id = getQueryParam('id');
if (!id) {
console.error('No ID provided in URL');
return;
}
// Fetch video data from the API based on the selected category and ID
const fetchVideoData = (category) => {
const apiUrl = `${baseApiUrl}?id=${id}&server=vidstreaming&category=${category}`;
console.log(`Fetching video data from: ${apiUrl}`); // Debug log
return fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.catch(error => {
console.error('Error fetching API data:', error);
});
};
// Initialize or reinitialize the player with the new data
const initializePlayer = (data) => {
if (!data || !data.sources) {
console.error('Invalid data received from API:', data); // Debug log
return;
}
const videoSource = data.sources[0].url;
const subtitleTracks = data.tracks.filter(track => track.kind === 'captions');
// Destroy the existing player if it exists
if (art) {
art.destroy();
}
art = new Artplayer({
container: '.artplayer-app',
url: videoSource,
type: 'm3u8',
screenshot: true,
setting: true,
autoplay: true,
fullscreen: true,
fullscreenWeb: true,
airplay: true,
playsInline: true,
plugins: [
artplayerPluginChromecast({}),
],
settings: [
{
html: 'Speed',
selector: [
{ html: '1.0x', playbackRate: 1.0, default: true },
{ html: '1.5x', playbackRate: 1.5 },
{ html: '2.0x', playbackRate: 2.0 },
],
onSelect: function (item) {
art.playbackRate = item.playbackRate;
return item.html;
},
},
{
html: 'Subtitles',
selector: subtitleTracks.map(track => ({
html: track.label,
url: track.file,
default: track.default || false,
})),
onSelect: function (item) {
art.subtitle.switch(item.url, item.html);
return item.html;
},
},
{
html: 'Audio',
selector: [
{ html: 'Sub', category: 'sub', default: category === 'sub' },
{ html: 'Dub', category: 'dub', default: category === 'dub' },
],
onSelect: function (item) {
category = item.category;
fetchVideoData(category).then(data => {
initializePlayer(data);
});
return item.html;
},
},
],
customType: {
m3u8: function (video, url) {
if (Hls.isSupported()) {
const hls = new Hls();
hls.loadSource(url);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
video.play();
});
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url;
video.addEventListener('loadedmetadata', () => {
video.play();
});
} else {
art.notice.show('Does not support playback of m3u8');
}
}
},
moreVideoAttr: {
'webkit-playsinline': true,
'playsinline': true,
},
});
// Create and style the back button
const backButton = document.createElement('div');
backButton.innerHTML = '<'; // HTML entity for "<"
backButton.style.position = 'absolute';
backButton.style.top = '10px';
backButton.style.left = '10px';
backButton.style.fontSize = '24px';
backButton.style.color = 'white';
backButton.style.cursor = 'pointer';
backButton.style.zIndex = '9999';
// Add click event to the back button
backButton.addEventListener('click', () => {
window.history.back();
});
// Append the back button to the player container
const playerContainer = document.querySelector('.artplayer-app');
playerContainer.appendChild(backButton);
// Hide controls when not hovering over player
playerContainer.addEventListener('mousemove', () => {
playerContainer.querySelector('.artplayer-controls').style.opacity = '1';
playerContainer.querySelector('.artplayer-controls').style.visibility = 'visible';
});
playerContainer.addEventListener('mouseleave', () => {
playerContainer.querySelector('.artplayer-controls').style.opacity = '0';
playerContainer.querySelector('.artplayer-controls').style.visibility = 'hidden';
});
};
// Fetch the initial video data and initialize the player
fetchVideoData(category).then(initializePlayer);
});
</script>
</body>
</html>