mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-04-19 16:32:15 +00:00
subtitle parsing poggers
This commit is contained in:
parent
7a1fdd9032
commit
56e7d29db3
5 changed files with 12593 additions and 5679 deletions
|
|
@ -184,7 +184,7 @@
|
|||
<input type="range" min="0" max="1000" value="0" id="prog">
|
||||
<span class="ts" id="remaining">--:--</span>
|
||||
<div class="subtitles dropdown dropup with-arrow">
|
||||
<span class="material-icons ctrl" title="Subtitles [S]" id="bcap" data-toggle="dropdown"
|
||||
<span class="material-icons ctrl" title="Subtitles [C]" id="bcap" data-toggle="dropdown"
|
||||
id="subtitle-popover" aria-haspopup="true" aria-expanded="false">
|
||||
subtitles
|
||||
</span>
|
||||
|
|
|
|||
18211
app/bundle.js
18211
app/bundle.js
File diff suppressed because it is too large
Load diff
|
|
@ -324,7 +324,7 @@ document.onkeydown = function (a) {
|
|||
case "t":
|
||||
btheatre();
|
||||
break;
|
||||
case "s":
|
||||
case "c":
|
||||
bcap();
|
||||
break;
|
||||
case "f":
|
||||
|
|
|
|||
|
|
@ -1,20 +1,5 @@
|
|||
var parser = new MatroskaSubtitles()
|
||||
let tracks
|
||||
let tracks = []
|
||||
|
||||
parser.once('tracks', function (pTracks) {
|
||||
tracks = []
|
||||
pTracks.forEach(track => {
|
||||
if (track.type == "ass") {
|
||||
tracks[track.number] = video.addTextTrack('captions', track.number, !!track.language ? track.language : track.number)
|
||||
}
|
||||
})
|
||||
if (video.textTracks[0]) {
|
||||
video.textTracks[0].mode = "showing"
|
||||
}
|
||||
})
|
||||
parser.on('subtitle', function (subtitle, trackNumber) {
|
||||
subConvt(subtitle, trackNumber)
|
||||
})
|
||||
let re_newline = /\\N/g, // replace \N with newline
|
||||
re_softbreak = /\\n/g, // There's no equivalent function in WebVTT.
|
||||
re_hardspace = /\\h/g, // Replace with
|
||||
|
|
@ -61,6 +46,7 @@ function subConvt(result, trackNumber) {
|
|||
}
|
||||
if ((posNum - 1) % 4 == 0) {
|
||||
cue.align = "start";
|
||||
cue.text = " \r\n"
|
||||
} else if ((posNum - 1) % 4 == 2) {
|
||||
cue.align = "end";
|
||||
}
|
||||
|
|
@ -123,5 +109,7 @@ function subConvt(result, trackNumber) {
|
|||
content += '</' + tagsToClose.pop() + '>';
|
||||
}
|
||||
cue.text += `${content}\r\n `
|
||||
tracks[trackNumber].addCue(cue)
|
||||
if (!Object.values(tracks[trackNumber].cues).some(c => c.text == cue.text)) {
|
||||
tracks[trackNumber].addCue(cue)
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ const client = new WebTorrent(),
|
|||
],
|
||||
scope = '/app/',
|
||||
sw = navigator.serviceWorker.register('sw.js', { scope })
|
||||
let parser
|
||||
//for debugging
|
||||
function t(a) {
|
||||
switch (a) {
|
||||
|
|
@ -52,6 +53,8 @@ function addTorrent(magnet) {
|
|||
if (client.torrents.length >= maxTorrents) {
|
||||
client.remove(client.torrents[0].infoHash)
|
||||
}
|
||||
halfmoon.toggleModal("tsearch")
|
||||
document.location.href = "#player"
|
||||
client.add(magnet, async function (torrent) {
|
||||
await sw
|
||||
function onProgress() {
|
||||
|
|
@ -91,10 +94,7 @@ function addTorrent(magnet) {
|
|||
if (subStream) {
|
||||
subStream.destroy()
|
||||
}
|
||||
subStream = videoFile.createReadStream().pipe(parser)
|
||||
document.location.href = "#player"
|
||||
nowPlaying(selected)
|
||||
halfmoon.toggleModal("tsearch")
|
||||
})
|
||||
|
||||
}
|
||||
|
|
@ -127,11 +127,36 @@ function serveFile(file, req) {
|
|||
res.headers['Content-Length'] = file.length
|
||||
}
|
||||
|
||||
|
||||
res.headers['Cache-Control'] = 'no-store'
|
||||
res.body = req.method === 'HEAD' ? '' : 'stream'
|
||||
|
||||
// file.createReadStream(range).pipe(parser)
|
||||
parser = new MatroskaSubtitles({ prevInstance: parser, offset: range.start })
|
||||
|
||||
return [res, req.method === 'GET' && file.createReadStream(range)]
|
||||
parser.once('tracks', function (pTracks) {
|
||||
tracks = []
|
||||
pTracks.forEach(track => {
|
||||
if (track.type == "ass") {
|
||||
tracks[track.number] = video.addTextTrack('captions', track.number, !!track.language ? track.language : track.number)
|
||||
}
|
||||
})
|
||||
if (video.textTracks[0]) {
|
||||
video.textTracks[0].mode = "showing"
|
||||
}
|
||||
})
|
||||
|
||||
parser.once('cues', function () {
|
||||
console.log('seeking ready')
|
||||
})
|
||||
|
||||
parser.on('subtitle', function (subtitle, trackNumber) {
|
||||
subConvt(subtitle, trackNumber)
|
||||
})
|
||||
|
||||
// parser is really a passthrough mkv stream now
|
||||
file.createReadStream(range).pipe(parser)
|
||||
|
||||
return [res, req.method === 'GET' && parser]
|
||||
}
|
||||
|
||||
// kind of a fetch event from service worker but for the main thread.
|
||||
|
|
|
|||
Loading…
Reference in a new issue