mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-04-21 20:31:57 +00:00
subtitle parsing progress, still a bit buggy
This commit is contained in:
parent
a868626af1
commit
792021bcb4
5 changed files with 229 additions and 211 deletions
|
|
@ -306,4 +306,4 @@ async function rssFetch(url) {
|
|||
|
||||
alRequest()
|
||||
|
||||
search = /((?:\[[^\]]*\])*)?\s*((?:[^\d\[\.](?!S\d))*)?\s*((?:S\d+[^\w\[]*E?)?[\d\-]*)\s*(.*)?/
|
||||
// search = /((?:\[[^\]]*\])*)?\s*((?:[^\d\[\.](?!S\d))*)?\s*((?:S\d+[^\w\[]*E?)?[\d\-]*)\s*(.*)?/
|
||||
|
|
@ -138,7 +138,7 @@
|
|||
<div class="overflow-y-hidden content-wrapper">
|
||||
<section id="player">
|
||||
<a href="#player" class="w-full h-full"></a>
|
||||
<video id="video" class="w-full" autoPictureInPicture preload>
|
||||
<video id="video" class="w-full" autoPictureInPicture>
|
||||
</video>
|
||||
<div class="player d-none flex-column justify-content-between w-full h-full">
|
||||
<div class="h-full w-full d-flex flex-column justify-content-between" id="ptoggle">
|
||||
|
|
|
|||
|
|
@ -13068,19 +13068,19 @@ if (typeof Object.create === 'function') {
|
|||
|
||||
},{}],14:[function(require,module,exports){
|
||||
(function (Buffer){
|
||||
const Transform = require('readable-stream').Transform
|
||||
const ebml = require('ebml')
|
||||
const ebmlBlock = require('ebml-block')
|
||||
const readElement = require('./lib/read-element')
|
||||
const Transform = require('readable-stream').Transform
|
||||
const ebml = require('ebml')
|
||||
const ebmlBlock = require('ebml-block')
|
||||
const readElement = require('./lib/read-element')
|
||||
|
||||
// track elements we care about
|
||||
const TRACK_ELEMENTS = ['TrackNumber', 'TrackType', 'Language', 'CodecID', 'CodecPrivate']
|
||||
const SUBTITLE_TYPES = ['S_TEXT/UTF8', 'S_TEXT/SSA', 'S_TEXT/ASS']
|
||||
const ASS_KEYS = ['readOrder', 'layer', 'style', 'name', 'marginL', 'marginR', 'marginV', 'effect', 'text']
|
||||
// track elements we care about
|
||||
const TRACK_ELEMENTS = ['TrackNumber', 'TrackType', 'Language', 'CodecID', 'CodecPrivate']
|
||||
const SUBTITLE_TYPES = ['S_TEXT/UTF8', 'S_TEXT/SSA', 'S_TEXT/ASS']
|
||||
const ASS_KEYS = ['readOrder', 'layer', 'style', 'name', 'marginL', 'marginR', 'marginV', 'effect', 'text']
|
||||
|
||||
const CUES_ID = Buffer.from('1C53BB6B', 'hex')
|
||||
const CUES_ID = Buffer.from('1C53BB6B', 'hex')
|
||||
|
||||
class MatroskaSubtitles extends Transform {
|
||||
class MatroskaSubtitles extends Transform {
|
||||
constructor ({ prevInstance, offset } = {}) {
|
||||
super()
|
||||
|
||||
|
|
@ -13090,6 +13090,8 @@ class MatroskaSubtitles extends Transform {
|
|||
|
||||
let currentSeekID = null
|
||||
|
||||
let waitForNext = false
|
||||
|
||||
this.decoder = new ebml.Decoder()
|
||||
|
||||
if (prevInstance instanceof MatroskaSubtitles) {
|
||||
|
|
@ -13097,16 +13099,27 @@ class MatroskaSubtitles extends Transform {
|
|||
|
||||
prevInstance.once('drain', () => {
|
||||
// prevInstance.end()
|
||||
// console.log('prevInstance drain')
|
||||
console.log('prevInstance drained')
|
||||
})
|
||||
|
||||
if (offset === 0) {
|
||||
// just begin normal parsing
|
||||
this.subtitleTracks = prevInstance.subtitleTracks || new Map()
|
||||
this.timecodeScale = prevInstance.timecodeScale || 1
|
||||
this.cues = prevInstance.cues
|
||||
|
||||
this.decoder.on('data', _onMetaData.bind(this))
|
||||
return
|
||||
}
|
||||
|
||||
// copy previous metadata
|
||||
this.subtitleTracks = prevInstance.subtitleTracks
|
||||
this.timecodeScale = prevInstance.timecodeScale
|
||||
this.cues = prevInstance.cues
|
||||
|
||||
if (!this.cues) {
|
||||
return console.warn('No cues.')
|
||||
this.decoder = null
|
||||
return console.warn('No cues was parsed. Subtitle parsing disabled.')
|
||||
}
|
||||
|
||||
// find a cue that's close to the file offset
|
||||
|
|
@ -13127,10 +13140,15 @@ class MatroskaSubtitles extends Transform {
|
|||
|
||||
this.decoder.on('data', _onMetaData.bind(this))
|
||||
} else {
|
||||
this.decoder = null
|
||||
console.warn(`No cues for offset ${offset}. Subtitle parsing disabled.`)
|
||||
}
|
||||
} else {
|
||||
if (offset) return console.error(`Offset is ${offset}, and must be 0 for initial instance!`)
|
||||
if (offset) {
|
||||
this.decoder = null
|
||||
console.error(`Offset is ${offset}, and must be 0 for initial instance. Subtitle parsing disabled.`)
|
||||
return
|
||||
}
|
||||
|
||||
this.subtitleTracks = new Map()
|
||||
this.timecodeScale = 1
|
||||
|
|
@ -13138,15 +13156,12 @@ class MatroskaSubtitles extends Transform {
|
|||
this.decoder.on('data', _onMetaData.bind(this))
|
||||
}
|
||||
|
||||
let waitForNext = false
|
||||
|
||||
function _onMetaData (chunk) {
|
||||
if (waitForNext) {
|
||||
waitForNext = false
|
||||
// Keep cues if this is the same segment
|
||||
if (!this.cues || this.cues.start !== chunk[1].start) {
|
||||
// Add 0 as a valid cue point
|
||||
this.cues = { start: chunk[1].start, positions: new Set([0]) }
|
||||
this.cues = { start: chunk[1].start, positions: new Set() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -13271,6 +13286,8 @@ class MatroskaSubtitles extends Transform {
|
|||
}
|
||||
|
||||
_transform (chunk, _, callback) {
|
||||
if (!this.decoder) return callback(null, chunk)
|
||||
|
||||
if (this.skip) {
|
||||
// skip bytes to reach cue position
|
||||
if (this.skip < chunk.length) {
|
||||
|
|
@ -13288,9 +13305,9 @@ class MatroskaSubtitles extends Transform {
|
|||
|
||||
callback(null, chunk)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MatroskaSubtitles
|
||||
module.exports = MatroskaSubtitles
|
||||
|
||||
}).call(this,require("buffer").Buffer)
|
||||
},{"./lib/read-element":15,"buffer":3,"ebml":12,"ebml-block":9,"readable-stream":31}],15:[function(require,module,exports){
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ video[src=""] {
|
|||
}
|
||||
|
||||
video::cue {
|
||||
background: none;
|
||||
font-family: "Open Sans", sans-serif;
|
||||
color: #fff;
|
||||
text-shadow: 2px 2px 0 #000,
|
||||
|
|
@ -100,7 +101,6 @@ video::cue {
|
|||
-2px 0px 0 #000,
|
||||
0px -2px 0 #000,
|
||||
2px 2px 2px #000;
|
||||
background: none;
|
||||
}
|
||||
|
||||
.controls {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ function addTorrent(magnet) {
|
|||
alertType: "alert-success",
|
||||
fillType: ""
|
||||
});
|
||||
finishThumbnails();
|
||||
// finishThumbnails(); //disabled for performance and testing reasons
|
||||
})
|
||||
torrent.on('noPeers', function () {
|
||||
halfmoon.initStickyAlert({
|
||||
|
|
@ -130,6 +130,7 @@ function serveFile(file, req) {
|
|||
|
||||
res.headers['Cache-Control'] = 'no-store'
|
||||
res.body = req.method === 'HEAD' ? '' : 'stream'
|
||||
console.log('set parser', range)
|
||||
|
||||
parser = new MatroskaSubtitles({ prevInstance: parser, offset: range.start })
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue