-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
293 lines (281 loc) · 11.3 KB
/
app.js
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
var media = new Vue({
el:'#media',
template:`
<div class="media">
<!--<template v-if="this.basename!="></template>-->
<div v-show="!show" @click="showPannel" class="media-show-btn">媒体列表</div>
<div id="media-dir" class="media-dir" :class="{'media-with-player':showPlayer}" v-if="sourcelists.length>0 && show==1" >
<div class="media-nav">
<div>{{pathname}}</div>
<div v-if="revert" @click="revertPlay(revert.filename,revert.time)" class="media-nav-item media-nav-revent">▶继续播放{{revert.filename}} <span style="color:#00b91f;">{{revert.timeFormat}}</span> </div>
<div @click="prev()" class="media-nav-item media-nav-prev">⏮上一集</div>
<div @click="next()" class="media-nav-item media-nav-next">⏭下一集</div>
<div @click="close()" class="media-nav-item media-nav-next">❌关闭</div>
</div>
<div class="media-files">
<div v-for="(source) in sourcelists" @click="playMedia(source.url,source.sign)" :data-sign="source.sign" class="media-item" :class="{'media-current-item':playfilename==source.name}">
{{source.name}}
</div>
</div>
</div>
<div id="media-history" class="media-history" v-if="Object.keys(allHistory).length>0 && show==2">
<h2>播放历史</h2> <span @click="close()" class="media-history-delete">x</span>
<div @click="jump(dir)" class="media-history-item" v-for="(history,dir) in allHistory">
{{dir}}/{{history.filename}}
<span @click.prevert="autoRevertPlay(dir)" style="color: #00b91f;">▶{{history.timeFormat}}</span>
<span @click.prevent="removeHistory(dir)" class="media-history-delete">x</span>
</div>
</div>
<div class="artplayer-app" v-show="showPlayer" >
<div class="media-player-title">{{pathname}}/{{playfilename}}</div>
<div id="artplayer" ref="player"></div>
</div>
</div>
`,
data(){
return {
show:1,
showPlayer:0,
allHistory:{},
mediaDir: [],
sourcelists: {},
pathname: null,
basename: null,
playfilename: null,
revert: null,
firstLoaded:0
}
},
watch:{
show(newValue){
localStorage.setItem('MediaShow',newValue)
if(newValue==2){
this.refreshHistory()
}
},
},
methods:{
loadList(response,pathname = null){
this.firstLoaded = 1
if(response.code==200){
this.pathname = pathname??this.pathname
this.sourcelists = []
for (let ck in response.data.content){
if(response.data.content[ck].type==2){
response.data.content[ck].url = (pathname??this.pathname) + '/' + response.data.content[ck].name
this.sourcelists.push(response.data.content[ck])
}
}
if(this.sourcelists.length==0 && this.show==1){
this.show = 2
}
if(this.sourcelists.length>0 && this.show==2){
this.show=1
}
this.revertTime(this.pathname);
this.$forceUpdate()
}
},
jump(url){
axios.post('/api/fs/list',{
path:url,password:"",page:1,per_page:0,refresh:true
}).then((response)=>{
this.pathname = url
this.revertTime(this.pathname)
this.show = 1
})
},
autoRevertPlay(url){
axios.post('/api/fs/list',{
path:url,password:"",page:1,per_page:0,refresh:true
}).then((response)=>{
this.show = 1
this.pathname = url
this.revertTime(this.pathname)
this.revertPlay(this.revert.filename,this.revert.time)
})
},
reBuildXHR(){
function ajaxEventTrigger(event) {
var ajaxEvent = new CustomEvent(event, { detail: this });
window.dispatchEvent(ajaxEvent);
}
var oldXHR = window.XMLHttpRequest;
function newXHR() {
var realXHR = new oldXHR();
realXHR.addEventListener('abort', function () { ajaxEventTrigger.call(this, 'ajaxAbort'); }, false);
realXHR.addEventListener('error', function () { ajaxEventTrigger.call(this, 'ajaxError'); }, false);
realXHR.addEventListener('load', function () { ajaxEventTrigger.call(this, 'ajaxLoad'); }, false);
realXHR.addEventListener('loadstart', function () { ajaxEventTrigger.call(this, 'ajaxLoadStart'); }, false);
realXHR.addEventListener('progress', function () { ajaxEventTrigger.call(this, 'ajaxProgress'); }, false);
realXHR.addEventListener('timeout', function () { ajaxEventTrigger.call(this, 'ajaxTimeout'); }, false);
realXHR.addEventListener('loadend', function () { ajaxEventTrigger.call(this, 'ajaxLoadEnd'); }, false);
realXHR.addEventListener('readystatechange', function() { ajaxEventTrigger.call(this, 'ajaxReadyStateChange'); }, false);
return realXHR;
}
window.XMLHttpRequest = newXHR;
window.addEventListener('ajaxLoadEnd',(e)=> {
let response = JSON.parse(e.detail.responseText)
if(response){
if(response.data && response.data.content){
this.loadList(response,this.currentDir());
}
}
})
},
currentDir(){
this.pathname = decodeURIComponent(location.pathname);
let paths = this.pathname.split('/')
this.filename = paths.pop()
return this.pathname
},
playMedia(path,sign,time = null){
console.log(path,sign,time)
this.$el.style.width = '100vw'
this.$el.style.height = '100vh'
this.showPlayer = 1;
let src = location.protocol + '//' + location.host+'/d'+path+'?sign='+sign
let subpaths = path.split('/');
this.playfilename = subpaths.pop()
this.art.switchUrl(src,this.playfilename)
this.art.title = this.playfilename
this.art.subtitle = this.playfilename
this.art.on('video:ended',()=>{
this.next()
})
this.art.play().then(()=>{
if(time){
this.art.currentTime = time
time = null;
}
})
this.revert = null
},
initplayer(){
this.art = new Artplayer({
container: '#artplayer',
volume: 0.5,
autoSize: false,
autoMini: true,
loop: false,
flip: true,
playbackRate: true,
aspectRatio: true,
setting: true,
hotkey: true,
pip: true,
mutex: true,
fullscreen: true,
fullscreenWeb: true,
subtitleOffset: true,
miniProgressBar: false,
playsInline: true,
});
this.art.on('video:progress',(e)=>{
if(this.pathname && this.playfilename){
this.handleProcess(this.pathname,this.playfilename,parseInt(this.art.currentTime))
}
})
},
handleProcess(dir,filename,time){
if(dir && time>0){
let mediaProcess = JSON.parse(localStorage.getItem('mediaProcess')??'{}')
mediaProcess[dir] = {filename,time:parseInt(time)};
localStorage.setItem('mediaProcess',JSON.stringify(mediaProcess))
}
},
next(){
let nextElement = document.getElementsByClassName('media-current-item')[0].nextElementSibling
if(nextElement){
this.playMedia(this.pathname+'/'+nextElement.textContent.trim(),nextElement.dataset.sign)
}
},
prev(){
let prevElement = document.getElementsByClassName('media-current-item')[0].previousElementSibling
if(prevElement){
this.playMedia(this.pathname+'/'+prevElement.textContent.trim(),prevElement.dataset.sign)
}
},
close(){
if(this.showPlayer==0){
if(this.show==1){
this.show =2
}else if(this.show==2){
this.show = 0
}
}else{
this.closePlayer()
}
},
closePlayer(){
console.log('closePlayer')
this.$el.style.width = 'auto'
this.$el.style.height = 'auto'
this.showPlayer = 0;
this.playfilename = null
this.revertTime(this.pathname)
if(this.art && this.art.playing){
this.art.pause()
}
},
showPannel(){
if(this.sourcelists.length>0){
this.show = 1
}else{
this.refreshHistory()
this.show = 2
}
},
refreshHistory(){
this.allHistory = JSON.parse(localStorage.getItem('mediaProcess')??'{}')
for (let k in this.allHistory){
this.allHistory[k].timeFormat = Math.floor(this.allHistory[k].time/60) + ':' + this.allHistory[k].time%60
}
},
revertTime(pathname){
let mediaProcess = JSON.parse(localStorage.getItem('mediaProcess')??'{}')
if(mediaProcess[pathname]){
this.revert = mediaProcess[pathname]
this.revert.timeFormat = Math.floor(this.revert.time/60) + ':' + this.revert.time%60
}else{
this.revert = null
}
},
revertPlay(filename,time){
let sign = null
for (let k in this.sourcelists){
if(this.sourcelists[k].name==filename){
sign = this.sourcelists[k].sign
break;
}
}
if(sign){
this.playMedia(this.pathname+'/'+filename,sign,time)
}
},
removeHistory(dir){
let mediaProcess = JSON.parse(localStorage.getItem('mediaProcess')??'{}')
delete mediaProcess[dir]
this.allHistory = mediaProcess
localStorage.setItem('mediaProcess',JSON.stringify(mediaProcess))
},
//当插件初始化完成的时候,有概率没有监听到当前文件列表页的数据,所有有必要进行第一次文件列表的加载
firstLoad(){
axios.post('/api/fs/list',{
path:this.currentDir(),password:"",page:1,per_page:0,refresh:true
}).then((response)=>{
this.currentDir()
})
}
},
created(){
this.show = Number(localStorage.getItem('MediaShow')??0)
},
mounted(){
this.currentDir()
this.revertTime(this.pathname);
this.initplayer()
this.reBuildXHR()
this.firstLoad()
}
})