add subtitle preview server
This commit is contained in:
parent
651607e354
commit
2ce50f2971
7 changed files with 322 additions and 4 deletions
1
cdoseaplay/static/index.html
Normal file
1
cdoseaplay/static/index.html
Normal file
|
|
@ -0,0 +1 @@
|
|||
<script src="subtitles.js"></script>
|
||||
77
cdoseaplay/static/subtitles.js
Normal file
77
cdoseaplay/static/subtitles.js
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
'use strict'
|
||||
|
||||
var app = {}
|
||||
|
||||
app.status = {
|
||||
currentTime: 0,
|
||||
path: null,
|
||||
subtitles: {}
|
||||
}
|
||||
|
||||
app.render = function() {
|
||||
|
||||
var html = ''
|
||||
|
||||
html += 'Current Time: ' + app.status.currentTime + '<br>'
|
||||
|
||||
if (app.status.subtitles[app.status.current]) {
|
||||
app.status.subtitles[app.status.current].forEach(function(sub) {
|
||||
if (app.status.currentTime >= sub['in'] && app.status.currentTime < sub.out) {
|
||||
html += '<br><br><b>' + sub['in'] + ' ' + sub.out + ': ' + sub.value + '</b>'
|
||||
} else {
|
||||
html += '<br><br>' + sub['in'] + ' ' + sub.out + ': ' + sub.value
|
||||
}
|
||||
})
|
||||
}
|
||||
if (app.status.subtitles[app.status.next]) {
|
||||
html += '<br><br>Next: '
|
||||
app.status.subtitles[app.status.next].forEach(function(sub) {
|
||||
html += '<br><br>' + sub['in'] + ' ' + sub.out + ': ' + sub.value
|
||||
})
|
||||
}
|
||||
document.body.innerHTML = html
|
||||
}
|
||||
|
||||
app.connectWS = function() {
|
||||
app.ws = new WebSocket('ws://' + document.location.host + '/ws/')
|
||||
app.ws.onopen = function() {
|
||||
//console.log('open')
|
||||
}
|
||||
app.ws.onerror = function(event) {
|
||||
//console.log('error')
|
||||
ws.close()
|
||||
}
|
||||
app.ws.onclose = function(event) {
|
||||
//console.log('closed')
|
||||
setTimeout(app.connectWS, 1000)
|
||||
}
|
||||
app.ws.onmessage = function(event) {
|
||||
var request
|
||||
try {
|
||||
request = JSON.parse(event.data)
|
||||
} catch(e) {
|
||||
request = {
|
||||
'error': {},
|
||||
'debug': event.data
|
||||
}
|
||||
}
|
||||
//console.log('message', request)
|
||||
app.status.currentTime = request.currentTime
|
||||
|
||||
if (request.current) {
|
||||
app.status.current = request.current
|
||||
}
|
||||
if (request.next) {
|
||||
app.status.next = request.next
|
||||
}
|
||||
if (request.subtitles) {
|
||||
Object.keys(request.subtitles).forEach(function(name) {
|
||||
app.status.subtitles[name] = request.subtitles[name]
|
||||
})
|
||||
}
|
||||
app.render()
|
||||
}
|
||||
}
|
||||
|
||||
app.connectWS()
|
||||
window.addEventListener('load', app.render, false)
|
||||
Loading…
Add table
Add a link
Reference in a new issue