-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathPlayerHeader.vue
More file actions
719 lines (636 loc) · 20.2 KB
/
PlayerHeader.vue
File metadata and controls
719 lines (636 loc) · 20.2 KB
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
<template>
<div class="player-header">
<h3>正在播放: {{ episodeName }}</h3>
<div class="player-controls">
<div class="compact-button-group">
<!-- 调试按钮 - 仅在有直链和请求头时显示 -->
<div
v-if="showDebugButton"
class="compact-btn debug-btn"
@click="$emit('toggle-debug')"
title="调试信息"
>
<svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 2L2 7l10 5 10-5-10-5z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 17l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<span class="btn-text">调试</span>
</div>
<!-- 自动连播按钮 -->
<div
v-if="showAutoNext && episodes.length > 1"
class="compact-btn"
@click="$emit('toggle-auto-next')"
:class="{ active: autoNextEnabled }"
>
<svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8 5v14l11-7z" fill="currentColor"/>
</svg>
<span class="btn-text">自动连播</span>
</div>
<!-- 循环播放按钮 -->
<div
class="compact-btn"
@click="$emit('toggle-loop')"
:class="{ active: loopEnabled }"
title="循环播放当前选集"
>
<svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M17 1l4 4-4 4" stroke="currentColor" stroke-width="2" fill="none"/>
<path d="M3 11V9a4 4 0 0 1 4-4h14" stroke="currentColor" stroke-width="2" fill="none"/>
<path d="M7 23l-4-4 4-4" stroke="currentColor" stroke-width="2" fill="none"/>
<path d="M21 13v2a4 4 0 0 1-4 4H3" stroke="currentColor" stroke-width="2" fill="none"/>
</svg>
<span class="btn-text">循环播放</span>
</div>
<!-- 倒计时按钮 -->
<div
v-if="showCountdown && episodes.length > 1"
class="compact-btn"
@click="$emit('toggle-countdown')"
:class="{ active: countdownEnabled }"
>
<svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2"/>
<polyline points="12,6 12,12 16,14" stroke="currentColor" stroke-width="2"/>
</svg>
<span class="btn-text">倒计时</span>
</div>
<!-- 解析选择器 - 仅在需要解析时显示 -->
<div
v-if="showParserSelector"
class="compact-btn selector-btn"
>
<svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 2L2 7l10 5 10-5-10-5z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 17l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<a-select
:model-value="selectedParser"
@change="handleParserChange"
class="compact-select"
size="small"
:loading="parsersLoading"
:disabled="!availableParsers.length"
>
<a-option
v-for="parser in availableParsers"
:key="parser.id"
:value="parser.id"
:title="`${parser.name} (${parser.type === '1' ? 'JSON' : '嗅探'})`"
:disabled="parser.type === '0' && !snifferEnabled"
>
解析:{{ parser.name }}
<span v-if="parser.type === '0' && !snifferEnabled" style="color: #ff4d4f; font-size: 10px;">
(需嗅探器)
</span>
</a-option>
</a-select>
</div>
<!-- 代理播放地址选择器 -->
<div class="compact-btn selector-btn">
<svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 2L2 7l10 5 10-5-10-5z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 17l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 12l10 5 10-5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<a-select
:model-value="currentProxyOption"
@change="handleProxyChange"
class="compact-select"
size="small"
>
<a-option value="disabled" title="关闭代理播放功能">代理播放:关闭</a-option>
<a-option
v-for="option in proxyOptions"
:key="option.value"
:value="option.value"
:title="`${option.label}\n完整链接: ${option.url || option.value}`"
>
代理播放:{{ option.label }}
</a-option>
</a-select>
</div>
<!-- 画质选择器 -->
<div
v-if="qualities && qualities.length > 1"
class="compact-btn selector-btn"
>
<svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="2" y="3" width="20" height="14" rx="2" ry="2" stroke="currentColor" stroke-width="2"/>
<line x1="8" y1="21" x2="16" y2="21" stroke="currentColor" stroke-width="2"/>
<line x1="12" y1="17" x2="12" y2="21" stroke="currentColor" stroke-width="2"/>
<text x="12" y="12" text-anchor="middle" fill="currentColor" font-size="8">HD</text>
</svg>
<a-select
:model-value="currentQuality"
@change="$emit('quality-change', $event)"
class="compact-select"
size="small"
>
<a-option
v-for="quality in qualities"
:key="quality.name"
:value="quality.name"
:title="`切换到${quality.name}画质`"
>
画质:{{ quality.name }}
</a-option>
</a-select>
</div>
<!-- 播放器切换选择器 -->
<div class="compact-btn selector-btn">
<svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2" stroke="currentColor" stroke-width="2"/>
<circle cx="8.5" cy="8.5" r="1.5" fill="currentColor"/>
<path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" stroke="currentColor" stroke-width="2"/>
</svg>
<a-select
:model-value="playerType"
@change="$emit('player-change', $event)"
class="compact-select"
size="small"
>
<a-option value="default" title="使用浏览器默认的HTML5视频播放器">默认播放器</a-option>
<a-option value="artplayer" title="使用ArtPlayer播放器,支持更多功能和自定义选项">ArtPlayer</a-option>
</a-select>
</div>
<!-- 片头片尾设置按钮 -->
<div
class="compact-btn"
:class="{ active: skipEnabled }"
@click="$emit('open-skip-settings')"
>
<svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 4l10 8-10 8V4z" fill="currentColor"/>
<path d="M19 5v14" stroke="currentColor" stroke-width="2"/>
<path d="M3 12h2" stroke="currentColor" stroke-width="2"/>
<path d="M19 12h2" stroke="currentColor" stroke-width="2"/>
</svg>
<span class="btn-text">片头片尾</span>
</div>
<!-- 关闭按钮 -->
<div class="compact-btn close-btn" @click="$emit('close')">
<svg class="btn-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<line x1="18" y1="6" x2="6" y2="18" stroke="currentColor" stroke-width="2"/>
<line x1="6" y1="6" x2="18" y2="18" stroke="currentColor" stroke-width="2"/>
</svg>
<span class="btn-text">关闭</span>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
import { useParserStore } from '@/stores/parser'
import { isSnifferEnabled } from '@/api/services/sniffer'
// Props
const props = defineProps({
episodeName: {
type: String,
default: '未知选集'
},
playerType: {
type: String,
default: 'default'
},
episodes: {
type: Array,
default: () => []
},
autoNextEnabled: {
type: Boolean,
default: false
},
loopEnabled: {
type: Boolean,
default: false
},
countdownEnabled: {
type: Boolean,
default: false
},
skipEnabled: {
type: Boolean,
default: false
},
showAutoNext: {
type: Boolean,
default: true
},
showCountdown: {
type: Boolean,
default: true
},
showDebugButton: {
type: Boolean,
default: false
},
// 画质相关属性
qualities: {
type: Array,
default: () => []
},
currentQuality: {
type: String,
default: '默认'
},
// 解析相关属性
showParserSelector: {
type: Boolean,
default: false
},
needsParsing: {
type: Boolean,
default: false
},
parseData: {
type: Object,
default: () => null
}
})
// Emits
const emit = defineEmits([
'toggle-auto-next',
'toggle-loop',
'toggle-countdown',
'player-change',
'open-skip-settings',
'toggle-debug',
'close',
'proxy-change',
'quality-change',
'parser-change'
])
// 代理播放地址相关状态
const currentProxyOption = ref('disabled')
const proxyOptions = ref([])
// 解析器相关状态
const parserStore = useParserStore()
const selectedParser = ref('')
const availableParsers = ref([])
const parsersLoading = ref(false)
const snifferEnabled = ref(false)
// 获取代理播放地址配置名称
const getProxyName = (url) => {
if (!url) return '未知'
const hashIndex = url.indexOf('#')
if (hashIndex !== -1 && hashIndex < url.length - 1) {
return url.substring(hashIndex + 1)
}
return '默认代理'
}
// 加载代理播放地址配置
const loadProxyConfig = () => {
try {
// 从设置中获取代理播放配置
const savedAddresses = JSON.parse(localStorage.getItem('addressSettings') || '{}')
const proxyPlayEnabled = savedAddresses.proxyPlayEnabled || false
const proxyPlay = savedAddresses.proxyPlay || ''
// 清空选项
proxyOptions.value = []
// 先加载历史记录
loadProxyHistory()
// 如果启用了代理播放且有配置地址
if (proxyPlayEnabled && proxyPlay) {
// 检查当前配置的代理是否已在历史记录中
const existingIndex = proxyOptions.value.findIndex(option => option.url === proxyPlay)
if (existingIndex !== -1) {
// 如果在历史记录中,将其移到最前面
const currentOption = proxyOptions.value.splice(existingIndex, 1)[0]
proxyOptions.value.unshift(currentOption)
} else {
// 如果不在历史记录中,添加到最前面
const proxyName = getProxyName(proxyPlay)
proxyOptions.value.unshift({
value: proxyPlay,
label: `${proxyName} (当前)`,
url: proxyPlay
})
}
// 设置默认选中当前配置的代理
currentProxyOption.value = proxyPlay
} else {
// 如果代理播放开关关闭,默认选择关闭
currentProxyOption.value = 'disabled'
}
console.log('代理播放配置加载完成:', {
enabled: proxyPlayEnabled,
current: proxyPlay,
optionsCount: proxyOptions.value.length,
selected: currentProxyOption.value
})
} catch (error) {
console.error('加载代理播放配置失败:', error)
currentProxyOption.value = 'disabled'
}
}
// 加载代理播放地址历史记录
const loadProxyHistory = () => {
try {
// 只从设置界面的存储位置加载
const addressHistoryKey = 'address-history-proxy-play'
const addressHistory = JSON.parse(localStorage.getItem(addressHistoryKey) || '[]')
// 添加历史记录到选项中
addressHistory.forEach(item => {
const url = item.url || item.value || ''
if (!url) return
const exists = proxyOptions.value.some(option => option.url === url)
if (!exists) {
const proxyName = getProxyName(url)
proxyOptions.value.push({
value: url,
label: proxyName,
url: url
})
}
})
console.log('已加载代理播放历史记录:', proxyOptions.value.length, '个选项')
} catch (error) {
console.error('加载代理播放历史记录失败:', error)
}
}
// 保存代理播放地址到历史记录
const saveToProxyHistory = (url) => {
if (!url || url === 'disabled') return
try {
const proxyName = getProxyName(url)
const timestamp = Date.now()
// 只保存到设置界面使用的存储位置
const addressHistoryKey = 'address-history-proxy-play'
const addressHistory = JSON.parse(localStorage.getItem(addressHistoryKey) || '[]')
// 检查是否已存在
const existingIndex = addressHistory.findIndex(item => item.url === url)
if (existingIndex !== -1) {
// 如果存在,移到最前面
addressHistory.splice(existingIndex, 1)
}
// 添加到最前面
addressHistory.unshift({
url: url,
timestamp: timestamp
})
// 限制历史记录数量(最多保存10个)
if (addressHistory.length > 10) {
addressHistory.splice(10)
}
localStorage.setItem(addressHistoryKey, JSON.stringify(addressHistory))
console.log('已保存代理播放地址到历史记录:', url)
} catch (error) {
console.error('保存代理播放历史记录失败:', error)
}
}
// 处理代理播放地址变更
const handleProxyChange = (value) => {
currentProxyOption.value = value
// 如果不是关闭,保存到历史记录
if (value !== 'disabled') {
saveToProxyHistory(value)
}
// 发送事件给父组件
emit('proxy-change', value)
}
// 加载解析器配置
const loadParsers = async () => {
try {
parsersLoading.value = true
// 获取已启用的解析器
availableParsers.value = parserStore.enabledParsers.map(parser => ({
id: parser.id,
name: parser.name,
type: parser.type,
url: parser.url,
enabled: parser.enabled
}))
// 检查嗅探器是否可用
snifferEnabled.value = isSnifferEnabled()
// 从本地存储加载上次选择的解析器
const savedParser = localStorage.getItem('selectedParser')
let shouldTriggerParsing = false
if (savedParser && availableParsers.value.find(p => p.id === savedParser)) {
selectedParser.value = savedParser
shouldTriggerParsing = true
} else if (availableParsers.value.length > 0) {
// 默认选择第一个解析器
selectedParser.value = availableParsers.value[0].id
shouldTriggerParsing = true
}
console.log('解析器配置加载完成:', {
count: availableParsers.value.length,
selected: selectedParser.value,
snifferEnabled: snifferEnabled.value,
shouldTriggerParsing
})
// 如果选择了解析器且有解析数据,自动触发解析
if (shouldTriggerParsing && selectedParser.value && props.parseData) {
console.log('🚀 [自动解析] 触发默认解析器解析')
// 延迟一点时间确保组件完全初始化
nextTick(() => {
handleParserChange(selectedParser.value)
})
}
} catch (error) {
console.error('加载解析器配置失败:', error)
} finally {
parsersLoading.value = false
}
}
// 处理解析器变更
const handleParserChange = (parserId) => {
selectedParser.value = parserId
// 获取选中的解析器信息
const parser = availableParsers.value.find(p => p.id === parserId)
// 保存到本地存储(统一保存为JSON对象格式)
if (parser) {
localStorage.setItem('selectedParser', JSON.stringify(parser))
}
// 发送事件给父组件
emit('parser-change', {
parserId,
parser,
parseData: props.parseData
})
console.log('解析器已切换:', parser)
}
// 监听设置变化
const handleStorageChange = (event) => {
if (event.key === 'addressSettings') {
// 设置发生变化时重新加载配置
loadProxyConfig()
}
}
// 组件挂载时加载配置
onMounted(() => {
loadProxyConfig()
// 如果需要解析,加载解析器配置
if (props.showParserSelector) {
loadParsers()
}
// 监听localStorage变化
window.addEventListener('storage', handleStorageChange)
// 监听自定义事件(用于同一页面内的设置变化)
window.addEventListener('addressSettingsChanged', loadProxyConfig)
})
// 监听showParserSelector变化
watch(() => props.showParserSelector, (newValue) => {
if (newValue) {
loadParsers()
}
})
// 组件卸载时清理监听器
onUnmounted(() => {
window.removeEventListener('storage', handleStorageChange)
window.removeEventListener('addressSettingsChanged', loadProxyConfig)
})
</script>
<style scoped>
.player-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
padding: 0 4px;
}
.player-header h3 {
margin: 0;
font-size: 16px;
font-weight: 600;
color: #2c3e50;
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin-right: 12px;
}
.player-controls {
display: flex;
align-items: center;
gap: 8px;
}
.compact-button-group {
display: flex;
align-items: center;
gap: 2px;
background: #f8f9fa;
border-radius: 6px;
padding: 2px;
border: 1px solid #e9ecef;
}
.compact-btn {
display: flex;
align-items: center;
gap: 4px;
padding: 6px 10px;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
background: transparent;
border: none;
font-size: 12px;
font-weight: 500;
color: #495057;
min-height: 28px;
position: relative;
}
.compact-btn:hover {
background: #e9ecef;
color: #212529;
transform: translateY(-1px);
}
.compact-btn.active {
background: #23ade5;
color: white;
box-shadow: 0 2px 8px rgba(35, 173, 229, 0.3);
}
.compact-btn.active:hover {
background: #1e90ff;
}
.compact-btn.close-btn {
color: #dc3545;
}
.compact-btn.close-btn:hover {
background: #f8d7da;
color: #721c24;
}
.compact-btn.debug-btn {
color: #6f42c1;
}
.compact-btn.debug-btn:hover {
background: #e2d9f3;
color: #5a2d91;
}
.btn-icon {
width: 14px;
height: 14px;
flex-shrink: 0;
}
.btn-text {
font-size: 11px;
white-space: nowrap;
}
.selector-btn {
position: relative;
padding: 0;
overflow: hidden;
}
.compact-select {
border: none !important;
background: transparent !important;
box-shadow: none !important;
min-width: 120px;
}
.compact-select :deep(.arco-select-view) {
border: none !important;
background: transparent !important;
padding: 6px 10px;
font-size: 11px;
font-weight: 500;
}
.compact-select :deep(.arco-select-view-suffix) {
color: currentColor;
}
/* 响应式设计 */
@media (max-width: 768px) {
.player-header {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.player-header h3 {
margin-right: 0;
font-size: 15px;
}
.compact-button-group {
flex-wrap: wrap;
width: 100%;
justify-content: center;
}
.compact-btn {
flex: 1;
min-width: 80px;
justify-content: center;
}
.btn-text {
display: none;
}
.selector-btn {
flex: 2;
}
.compact-select {
min-width: 100px;
}
}
@media (max-width: 480px) {
.compact-btn {
padding: 4px 6px;
min-height: 26px;
}
.btn-icon {
width: 12px;
height: 12px;
}
}
</style>