-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubject-details.html
358 lines (329 loc) · 13.7 KB
/
subject-details.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
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
><!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="/theme/simple/static/favicon.ico" rel="icon">
<title>番剧详情页面</title>
<link href="/theme/simple/static/lib/bootstrap-5.0.2/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<style>
.list-group-item {
background-color: #f8f9fa; /* 默认按钮背景色 */
overflow: hidden;
}
.list-group-item:hover {
background-color: #f0f0f0; /* 鼠标移动到剧集时的背景颜色 */
cursor: pointer; /* 鼠标样式为手型 */
}
.list-group-item.active {
background-color: #ff6600; /* 选中的剧集颜色为橘黄色 */
border-color: #ff6600; /* 边框颜色为橘黄色 */
color: #ffffff; /* 字体颜色为白色 */
}
.toggle-layout {
background-color: #f8f9fa; /* 按钮背景色 */
border: 1px solid #dee2e6; /* 按钮边框颜色 */
color: #343a40; /* 按钮文字颜色 */
}
.toggle-layout.active {
background-color: #ff6600; /* 选中按钮的背景色 */
border-color: #ff6600; /* 选中按钮的边框颜色 */
color: #ffffff; /* 选中按钮的文字颜色 */
}
.cover-image {
width: 100%;
max-width: 100%;
height: auto;
border-radius: 5px;
}
.anime-description {
display: -webkit-box;
-webkit-line-clamp: 10; /* 最小高度为10行 */
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
.artplayer-app {
width: 100%;
height: 100%
}
.scale {
width: 100%;
padding-bottom: 56.25%;
height: 0;
position: relative;
}
.item {
width: 100%;
height: 100%;
position: absolute;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<!-- 左侧内容,占据全宽度,当屏幕大于等于 md 尺寸时显示 -->
<div class="col-xl-8 col-lg-8 col-md-8 col-sm-12">
<!-- 播放器 -->
<div class="scale">
<div class="item">
<!-- 放在固定 16:9 的父容器里 -->
<div class="artplayer-app" ></div>
</div>
</div>
<!-- 切换选择剧集和布局 -->
<div class="mt-4 d-flex justify-content-between align-items-center">
<h4 class="mb-0 mr-3">选择剧集</h4>
<div class="btn-group" role="group" aria-label="Layout Toggle">
<button type="button" class="btn btn-secondary toggle-layout" data-layout="horizontal">横向</button>
<button type="button" class="btn btn-secondary toggle-layout" data-layout="vertical">纵向</button>
</div>
</div>
<div class="mt-4">
<ul id="episodeList" class="list-group">
<li class="list-group-item "th:classappend="${episode.sequence == 1 && episode.group == 'MAIN'} ? 'active' : '' " th:each="episode: ${subject.episodes}">
<span th:text="${episode.group}"></span>
-
<span th:text="${episode.sequence}"></span>
-
<span th:text="${episode.name}"></span>
</li>
<!-- 添加更多剧集 -->
</ul>
</div>
</div>
<!-- 右侧内容,占据1/3的宽度 -->
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 ">
<!-- 番剧详情 -->
<h2 style="margin: 1vh 0" th:text="${subject.name}">番剧标题</h2>
<p th:text="${subject.nameCn}"></p>
<p class="anime-description" th:text="${subject.summary}">番剧介绍... </p>
<!-- 封面图 -->
<img th:src="${subject.cover}" width="100%" alt="番剧封面" class="cover-image">
</div>
</div>
</div>
<script src="/theme/simple/static/lib/bootstrap-5.0.2/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="/theme/simple/static/lib/artplayer-5.0.9/artplayer.js" crossorigin="anonymous"></script>
<script src="/theme/simple/static/lib/JavascriptSubtitlesOctopus/subtitles-octopus.js" crossorigin="anonymous"></script>
<script src="/theme/simple/static/lib/JavascriptSubtitlesOctopus/subtitles-octopus-worker.js" crossorigin="anonymous"></script>
<script th:inline="javascript">
const subtitlesOctopusWorkJsPath = window.location.origin + '/theme/simple/static/lib/JavascriptSubtitlesOctopus/subtitles-octopus-worker.js';
var subject = [[${subject}]];
var videoSubtitleList = [[${videoSubtitleList}]];
var fonts = [[${fonts}]];
console.debug('window.location.origin', window.location.origin)
fonts = fonts.map(url => window.location.origin + url)
console.debug('subject', subject);
console.debug('videoSubtitleList', videoSubtitleList);
console.debug('fonts', fonts);
var subtitleOctopus;
const artplayerPluginAss = (options) => {
return (art) => {
subtitleOctopus = new SubtitlesOctopus({
...options,
video: art.template.$video,
});
subtitleOctopus.canvasParent.style.zIndex = 20;
art.on('destroy', () => subtitleOctopus.dispose());
return {
key: 'artplayerPluginAss',
name: 'artplayerPluginAss',
instance: subtitleOctopus,
};
};
};
const art = new Artplayer({
container: '.artplayer-app',
volume: 0.5,
isLive: false,
muted: false,
autoplay: false,
pip: true,
autoSize: true,
autoMini: true,
screenshot: true,
setting: true,
loop: true,
flip: true,
playbackRate: true,
aspectRatio: true,
fullscreen: true,
fullscreenWeb: true,
subtitleOffset: false,
miniProgressBar: true,
mutex: true,
backdrop: true,
playsInline: true,
autoPlayback: true,
airplay: true,
theme: 'skyblue',
lang: navigator.language.toLowerCase(),
moreVideoAttr: {
crossOrigin: 'anonymous',
},
plugins: [],
settings: [],
});
var currentSubUrl = '';
if (videoSubtitleList.length > 0) {
currentSubUrl = videoSubtitleList[0].url;
art.plugins.add(artplayerPluginAss({
// debug: true,
fonts: fonts,
fallbackFont: '',
subUrl: currentSubUrl,
workerUrl: subtitlesOctopusWorkJsPath
}));
}
const artplayerSubtitleEnableSetting = {
key: 'artplayerSubtitleEnableSetting',
html: '开启',
tooltip: '显示',
switch: true,
onSwitch: function (item) {
item.tooltip = item.switch ? '隐藏' : '显示';
if (item.switch) {
subtitleOctopus.freeTrack();
} else {
subtitleOctopus.setTrackByUrl(currentSubUrl);
}
return !item.switch;
},
};
const artplayerSubtitleSetting = {
key: 'artplayerSubtitleSetting',
width: 200,
html: '字幕',
tooltip: '选择',
icon: '<img width="22" heigth="22" src="/theme/simple/static/images/svg/subtitle.svg">',
selector: [artplayerSubtitleEnableSetting],
onSelect: function (item) {
const newSubtitleUrl = item.url;
currentSubUrl = newSubtitleUrl;
subtitleOctopus.setTrackByUrl(newSubtitleUrl);
artplayerSubtitleEnableSetting.switch = true;
return item.html;
},
};
function getSubtitleSimpleNameByAttachmentName(name){
if (!name) return '';
var str = name.substring(0, name.lastIndexOf('.'));
str = str.substring(str.lastIndexOf('.') + 1);
str = str.toLocaleUpperCase();
// console.log('subtitle simple name', name, str);
return str;
};
function switchVideoUrl(resource) {
console.debug('switchVideoUrl', 'resource', resource)
if(!resource) return;
art.switch = resource.url;
var attachmentId = resource.attachmentId;
if(videoSubtitleList && videoSubtitleList.length >0) {
var subtitles = videoSubtitleList.filter(e => attachmentId === e.master_attachment_id);
console.debug('attachmentId subtitles', attachmentId, subtitles)
if(subtitles && subtitles.length > 0) {
if(subtitleOctopus) {
subtitleOctopus.freeTrack();
}
console.debug('art.setting', art.setting)
artplayerSubtitleSetting.selector = []
artplayerSubtitleSetting.selector.push(artplayerSubtitleEnableSetting)
subtitles.forEach(e => {
var simpleName = getSubtitleSimpleNameByAttachmentName(e.name);
artplayerSubtitleSetting.selector.push({
default: simpleName === 'SC' || simpleName === 'sc',
url: e.url,
html: simpleName
})
})
art.setting.update(artplayerSubtitleSetting)
} else {
if(subtitleOctopus) {
subtitleOctopus.freeTrack();
}
}
}
}
function getEpisodeSeqStr(num) {
let epSeqStr = num + '';
epSeqStr = epSeqStr.indexOf('.') > 0 ? epSeqStr : epSeqStr + ".0"
return epSeqStr
}
document.addEventListener('DOMContentLoaded', function() {
var episodeList = document.getElementById('episodeList');
var listItems = episodeList.getElementsByTagName('li');
var layoutToggleButtons = document.querySelectorAll('.toggle-layout');
// 如果第一集有绑定资源,则切换到第一集
const urlParams = new URLSearchParams(window.location.search);
const epSeq = urlParams.get('episode');
let epGroup = urlParams.get('group');
if (!epGroup || epGroup === '') epGroup = 'MAIN';
const selectedEpisode = subject.episodes
.find(ep => ep.group === epGroup && getEpisodeSeqStr(ep.sequence) === epSeq && ep.resources && ep.resources.length > 0);
console.info('selected episode', epSeq, selectedEpisode);
if (selectedEpisode) {
switchVideoUrl(selectedEpisode.resources[0])
console.debug('listItems', listItems)
var seleItem = undefined;
for (var i = 0; i < listItems.length; i++) {
var group = listItems[i].children[0].innerHTML;
var seq = listItems[i].children[1].innerHTML;
if ((epSeq + '') === seq && (epGroup + '') === group) {
seleItem = listItems[i];
break;
}
}
console.debug('seleItem', seleItem)
if (seleItem) seleItem.classList.add('active');
}
for (var i = 0; i < listItems.length; i++) {
listItems[i].addEventListener('click', function() {
console.debug('this.children', this.children);
var epGroup = this.children[0].innerHTML;
var epSeq = this.children[1].innerHTML;
var epName = this.children[2].innerHTML;
console.debug('episode seq', epSeq);
console.debug('episode name', epName);
var episode = subject.episodes.find(function(ep) {
console.debug('epSeq', epSeq)
console.debug('ep.sequence', ep.sequence)
return ((ep.group + '') === epGroup) && (getEpisodeSeqStr(ep.sequence) === epSeq) && (ep.name === epName);
})
console.debug('select episode', episode)
if(episode && episode.resources.length > 0) {
// change html style
// for (var j = 0; j < listItems.length; j++) {
// listItems[j].classList.remove('active');
// }
// this.classList.add('active');
//
// // switch video src
// console.debug('switch episode resource', episode.resources[0])
// switchVideoUrl(episode.resources[0])
window.location.href = window.location.origin.substring(0, window.location.origin.indexOf('?'))
+ '?group=' + epGroup + '&episode=' + epSeq;
} else {
alert('当前剧集没有绑定资源');
}
});
}
layoutToggleButtons.forEach(function(button) {
button.addEventListener('click', function() {
var layout = this.getAttribute('data-layout');
episodeList.classList.remove('list-group-horizontal', 'flex-wrap');
if (layout === 'horizontal') {
episodeList.classList.add('list-group-horizontal', 'flex-wrap');
}
layoutToggleButtons.forEach(function(button) {
button.classList.remove('active');
});
this.classList.add('active');
});
});
});
</script>
</body>
</html>