Skip to content

Commit af644d7

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

File tree

12 files changed

+76
-170
lines changed

12 files changed

+76
-170
lines changed

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",
@@ -92,9 +91,9 @@
9291
"highlight.js": "^11.11.1",
9392
"hls.js": "^1.6.15",
9493
"ini": "^6.0.0",
94+
"jassub": "^2.4.1",
9595
"just-once": "^2.2.0",
9696
"katex": "^0.16.28",
97-
"libass-wasm": "^4.1.0",
9897
"libheif-js": "^1.19.8",
9998
"lightgallery": "^2.9.0",
10099
"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
@@ -47,26 +47,12 @@ export const useCDN = () => {
4747
: `${static_path}/libheif`
4848
}
4949

50-
const libAssPath = () => {
51-
return import.meta.env.VITE_LITE === "true"
52-
? npm(packageJson.name, packageJson.version, "dist/static/libass-wasm")
53-
: `${static_path}/libass-wasm`
54-
}
55-
56-
const fontsPath = () => {
57-
return import.meta.env.VITE_LITE === "true"
58-
? npm(packageJson.name, packageJson.version, "dist/static/fonts")
59-
: `${static_path}/fonts`
60-
}
61-
6250
return {
6351
npm,
6452
monacoPath,
6553
katexCSSPath,
6654
mermaidJSPath,
6755
ruffleJSPath,
6856
libHeifPath,
69-
libAssPath,
70-
fontsPath,
7157
}
7258
}

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)