Skip to content

Commit f74ca97

Browse files
committed
refactor(video): migrate to jassub for subtitle handling
Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent b5ffe10 commit f74ca97

12 files changed

Lines changed: 76 additions & 170 deletions

File tree

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"license": "MIT",
3838
"devDependencies": {
3939
"@crowdin/cli": "^4.14.1",
40-
"@hrgui/libass-wasm-ts": "^1.0.3",
4140
"@types/bencode": "^2.0.4",
4241
"@types/crypto-js": "^4.2.2",
4342
"@types/mark.js": "^8.11.12",
@@ -91,9 +90,9 @@
9190
"highlight.js": "^11.11.1",
9291
"hls.js": "^1.6.15",
9392
"ini": "^6.0.0",
93+
"jassub": "^2.4.1",
9494
"just-once": "^2.2.0",
9595
"katex": "^0.16.44",
96-
"libass-wasm": "^4.1.0",
9796
"libheif-js": "^1.19.8",
9897
"lightgallery": "^2.9.0",
9998
"mark.js": "^8.11.1",

pnpm-lock.yaml

Lines changed: 31 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
-815 KB
Binary file not shown.

src/components/artplayer-plugin-ass/index.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/components/artplayer-plugin-ass/index.js

Lines changed: 0 additions & 110 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type Artplayer from "artplayer"
2+
import type { JASSUBOptions } from "jassub"
3+
import JASSUB from "jassub"
4+
// import modernWasmUrl from "jassub/dist/wasm/jassub-worker-modern.wasm?url"
5+
// import wasmUrl from "jassub/dist/wasm/jassub-worker.wasm?url"
6+
7+
type SubtitleSourceOption =
8+
| { subUrl: string; subContent?: string }
9+
| { subUrl?: string; subContent: string }
10+
11+
type ArtplayerPluginAssOptions = Omit<
12+
JASSUBOptions,
13+
"video" | "canvas" | "subUrl" | "subContent"
14+
> &
15+
SubtitleSourceOption
16+
17+
export default function artplayerPluginAss(option: ArtplayerPluginAssOptions) {
18+
return (art: Artplayer) => {
19+
const instance = new JASSUB({
20+
video: art.video,
21+
debug: import.meta.env.DEV,
22+
...option,
23+
} satisfies JASSUBOptions)
24+
25+
instance._canvasParent?.style &&
26+
(instance._canvasParent.style.zIndex = "20")
27+
28+
art.on("destroy", () => {
29+
instance.destroy()
30+
})
31+
32+
return {
33+
name: "artplayerPluginAss",
34+
instance,
35+
}
36+
}
37+
}

src/hooks/useCDN.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,11 @@ export const useCDN = () => {
3737
: `${static_path}/libheif`
3838
}
3939

40-
const libAssPath = () => {
41-
return import.meta.env.VITE_LITE === "true"
42-
? npm(packageJson.name, packageJson.version, "dist/static/libass-wasm")
43-
: `${static_path}/libass-wasm`
44-
}
45-
46-
const fontsPath = () => {
47-
return import.meta.env.VITE_LITE === "true"
48-
? npm(packageJson.name, packageJson.version, "dist/static/fonts")
49-
: `${static_path}/fonts`
50-
}
51-
5240
return {
5341
npm,
5442
monacoPath,
5543
katexCSSPath,
5644
mermaidJSPath,
5745
libHeifPath,
58-
libAssPath,
59-
fontsPath,
6046
}
6147
}

src/pages/home/previews/aliyun_video.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { getMainColor, getSettingBool, objStore, password } from "~/store"
55
import { ObjType, PResp } from "~/types"
66
import { ext, handleResp, notify, r, pathDir, pathJoin } from "~/utils"
77
import Artplayer from "artplayer"
8-
import { type Option } from "artplayer/types/option"
9-
import { type Setting } from "artplayer/types/setting"
10-
import { type Events } from "artplayer/types/events"
8+
import { type Option } from "artplayer"
9+
import { type Setting } from "artplayer"
10+
import { type Events } from "artplayer"
1111
import artplayerPluginDanmuku from "artplayer-plugin-danmuku"
1212
import { type Option as DanmukuOption } from "artplayer-plugin-danmuku"
1313
import artplayerPluginAss from "~/components/artplayer-plugin-ass"
@@ -180,7 +180,6 @@ const Preview = () => {
180180
isEnhanceAssMode = true
181181
option.plugins?.push(
182182
artplayerPluginAss({
183-
// debug: true,
184183
subUrl: proxyLink(defaultSubtitle, true),
185184
}),
186185
)

src/pages/home/previews/video.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { getMainColor, getSettingBool, objStore } from "~/store"
55
import { ObjType } from "~/types"
66
import { ext, pathDir, pathJoin } from "~/utils"
77
import Artplayer from "artplayer"
8-
import { type Option } from "artplayer/types/option"
9-
import { type Setting } from "artplayer/types/setting"
10-
import { type Events } from "artplayer/types/events"
8+
import { type Option } from "artplayer"
9+
import { type Setting } from "artplayer"
10+
import { type Events } from "artplayer"
1111
import artplayerPluginDanmuku from "artplayer-plugin-danmuku"
1212
import { type Option as DanmukuOption } from "artplayer-plugin-danmuku"
1313
import artplayerPluginAss from "~/components/artplayer-plugin-ass"
@@ -170,7 +170,6 @@ const Preview = () => {
170170
isEnhanceAssMode = true
171171
option.plugins?.push(
172172
artplayerPluginAss({
173-
// debug: true,
174173
subUrl: proxyLink(defaultSubtitle, true),
175174
}),
176175
)

0 commit comments

Comments
 (0)