-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwatch.html
205 lines (189 loc) · 7.09 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Watch</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
background: #000;
}
.container {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
background: #000;
overflow: hidden;
}
.artplayer-app {
width: 100%;
height: 100%;
background: #000;
box-sizing: border-box;
}
@media (max-width: 768px) {
.artplayer-app {
width: 100%;
height: 100%;
}
}
@media (max-width: 1024px) {
.artplayer-app {
width: 100%;
height: 100%;
}
}
</style>
<script src="https://cdn.jsdelivr.net/npm/hls.js"></script>
<script src="https://cdn.jsdelivr.net/npm/artplayer/dist/artplayer.js"></script>
<script src="https://cdn.jsdelivr.net/npm/artplayer-plugin-chromecast"></script>
<script src="https://cdn.jsdelivr.net/npm/eruda"></script>
<script>eruda.init();</script>
</head>
<body>
<div class="artplayer-app"></div>
<script>
// Utility: Get URL query parameter
function 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');
alert('No video ID found!');
throw new Error('Missing video ID in URL query');
}
// Proxy URL function
function applyProxy(url) {
const proxyURL = 'https://gogoanime-and-hianime-proxy-nn.vercel.app/hls-proxy?url=';
return proxyURL + encodeURIComponent(url);
}
// API Configuration
const apiURL = `https://api-consumet-org-gamma.vercel.app/meta/anilist/watch/${id}`; // Replace with your API endpoint
const headers = { 'Referer': 'https://s3embtaku.pro' };
let art;
let hls;
async function fetchVideoData() {
try {
const response = await fetch(apiURL, { headers });
if (!response.ok) throw new Error('Failed to fetch video data');
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching video data:', error);
return null;
}
}
function initializePlayer(videoData) {
const defaultSource = videoData.sources.find(source => source.quality === 'default');
const backupSource = videoData.sources.find(source => source.quality === 'backup');
const qualitySources = videoData.sources.filter(source =>
['360p', '480p', '720p', '1080p'].includes(source.quality)
);
if (!defaultSource || !backupSource) {
console.error('Default or backup source not found.');
return;
}
// Apply the proxy to all source URLs
const defaultURL = applyProxy(defaultSource.url);
const backupURL = applyProxy(backupSource.url);
const qualityURLs = qualitySources.map(source => ({
...source,
url: applyProxy(source.url)
}));
// Initialize ArtPlayer
art = new Artplayer({
container: '.artplayer-app',
url: defaultURL,
type: 'm3u8',
autoplay: true,
theme: '#00aaff',
setting: true,
volume: 0.5,
playbackRate: true,
fullscreen: true,
fullscreenWeb: true,
miniProgressBar: true,
screenshot: true,
plugins: [
artplayerPluginChromecast({})
],
settings: [
// Quality Selector
{
html: 'Quality',
selector: qualityURLs.map(source => ({
html: source.quality,
url: source.url
})),
onSelect: function (item) {
art.switchUrl(item.url);
return item.html;
}
},
// Server Selector
{
html: 'Server',
selector: [
{ html: 'Default', url: defaultURL },
{ html: 'Backup', url: backupURL }
],
onSelect: function (item) {
art.switchUrl(item.url);
return item.html;
}
},
// Speed Selector
{
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;
}
}
],
customType: {
m3u8: function (video, url) {
if (Hls.isSupported()) {
if (hls) hls.destroy(); // Destroy previous instance
hls = new Hls();
hls.loadSource(url);
hls.attachMedia(video);
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url;
} else {
art.notice.show('Your browser does not support HLS playback.');
}
}
}
});
// Resume Last Seen Position
const lastSeenKey = `last-seen-${id}`;
const lastSeen = localStorage.getItem(lastSeenKey);
if (lastSeen) {
art.currentTime = parseFloat(lastSeen);
art.notice.show(`Resumed at ${lastSeen} seconds.`);
}
art.on('video:timeupdate', () => {
localStorage.setItem(lastSeenKey, art.currentTime);
});
}
// Fetch video data and initialize player
fetchVideoData().then(videoData => {
if (videoData) initializePlayer(videoData);
else alert('Failed to load video data.');
});
</script>
</body>
</html>