-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
245 lines (214 loc) · 10.7 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
<!DOCTYPE html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/x-icon" href="./favicon.ico">
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<link rel="stylesheet" href="./style.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"
integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
<script src="./script.js"></script>
<script src="https://unpkg.com/video.js/dist/alt/video.core.js"></script>
<script src="https://unpkg.com/@videojs/http-streaming@1/dist/videojs-http-streaming.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-quality-levels/2.0.9/videojs-contrib-quality-levels.min.js"></script>
<title>Anime Stream</title>
</head>
<body>
<div id="main-container">
<!-- <div id="eptitle">
</div> -->
<div class="wrap">
<div class="search">
<input type="text" class="searchTerm" placeholder="Anime name...">
<button onclick="searchAnime()" id="playbutton" type="submit" class="searchButton">
<i class="fa fa-search"></i>
</button>
</div>
</div>
<div class="animebox">
<p id="maintitle">Anime Details</p>
<p id="details">No Search Query!</p>
</div>
<div id="mainplayer" class="mainplayer">
<h1 id="episodetitle">Sample Name</h1>
<video id="animestream" class="video-js vjs-default-skin vjs-16-9 vjs-big-play-centered " controls preload="auto">
<source src="" type="application/x-mpegURL">
</video>
<button id="setMinLevel">min quality</button>
<button id="setMaxLevel">max quality</button>
<script id="playerscript"></script>
</div>
<script async>
const maincontainer = document.getElementById('wrap')
const videotag = document.getElementById("video");
const button = document.getElementById("playvideo");
const main = document.getElementById("mainplayer");
const script = document.getElementById("playerscript");
const search = document.querySelector(".searchTerm");
const details = document.getElementById("details");
const animebox = document.querySelector(".animebox")
const episodename = document.getElementById("episodetitle");
let animeid;
let episodeid;
var player = videojs('animestream', {
controls: true,
fluid: true,
html5: {
vhs: {
overrideNative: true,
enableLowInitialPlaylist: true, // see https://github.com/videojs/http-streaming
bandwidth: 10285391,
limitRenditionByPlayerDimensions: false,
smoothQualityChange: false,
experimentalBufferBasedABR: true,
handlePartialData: true
},
nativeCaptions: false ,
nativeAudioTracks: false,
nativeVideoTracks: false
}
});
const apiurl = "https://api.consumet.org/anime/enime/"
main.style.display = "none"
maincontainer.style.display = "none"
async function searchAnime() {
words = search.value
url = apiurl + words
const res = await fetch(url);
const data = await res.json();
animedata = data.results[0]
showAnime(animedata)
main.style.display = "none"
animebox.style.display = ""
}
async function showAnime(data) {
animeid = data.id
title = data.title
date = data.releaseDate
genres = data.genres.join(", ")
details.innerHTML = `
<p>
<b>Title: </b>${title}</br>
<b>Date: </b>${date}</br>
<b>Title: </b>${genres}</br>
<b>Rating: </b>${data.rating}</br>
<b>Status: </b>${data.status}</br>
<b>Type: </b>${data.type}</br>
<h4 id="progtext">Give me an episode number!</h4>
<input id="episodeNumber" class="srchTerm"></input></br></br>
<button onclick="getAnimeInfo()" id="infobutton" type="submit" class="searchButton">Play</button>
`
}
async function getAnimeInfo() {
console.log('info func called')
console.log('hi im here')
document.getElementById('episodeNumber').style.display = "none"
document.getElementById('infobutton').style.display = "none"
episodenum = document.getElementById('episodeNumber').value
document.getElementById('progtext').innerHTML = `Please wait...</br><img id="loadinggif" src="./loading.gif" width="100" height="75">`
infourl = "https://api.consumet.org/anime/enime/info?id=" + animeid
const resp = await fetch(infourl);
const data = await resp.json();
let episode = data.episodes.find(ep => ep.number == Number(episodenum))
episodeid = episode.id
episodetitle = episode.title
episodename.innerText = `Episode: ${episode.number} - ${episodetitle} HD`
episodeurl = "https://api.consumet.org/anime/enime/watch?episodeId=" + episodeid
const epresp = await fetch(episodeurl);
const epdata = await epresp.json();
await playVideo(epdata.sources[epdata.sources.length - 2].url, data.cover)
document.body.style.background = `url("${data.cover}")`
main.style.display = ""
}
async function playVideo(url, poster) {
player.src({
src: url,
type: 'application/x-mpegURL'});
document.getElementById('animestream').setAttribute("poster", poster)
document.getElementById('progtext').innerHTML = `Playing episode <code>${episodenum}</code> now!`
videoattached = true
animebox.style.display = "none"
let qualityLevels = player.qualityLevels();
for (var i = 0; i < qualityLevels.length; i++) {
var quality = qualityLevels[i];
if (quality.width >= 1080) {
console.log('playing 1080p')
quality.enabled = true;
} else {
quality.enabled = false;
}
}
// document.getElementById("setMinLevel").addEventListener('click', () => {
// console.log("Set Min quality level")
// enableQualityLevel(0);
// })
// document.getElementById("setMaxLevel").addEventListener('click', () => {
// console.log("Set Max quality level")
// enableQualityLevel(qualityLevels.length-1);
// })
// let enableQualityLevel = level => {
// for (var i = 0; i < qualityLevels.length; i++) {
// let qualityLevel = qualityLevels[i];
// qualityLevel.enabled = i === level ? true : false;
// }
// qualityLevels.selectedIndex_ = level;
// qualityLevels.trigger({ type: 'change', selectedIndex: level });
// }
// console.log("Set Max quality level")
// enableQualityLevel(qualityLevels.length-1);
qualityLevels.on('change', function () {
console.log('Quality Level changed!');
console.log('New level:', qualityLevels[qualityLevels.selectedIndex]);
});
// // set min quality level
// document.getElementById("setMinLevel").addEventListener('click', () => {
// console.log("Set Min quality level")
// enableQualityLevel(0);
// console.log("qualityLevels.selectedIndex: ", qualityLevels.selectedIndex);
// showEnabledLevels();
// })
// set max quality level
// document.getElementById("setMaxLevel").addEventListener('click', () => {
// console.log("Set Max quality level")
// enableQualityLevel(qualityLevels.length-1);
// console.log("qualityLevels.selectedIndex: ", qualityLevels.selectedIndex);
// showEnabledLevels();
// })
// player.on('timeupdate', function (){
// console.log("Playing now: ", player.videoHeight());
// })
// player.on('loadedmetadata', function () {
// // enable buttons
// document.getElementById("setMinLevel").disabled = false;
// document.getElementById("setMaxLevel").disabled = false;
// // track currently rendered segments change
// let tracks = player.textTracks();
// let segmentMetadataTrack;
// for (let i = 0; i < tracks.length; i++) {
// if (tracks[i].label === 'segment-metadata') {
// segmentMetadataTrack = tracks[i];
// }
// }
// let previousPlaylist;
// if (segmentMetadataTrack) {
// segmentMetadataTrack.on('cuechange', function () {
// let activeCue = segmentMetadataTrack.activeCues[0];
// if (activeCue) {
// if (previousPlaylist !== activeCue.value.playlist) {
// console.log('Switched from rendition ' + previousPlaylist +
// ' to rendition ' + activeCue.value.playlist, activeCue.value.resolution.height);
// }
// previousPlaylist = activeCue.value.playlist;
// }
// });
// }
// });
}
</script>
<!-- <script src="./script.js"></script> -->
</div>
<div class="questionbox"></div>>
</body>
</html>