mirror of
https://github.com/NoCrypt/migu.git
synced 2026-03-29 13:59:09 +00:00
fix: migrate to jassub
our chromium ver doesn't support local font access yet, but the support is there once we update
This commit is contained in:
parent
ab7341e0c7
commit
6d8fdee0b3
9 changed files with 19 additions and 11572 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Miru",
|
||||
"version": "2.7.1",
|
||||
"version": "2.7.2",
|
||||
"author": "ThaUnknown_ <ThaUnknown@users.noreply.github.com>",
|
||||
"main": "src/index.js",
|
||||
"homepage": "https://github.com/ThaUnknown/miru#readme",
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
|
||||
"builtin-modules": "^3.2.0",
|
||||
"concurrently": "^7.0.0",
|
||||
"electron": "^18.2.1",
|
||||
"electron": "^19.0.7",
|
||||
"electron-builder": "^22.14.13",
|
||||
"electron-notarize": "^1.1.1",
|
||||
"svelte": "^3.47.0",
|
||||
|
|
@ -118,6 +118,7 @@
|
|||
"discord-rpc": "^4.0.1",
|
||||
"electron-log": "^4.4.6",
|
||||
"electron-updater": "^4.6.5",
|
||||
"jassub": "^1.1.4",
|
||||
"matroska-subtitles": "github:ThaUnknown/matroska-subtitles#patch",
|
||||
"mime": "^3.0.0",
|
||||
"pump": "^3.0.0",
|
||||
|
|
|
|||
|
|
@ -70,9 +70,8 @@ function createWindow () {
|
|||
frame: false,
|
||||
backgroundColor: '#191c20',
|
||||
autoHideMenuBar: true,
|
||||
experimentalFeatures: true,
|
||||
webPreferences: {
|
||||
enableBlinkFeatures: 'AudioVideoTracks',
|
||||
enableBlinkFeatures: 'FontAccess, AudioVideoTracks',
|
||||
backgroundThrottling: false,
|
||||
nodeIntegrationInWorker: true,
|
||||
preload: path.join(__dirname, '/preload.js')
|
||||
|
|
|
|||
BIN
src/renderer/public/jassub-worker.wasm
Normal file
BIN
src/renderer/public/jassub-worker.wasm
Normal file
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
|
|
@ -1,4 +1,5 @@
|
|||
import SubtitlesOctopus from './subtitles-octopus.js'
|
||||
import JASSUB from 'jassub'
|
||||
import JASSUBWorker from 'jassub/dist/jassub-worker.js?url'
|
||||
import { toTS, videoRx, subRx } from './util.js'
|
||||
|
||||
import { client } from '@/modules/torrent.js'
|
||||
|
|
@ -21,7 +22,7 @@ export default class Subtitles {
|
|||
this._stylesMap = {
|
||||
Default: 0
|
||||
}
|
||||
this.fonts = ['Roboto.ttf']
|
||||
this.fonts = ['/Roboto.ttf']
|
||||
this.renderer = null
|
||||
this.parsed = false
|
||||
this.stream = null
|
||||
|
|
@ -33,29 +34,20 @@ export default class Subtitles {
|
|||
this.timeout = null
|
||||
client.on('tracks', this.handleTracks.bind(this))
|
||||
client.on('subtitle', this.handleSubtitle.bind(this))
|
||||
client.on('fonts', this.handleFonts.bind(this))
|
||||
client.on('file', this.handleFile.bind(this))
|
||||
}
|
||||
|
||||
handleFile ({ detail }) {
|
||||
if (this.selected) {
|
||||
this.fonts.push(URL.createObjectURL(new Blob([detail.data], { type: detail.mimetype })))
|
||||
}
|
||||
}
|
||||
|
||||
handleFonts () {
|
||||
if (this.selected) {
|
||||
this.renderer?.destroy()
|
||||
this.renderer = null
|
||||
this.initSubtitleRenderer()
|
||||
// re-create renderer with fonts
|
||||
const uint8 = new Uint8Array(detail.data)
|
||||
this.fonts.push(uint8)
|
||||
this.renderer.addFont(uint8)
|
||||
}
|
||||
}
|
||||
|
||||
handleSubtitle ({ detail }) {
|
||||
const { subtitle, trackNumber } = detail
|
||||
if (this.selected) {
|
||||
if (!this.renderer) this.initSubtitleRenderer()
|
||||
const string = JSON.stringify(subtitle)
|
||||
if (!this._tracksString[trackNumber].has(string)) {
|
||||
this._tracksString[trackNumber].add(string)
|
||||
|
|
@ -87,6 +79,7 @@ export default class Subtitles {
|
|||
this.onHeader()
|
||||
}
|
||||
}
|
||||
this.initSubtitleRenderer()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +120,7 @@ export default class Subtitles {
|
|||
}
|
||||
if (!this.current) {
|
||||
this.current = 0
|
||||
if (!this.renderer) this.initSubtitleRenderer()
|
||||
this.initSubtitleRenderer()
|
||||
this.selectCaptions(this.current)
|
||||
this.onHeader()
|
||||
}
|
||||
|
|
@ -136,12 +129,16 @@ export default class Subtitles {
|
|||
|
||||
initSubtitleRenderer () {
|
||||
if (!this.renderer) {
|
||||
this.renderer = new SubtitlesOctopus({
|
||||
this.renderer = new JASSUB({
|
||||
video: this.video,
|
||||
blendMode: 'js',
|
||||
subContent: this.headers[this.current].header.slice(0, -1),
|
||||
fonts: this.fonts,
|
||||
workerUrl: 'lib/subtitles-octopus-worker.js'
|
||||
fallbackFont: 'roboto medium',
|
||||
availableFonts: {
|
||||
'roboto medium': '/Roboto.ttf'
|
||||
},
|
||||
useLocalFonts: true,
|
||||
workerUrl: JASSUBWorker
|
||||
})
|
||||
this.selectCaptions(this.current)
|
||||
}
|
||||
|
|
@ -264,7 +261,6 @@ export default class Subtitles {
|
|||
destroy () {
|
||||
client.removeListener('tracks', this.handleTracks.bind(this))
|
||||
client.removeListener('subtitle', this.handleSubtitle.bind(this))
|
||||
client.removeListener('fonts', this.handleFonts.bind(this))
|
||||
client.removeListener('file', this.handleFile.bind(this))
|
||||
this.stream?.destroy()
|
||||
this.parser?.destroy()
|
||||
|
|
@ -275,6 +271,5 @@ export default class Subtitles {
|
|||
this.tracks = null
|
||||
this.headers = null
|
||||
this.onHeader()
|
||||
this.fonts?.forEach(file => URL.revokeObjectURL(file))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,7 +176,6 @@ class TorrentClient extends WebTorrent {
|
|||
stream.once('subtitle', () => {
|
||||
fileStreamStream.destroy()
|
||||
stream.destroy()
|
||||
this.dispatch('fonts')
|
||||
})
|
||||
const fileStreamStream = file.createReadStream()
|
||||
fileStreamStream.pipe(stream)
|
||||
|
|
|
|||
Loading…
Reference in a new issue