-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsale.html
210 lines (184 loc) · 6.36 KB
/
sale.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
<!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>
<!-- Artplayer 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>
<!-- Artplayer Script -->
<script src="https://cdn.jsdelivr.net/npm/artplayer/dist/artplayer.js"></script>
<!-- HLS.js Script -->
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<!-- Chromecast Plugin Script -->
<script src="https://cdn.jsdelivr.net/npm/artplayer-plugin-chromecast/dist/artplayer-plugin-chromecast.js"></script>
<!-- VTT Thumbnail Plugin Script -->
<script src="https://cdn.jsdelivr.net/npm/artplayer-plugin-vtt-thumbnail/dist/artplayer-plugin-vtt-thumbnail.js"></script>
</head>
<body>
<!-- Container for the Artplayer -->
<div class="container">
<div class="artplayer-app"></div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const baseApiUrl = 'https://aniwatch-api-net.vercel.app/api/v2/hianime/episode/sources';
let category = 'dub';
let art = null;
const getQueryParam = (param) => {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
};
const id = getQueryParam('id');
if (!id) {
console.error('No ID provided in URL');
return;
}
const fetchVideoData = (category) => {
const apiUrl = `${baseApiUrl}?animeEpisodeId=${id}&server=hd-1&category=${category}`;
console.log(`Fetching video data from: ${apiUrl}`);
return fetch(apiUrl)
.then(response => {
if (!response.ok) throw new Error('Network response was not ok');
return response.json();
})
.then(data => {
if (data.status === 502) return null;
return {
sources: data.data.sources,
tracks: data.data.tracks,
};
})
.catch(error => console.error('Error fetching API data:', error));
};
const initializePlayer = async (data) => {
if (!data || !data.sources) {
console.error('Invalid data received from API:', data);
return;
}
const videoSource = data.sources[0].url;
if (art) art.destroy();
// Initialize the player
art = new Artplayer({
container: '.artplayer-app',
url: videoSource,
type: 'm3u8',
screenshot: true,
setting: true,
autoplay: true,
fullscreen: true,
fullscreenWeb: true,
airplay: true,
playsInline: true,
miniProgressBar: true,
pip: true,
plugins: [artplayerPluginChromecast({})],
settings: [], // We'll add quality settings dynamically
customType: {
m3u8: (video, url) => {
if (Hls.isSupported()) {
const hls = new Hls();
// Load the HLS stream
hls.loadSource(url);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
const availableLevels = hls.levels.map((level, index) => ({
html: `${level.height}p`, // Quality label
value: index, // Level index
default: hls.currentLevel === index,
}));
// Add quality settings dynamically
art.setting.add({
html: 'Quality',
selector: [
{ html: 'Auto', value: -1, default: hls.autoLevelEnabled },
...availableLevels,
],
onSelect: (item) => {
hls.currentLevel = item.value; // Change the quality
return item.html;
},
});
video.play(); // Start playback
});
hls.on(Hls.Events.LEVEL_SWITCHED, (event, data) => {
const quality = hls.levels[data.level].height;
art.notice.show(`Switched to ${quality}p`);
});
// Error handling
hls.on(Hls.Events.ERROR, (event, data) => {
console.error('HLS.js error:', data);
});
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url;
video.addEventListener('loadedmetadata', () => video.play());
} else {
art.notice.show('This browser does not support HLS playback');
}
},
},
moreVideoAttr: {
'webkit-playsinline': true,
'playsinline': true,
},
});
};
fetchVideoData(category).then(data => {
if (!data) {
const otherCategory = category === 'sub' ? 'dub' : 'sub';
fetchVideoData(otherCategory).then(data => {
if (!data) {
alert(`Error loading both ${category} and ${otherCategory}`);
} else {
initializePlayer(data);
}
});
} else {
initializePlayer(data);
}
});
});
</script>
</body>
</html>