mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 23:51:20 -08:00
test(multiple-subtitles): [PKG-MULTI-SUB-01] freeze contracts and verify parser provenance
This commit is contained in:
1 parent
0c5bb2bd7a
commit
5a0d94cb89
33 files changed
+2375
-22
No files matched your search
@@ -0,0 +1,153 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"task": "PKG-MULTI-SUB-01",
|
||||
"status": "done",
|
||||
"parentCommit": "0c5bb2bd7ac6d76b0b5f42dcdfb71ccdb31fb8d5",
|
||||
"checks": [
|
||||
{
|
||||
"command": "yarn test:multiple-subtitles",
|
||||
"tests": 53,
|
||||
"pass": 53,
|
||||
"file": "refactor/.cache/multiple-subtitles01-suite.log",
|
||||
"sha256": "36af923592894ee482aacf7af6292ddf3bafac1c571603359b86ab4186f2df5d"
|
||||
},
|
||||
{
|
||||
"command": "pinned upstream parser adaptation and complete license",
|
||||
"result": {
|
||||
"provenance": {
|
||||
"revision": "380cfcce34ba8b472d3a31474874eb72a0e5f460",
|
||||
"packageVersionAtRevision": "2.1.2",
|
||||
"scope": "Pinned comparison revision, not proof of historical acquisition commit. After removing IIFE/global exportify and adding named ESM exports, normalized executable content matches local parser.",
|
||||
"sources": [
|
||||
{
|
||||
"file": "refactor/baselines/multiple-subtitles-vendor/parser.txt",
|
||||
"upstream": "https://raw.githubusercontent.com/w3c/webvtt.js/380cfcce34ba8b472d3a31474874eb72a0e5f460/parser.js",
|
||||
"sha256": "35a112e585b7cb1b4fd30350b0e8c8f6d1efa2670a6008c4a6038e07c9f8d727"
|
||||
},
|
||||
{
|
||||
"file": "refactor/baselines/multiple-subtitles-vendor/license.txt",
|
||||
"upstream": "https://raw.githubusercontent.com/w3c/webvtt.js/380cfcce34ba8b472d3a31474874eb72a0e5f460/LICENSE.md",
|
||||
"sha256": "6cc655a5df52fefac69058311c090f4e70b7c37b8f6488f9498420a930b8275d"
|
||||
},
|
||||
{
|
||||
"file": "refactor/baselines/multiple-subtitles-vendor/package.json.txt",
|
||||
"upstream": "https://raw.githubusercontent.com/w3c/webvtt.js/380cfcce34ba8b472d3a31474874eb72a0e5f460/package.json",
|
||||
"sha256": "d0102b9276839f1136ecafd9527102a28b44643e8ff403b3ddb1e51c04777a7b"
|
||||
}
|
||||
]
|
||||
},
|
||||
"normalizedSha256": "e71dc5073db409dcb8eef66a0d6bfe6c8d96fa7d157ff51a68decf6f05a7c80f",
|
||||
"localSha256LF": "ba582074d57fa2d72880e6e4253fe14646787916b2b68e2a1e748e685cf96ab1",
|
||||
"noticesSha256LF": "50755f38458d41151c7f0b1675c744aa365f0510dc11f53832691ef5c14ce6b6"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "yarn build artplayer-plugin-multiple-subtitles",
|
||||
"file": "refactor/.cache/multiple-subtitles01-build.log",
|
||||
"sha256": "81b37121fe29916391a899d047b30ed6ad73faadfe2327474f235c48321cf5b6",
|
||||
"artifacts": {
|
||||
"packages/artplayer-plugin-multiple-subtitles/dist/artplayer-plugin-multiple-subtitles.js": "fa21ea1ac923cd4d9085828631b9f89988490d0302d3a5436059317a6ebf96d8",
|
||||
"packages/artplayer-plugin-multiple-subtitles/dist/artplayer-plugin-multiple-subtitles.legacy.js": "bd686716cfe2d7b23d1739ae59bc1934cab2d7c346e36f2690f79a439144a8e4",
|
||||
"packages/artplayer-plugin-multiple-subtitles/dist/artplayer-plugin-multiple-subtitles.mjs": "a4a04affca97f673b881b20d27641516d854dee734d445c41c4a906777802cd2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "actual yarn pack and standalone headers",
|
||||
"archive": "refactor/.cache/multiple-subtitles01-package-final.tgz",
|
||||
"sha256": "6e83785d8348f021ba5df6e3a1f6828f238b519bd7985e4c1b1c887d6c491e20",
|
||||
"manifest": {
|
||||
"name": "artplayer-plugin-multiple-subtitles",
|
||||
"version": "1.2.0",
|
||||
"description": "multiple subtitles plugin for ArtPlayer",
|
||||
"author": "Harvey Zhao <laozhaochaguan@gmail.com>",
|
||||
"license": "MIT",
|
||||
"homepage": "https://artplayer.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zhw2590582/ArtPlayer.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/zhw2590582/ArtPlayer/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"html5",
|
||||
"video",
|
||||
"player"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./types/artplayer-plugin-multiple-subtitles.d.ts",
|
||||
"import": "./dist/artplayer-plugin-multiple-subtitles.mjs",
|
||||
"require": "./dist/artplayer-plugin-multiple-subtitles.js"
|
||||
},
|
||||
"./legacy": {
|
||||
"types": "./types/artplayer-plugin-multiple-subtitles.d.ts",
|
||||
"import": "./dist/artplayer-plugin-multiple-subtitles.legacy.js",
|
||||
"require": "./dist/artplayer-plugin-multiple-subtitles.legacy.js"
|
||||
}
|
||||
},
|
||||
"main": "./dist/artplayer-plugin-multiple-subtitles.js",
|
||||
"module": "./dist/artplayer-plugin-multiple-subtitles.mjs",
|
||||
"types": "./types/artplayer-plugin-multiple-subtitles.d.ts",
|
||||
"legacy": "./dist/artplayer-plugin-multiple-subtitles.legacy.js",
|
||||
"browserslist": "last 1 Chrome version"
|
||||
},
|
||||
"members": {
|
||||
"package/ARCHITECTURE.md": "6df20ecf8a537aad42ec44a471b79d612e93e9dc1068ae475d0db78dc6f8d285",
|
||||
"package/README.md": "6b969577a9a842aded237d75de7b502e5a589b93ba6aca1f51d6d64ff8cc5c47",
|
||||
"package/THIRD_PARTY_NOTICES": "50755f38458d41151c7f0b1675c744aa365f0510dc11f53832691ef5c14ce6b6",
|
||||
"package/dist/artplayer-plugin-multiple-subtitles.js": "fa21ea1ac923cd4d9085828631b9f89988490d0302d3a5436059317a6ebf96d8",
|
||||
"package/dist/artplayer-plugin-multiple-subtitles.legacy.js": "bd686716cfe2d7b23d1739ae59bc1934cab2d7c346e36f2690f79a439144a8e4",
|
||||
"package/dist/artplayer-plugin-multiple-subtitles.mjs": "a4a04affca97f673b881b20d27641516d854dee734d445c41c4a906777802cd2",
|
||||
"package/package.json": "77c93bc94154db46bdc2b2a3d02a03421ea0a49af54728bead91896dfae1092a",
|
||||
"package/types/artplayer-plugin-multiple-subtitles.d.ts": "ab5dae1d0bdfcf2515cb842b1d465edf21dd195fe2fc5b0cfe351a8c06eb965c"
|
||||
},
|
||||
"scope": "Actual tarball members and complete notices verified; not an installed consumer or native browser claim."
|
||||
},
|
||||
{
|
||||
"command": "candidate normal behavior source",
|
||||
"tests": 5,
|
||||
"pass": 5,
|
||||
"file": "refactor/.cache/multiple-subtitles01-candidate-source.log",
|
||||
"sha256": "5a9b041f56b47cc464cca0dbd6157a0c20d760488371343fac6ade25123f3aad"
|
||||
},
|
||||
{
|
||||
"command": "candidate normal behavior main",
|
||||
"tests": 5,
|
||||
"pass": 5,
|
||||
"file": "refactor/.cache/multiple-subtitles01-candidate-main.log",
|
||||
"sha256": "bd4f784ac1c78fefd5f70c94198d4f6eeb0c5afb022fcf4f6be9b9400f3acc48"
|
||||
},
|
||||
{
|
||||
"command": "candidate normal behavior legacy",
|
||||
"tests": 5,
|
||||
"pass": 5,
|
||||
"file": "refactor/.cache/multiple-subtitles01-candidate-legacy.log",
|
||||
"sha256": "50ba47e12a7d5f94223cb9797115cf3ddd593fdca9a8b1f828fd132e66864f61"
|
||||
},
|
||||
{
|
||||
"command": "yarn ci:check",
|
||||
"tests": {
|
||||
"unit": 1775,
|
||||
"engineering": 14,
|
||||
"baseline": 334,
|
||||
"total": 2123
|
||||
},
|
||||
"strictProductionTypeScriptFiles": 346,
|
||||
"file": "refactor/.cache/multiple-subtitles01-ci-final.log",
|
||||
"sha256": "b4e02860bdc35bb25db4fd1e4ab36e499346a56d5eaa1abf5071fa8c19c45d06",
|
||||
"registration": "Both new root test files are registered in test:unit; the contract suite is included by test:baseline."
|
||||
},
|
||||
{
|
||||
"command": "explicit lint including new helpers and refactor scripts",
|
||||
"file": "refactor/.cache/multiple-subtitles01-lint-verified.log",
|
||||
"sha256": "ee9dad77469369fbd40e8269ac7cb666ee3790e877977aa5e27e4cd60f1530cb"
|
||||
}
|
||||
],
|
||||
"publicSourceAndTypes": {
|
||||
"packages/artplayer-plugin-multiple-subtitles/src/index.js": "02d7019e92bed7817d815f04df80605ae0bd94f03e2b8c52022b5f622ba2e2ba",
|
||||
"packages/artplayer-plugin-multiple-subtitles/src/parser.js": "ba582074d57fa2d72880e6e4253fe14646787916b2b68e2a1e748e685cf96ab1",
|
||||
"packages/artplayer-plugin-multiple-subtitles/types/artplayer-plugin-multiple-subtitles.d.ts": "6fc3107127b93b5107d679183dadd5740d4b7d5ea2cf2e51d877d576957e1386"
|
||||
},
|
||||
"remaining": "Public type migration, error/lifecycle reproduction, native core/device combinations and complete distribution/demo consumers belong to tasks 02-06. Git core association is not support evidence. The pinned parser revision is a comparison source, not a proven historical acquisition commit."
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
# Multiple-subtitles 历史兼容契约
|
||||
|
||||
任务 PKG-MULTI-SUB-01。输入固定在 Git `0c5bb2bd7ac6d76b0b5f42dcdfb71ccdb31fb8d5`,
|
||||
包括源码、声明、README、三个产物和 multiple.subtitles demo,共 9 份输入。
|
||||
真实 npm 1.0.0、1.1.0、1.2.0 共 20 个成员逐项保存 SHA-256,归档验证 registry SHA-512。
|
||||
下载来源、版本和完整成员见 [发布记录](multiple-subtitles-release.json)。三个历史 gitHead
|
||||
关联的核心分别为 5.1.2、5.1.7、5.3.1;这是历史关联,不是全部已支持核心范围的证明。
|
||||
|
||||
| 维度 | 冻结事实 |
|
||||
| --- | --- |
|
||||
| 工厂 | artplayerPluginMultipleSubtitles({ subtitles = [] });整个参数不能省略,JS 可传 {} |
|
||||
| 加载 | 异步注册;并行 fetch 全部 URL,arrayBuffer 后按 encoding 或 utf-8 解码 |
|
||||
| 转换 | type 优先于 getExt(url);vtt 原文,srt/ass 使用核心转换器,其他扩展名产生空字幕文本 |
|
||||
| 解析 | WebVTTParser metadata 模式;parser 各轨排序,不代表合并后按全局时间排序 |
|
||||
| 1.0.0 合并 | 按 cue 数组下标把后续轨文字拼入首轨对应 cue,保留首轨时间 |
|
||||
| 1.1.0 起合并 | 依次连接各轨 cue 数组,保留每轨自己的 cue 时间 |
|
||||
| 样式 | 每轨顶层文本写入 art-subtitle-{name} div,reset 不重复套 div |
|
||||
| 返回值 | Promise 最终结果有 name: multipleSubtitles、tracks(names = [])、reset() |
|
||||
| 切换 | 按 name 查找并按调用者顺序输出;tracks() 或 [] 清空;reset 恢复初始轨顺序;不重新 fetch |
|
||||
| 更新 | setTracks 返回 undefined;每次先 revoke 旧 URL,再创建 text/vtt Blob URL,调用 subtitle.init |
|
||||
| 配置 | 永久把 art.option.subtitle.escape 改为 false;init 继承调用时 subtitle 配置,覆盖 url/type/onVttLoad |
|
||||
| onParser | 三个版本都在声明中出现,但已执行的真实工厂没有调用它 |
|
||||
| 类型 | subtitles 数组在声明中必需、其条目的 url/name/encoding 可选;声明没有 Promise、tracks/reset |
|
||||
| 旧导出 | 1.0.0/1.1.0 实际 CommonJS 为含 default 的对象,声明却使用 export=;都有脚本全局 |
|
||||
| 新导出 | 1.2.0 实际 CJS 直接函数,ESM default-only,声明使用默认导出;新增 exports/legacy 路径 |
|
||||
|
||||
## Parser 来源与保留范围
|
||||
|
||||
固定比较源为 [w3c/webvtt.js 的 380cfcce 修订](https://github.com/w3c/webvtt.js/tree/380cfcce34ba8b472d3a31474874eb72a0e5f460),
|
||||
该修订 package.json 的 version 为 2.1.2,不能把它误称为已验证的 npm 2.1.2 归档。
|
||||
原始文件和指纹在 [来源目录](multiple-subtitles-vendor/sources.json)。当前本地 parser 只
|
||||
改变 IIFE/global 导出为 ESM 导出、增加 eslint 说明并格式化;剥离这组明确适配后,
|
||||
esbuild 规范化的完整执行代码相同。两个旧 npm 包保留 IIFE/exportify,经过同样边界比较
|
||||
后也一致。历史真正下载时使用的 commit 没有直接证据,此修订是固定比较源。
|
||||
|
||||
原始 CC0 头保留,完整 dedication 放入包内 THIRD_PARTY_NOTICES,由现有构建脚本放入
|
||||
main/legacy/mjs 独立文件头。parser/serializer 的 metadata、实体、样式、cue 0、排序和
|
||||
无效 timing 输入与固定上游对照。此项不声称所有 WebVTT 浏览器渲染或设备已经验收。
|
||||
|
||||
## 复现与后续任务
|
||||
|
||||
`yarn test:multiple-subtitles` 验证 53 项:9 份实现的 45 个正常行为、6 个发布契约、
|
||||
2 个 vendor/分发测试。源实现与实际 main/legacy 候选还分别执行 5 项正常调用回归。
|
||||
converter stub 只证明调用/类型选择,不等于验证实际 SRT/ASS 解析正确性。
|
||||
实际 ESM 验证入口及空轨注册,不能当作真实视频字幕显示验证。
|
||||
|
||||
02 继续复现错误、编码、重叠/空轨、失败和切换;03 负责拆分及请求/URL生命周期;
|
||||
04 负责公开类型差异,05 负责原生核心/字幕/设备组合,06 负责安装消费者和实际 demo。
|
||||
源码目前缺少 fetch 取消及 destroy 的最后 URL 释放,仅从源码观察,未计作已修复。
|
||||
未知名字、轨道长度不等、HTML 样式节点、宿主失败等还需 02 系统复现。
|
||||
@@ -0,0 +1,199 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"task": "PKG-MULTI-SUB-01",
|
||||
"capturedAt": "2026-09-13T01:46:21.521Z",
|
||||
"sourceCommit": "0c5bb2bd7ac6d76b0b5f42dcdfb71ccdb31fb8d5",
|
||||
"registryObservation": {
|
||||
"url": "https://registry.npmjs.org/artplayer-plugin-multiple-subtitles",
|
||||
"status": 200,
|
||||
"sha256": "42f87af15439205eb6d3c114039b33a148dd7340d9be5ea859da0bacc02faa26",
|
||||
"versions": [
|
||||
"1.0.0",
|
||||
"1.1.0",
|
||||
"1.2.0"
|
||||
],
|
||||
"latest": "1.2.0",
|
||||
"workspaceVersion": "1.2.0"
|
||||
},
|
||||
"release": {
|
||||
"name": "artplayer-plugin-multiple-subtitles",
|
||||
"version": "1.2.0",
|
||||
"metadataUrl": "https://registry.npmjs.org/artplayer-plugin-multiple-subtitles/1.2.0",
|
||||
"tarball": "https://registry.npmjs.org/artplayer-plugin-multiple-subtitles/-/artplayer-plugin-multiple-subtitles-1.2.0.tgz",
|
||||
"integrity": "sha512-3mzoHkgKx3KVdxKQBwLkjetPF6WjJtro5uQNdse8FqUeiV0afbywLnP6H8lcDN/Fwgp2VlBknrs2+COiyFdV8g==",
|
||||
"sha256": "a013fbe0772bf560d177449fc80e848c41f16ae2f72ace86f8fb0d5b1000a54e",
|
||||
"archiveBytes": 12209,
|
||||
"publishedAt": "2026-03-12T14:20:38.214Z",
|
||||
"registryGitHead": "daf133b22630b4a0eecfa3336bbddab0e9119d96",
|
||||
"files": {
|
||||
"package/README.md": "c811dabe9b0baa8739497b26ec287ad13beda59f996dec8e96f8d9244b612e86",
|
||||
"package/dist/artplayer-plugin-multiple-subtitles.js": "c1cb0b511da88347165cc855185de9450a44835bb34bb802281ccdb854ef603c",
|
||||
"package/dist/artplayer-plugin-multiple-subtitles.legacy.js": "0b17644827e5b199afe8293093c44bfda571821014ff5b087c7c918c630dcc18",
|
||||
"package/dist/artplayer-plugin-multiple-subtitles.mjs": "e867c64303299a53d2bf6af62cc1e59044f1c7355aeb55e45b15ab2703448cb0",
|
||||
"package/package.json": "3f8b631444e51da259f86d6cc83095df788eb3c41843724ad2a35d8b896b985f",
|
||||
"package/types/artplayer-plugin-multiple-subtitles.d.ts": "6fc3107127b93b5107d679183dadd5740d4b7d5ea2cf2e51d877d576957e1386"
|
||||
},
|
||||
"manifest": {
|
||||
"name": "artplayer-plugin-multiple-subtitles",
|
||||
"version": "1.2.0",
|
||||
"description": "multiple subtitles plugin for ArtPlayer",
|
||||
"author": "Harvey Zhao <laozhaochaguan@gmail.com>",
|
||||
"license": "MIT",
|
||||
"homepage": "https://artplayer.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zhw2590582/ArtPlayer.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/zhw2590582/ArtPlayer/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"html5",
|
||||
"video",
|
||||
"player"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./types/artplayer-plugin-multiple-subtitles.d.ts",
|
||||
"import": "./dist/artplayer-plugin-multiple-subtitles.mjs",
|
||||
"require": "./dist/artplayer-plugin-multiple-subtitles.js"
|
||||
},
|
||||
"./legacy": {
|
||||
"types": "./types/artplayer-plugin-multiple-subtitles.d.ts",
|
||||
"import": "./dist/artplayer-plugin-multiple-subtitles.legacy.js",
|
||||
"require": "./dist/artplayer-plugin-multiple-subtitles.legacy.js"
|
||||
}
|
||||
},
|
||||
"main": "./dist/artplayer-plugin-multiple-subtitles.js",
|
||||
"module": "./dist/artplayer-plugin-multiple-subtitles.mjs",
|
||||
"types": "./types/artplayer-plugin-multiple-subtitles.d.ts",
|
||||
"legacy": "./dist/artplayer-plugin-multiple-subtitles.legacy.js",
|
||||
"browserslist": "last 1 Chrome version"
|
||||
},
|
||||
"missingEntrypoints": {},
|
||||
"historicalCore": {
|
||||
"version": "5.3.1",
|
||||
"commit": "daf133b22630b4a0eecfa3336bbddab0e9119d96",
|
||||
"file": "packages/artplayer/package.json",
|
||||
"sha256LF": "862f3697876fe915dd0ada178da766ce823aae7563ed30b3e5b11b811202929c",
|
||||
"scope": "Git association only; no npm core integration result is implied."
|
||||
}
|
||||
},
|
||||
"previous": [
|
||||
{
|
||||
"name": "artplayer-plugin-multiple-subtitles",
|
||||
"version": "1.1.0",
|
||||
"metadataUrl": "https://registry.npmjs.org/artplayer-plugin-multiple-subtitles/1.1.0",
|
||||
"tarball": "https://registry.npmjs.org/artplayer-plugin-multiple-subtitles/-/artplayer-plugin-multiple-subtitles-1.1.0.tgz",
|
||||
"integrity": "sha512-gXbCTK09LKfxs4rXv5lkJiiEJj5NDBcAoCD6DMzFLTtw88nZs81Al5HMhvnNfm5lqcmF77LFhk8YYDChSGcWoA==",
|
||||
"sha256": "b5e8cfa9671496b08a6f1377bace4ce557c865335dc2f746156707c03c8d9d16",
|
||||
"archiveBytes": 22044,
|
||||
"publishedAt": "2024-10-19T06:09:16.790Z",
|
||||
"registryGitHead": "9221d42964700e6a3190943d288a6e6822596790",
|
||||
"files": {
|
||||
"package/README.md": "26b4d8914fd19976a1c5e2999a4146cb76a693f32dd874de4d8322b0da52829a",
|
||||
"package/dist/artplayer-plugin-multiple-subtitles.js": "df40c0728decb7e39779d0f22cad0a32d5586a66bfdb19bcfecffbecca083a83",
|
||||
"package/dist/artplayer-plugin-multiple-subtitles.legacy.js": "580514627926d94e8e085bc662fed693951250069bb8db6513709753bde33b5a",
|
||||
"package/package.json": "6b044fa3bb2674ab94a930d8df4695dbb484f8b47cfc6b0cc193e820a2b0afd3",
|
||||
"package/src/index.js": "b79aa2ef836902b7b99d80d1789cb3c5c400a8e3b50c01f29114c52be31e3a07",
|
||||
"package/src/parser.js": "ce10bee2c21c59fd32230b253581738b59f103fcd2b350b74a245d630642e777",
|
||||
"package/types/artplayer-plugin-multiple-subtitles.d.ts": "ddd581ac12fc6285f583f2f97c061ef013e6dc0fccab043ca450a9639bb0ea47"
|
||||
},
|
||||
"manifest": {
|
||||
"license": "MIT",
|
||||
"version": "1.1.0",
|
||||
"name": "artplayer-plugin-multiple-subtitles",
|
||||
"types": "types/artplayer-plugin-multiple-subtitles.d.ts",
|
||||
"description": "multiple subtitles plugin for ArtPlayer",
|
||||
"main": "dist/artplayer-plugin-multiple-subtitles.js",
|
||||
"legacy": "dist/artplayer-plugin-multiple-subtitles.legacy.js",
|
||||
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
|
||||
"browserslist": "last 1 Chrome version",
|
||||
"homepage": "https://artplayer.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zhw2590582/ArtPlayer.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/zhw2590582/ArtPlayer/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"html5",
|
||||
"video",
|
||||
"player"
|
||||
]
|
||||
},
|
||||
"missingEntrypoints": {},
|
||||
"historicalCore": {
|
||||
"version": "5.1.7",
|
||||
"commit": "9221d42964700e6a3190943d288a6e6822596790",
|
||||
"file": "packages/artplayer/package.json",
|
||||
"sha256LF": "8bd532103099c367fb2c289e0d410f144fdeb00b1b62cf850762a24b61e63c8a",
|
||||
"scope": "Git association only; no npm core integration result is implied."
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "artplayer-plugin-multiple-subtitles",
|
||||
"version": "1.0.0",
|
||||
"metadataUrl": "https://registry.npmjs.org/artplayer-plugin-multiple-subtitles/1.0.0",
|
||||
"tarball": "https://registry.npmjs.org/artplayer-plugin-multiple-subtitles/-/artplayer-plugin-multiple-subtitles-1.0.0.tgz",
|
||||
"integrity": "sha512-BF3nQDkXtFXt+TnGZSXM711Sc9b1lIUQEzMjp1YGnI8p+CFbiDW7EJDmRNy3psZXqRoUXVmpZ86FtZjqra8UPw==",
|
||||
"sha256": "9b584f27287dbda1722315c07d05e1d7391453130b8fd9f952669e809e662ef5",
|
||||
"archiveBytes": 22428,
|
||||
"publishedAt": "2024-05-27T03:33:19.759Z",
|
||||
"registryGitHead": "43309b72cff84344bd61f4de505aee0e10a83e6b",
|
||||
"files": {
|
||||
"package/README.md": "734d156e18a2b577d0ca9e85f5599cbb221ffc694195d79a9ccbe4f715224d9d",
|
||||
"package/dist/artplayer-plugin-multiple-subtitles.js": "89ba01b678b5ca5e5277482718f55f496317ca9416d0d7b3d46b5c306f399c42",
|
||||
"package/dist/artplayer-plugin-multiple-subtitles.legacy.js": "1ed7790a910dec50846304a8869a8ea3f8ab61fbb49de1afbf7c426312831f12",
|
||||
"package/package.json": "70e5dfbfae4d6e7590223b22651750a65940c006b64faa0b9ac47eaeaad22be0",
|
||||
"package/src/index.js": "ecf74ed0f5f7760f906e818883fbf5a58339b41a13ceb6080e224d4815a94502",
|
||||
"package/src/parser.js": "ce10bee2c21c59fd32230b253581738b59f103fcd2b350b74a245d630642e777",
|
||||
"package/types/artplayer-plugin-multiple-subtitles.d.ts": "33aab7b7c098e39f3a11cfa264c07452b2e3ad0dc3a7a8c8c3c95dae6856bd74"
|
||||
},
|
||||
"manifest": {
|
||||
"license": "MIT",
|
||||
"version": "1.0.0",
|
||||
"name": "artplayer-plugin-multiple-subtitles",
|
||||
"types": "types/artplayer-plugin-multiple-subtitles.d.ts",
|
||||
"description": "multiple subtitles plugin for ArtPlayer",
|
||||
"main": "dist/artplayer-plugin-multiple-subtitles.js",
|
||||
"legacy": "dist/artplayer-plugin-multiple-subtitles.legacy.js",
|
||||
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
|
||||
"browserslist": "last 1 Chrome version",
|
||||
"homepage": "https://artplayer.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zhw2590582/ArtPlayer.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/zhw2590582/ArtPlayer/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"html5",
|
||||
"video",
|
||||
"player"
|
||||
]
|
||||
},
|
||||
"missingEntrypoints": {},
|
||||
"historicalCore": {
|
||||
"version": "5.1.2",
|
||||
"commit": "43309b72cff84344bd61f4de505aee0e10a83e6b",
|
||||
"file": "packages/artplayer/package.json",
|
||||
"sha256LF": "aaf3ba9c7beaaea31170cc50e3958c0bb5d779ab4f90b6a213994ce8c9aace36",
|
||||
"scope": "Git association only; no npm core integration result is implied."
|
||||
}
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
"packages/artplayer-plugin-multiple-subtitles/package.json": "3f8b631444e51da259f86d6cc83095df788eb3c41843724ad2a35d8b896b985f",
|
||||
"packages/artplayer-plugin-multiple-subtitles/README.md": "c811dabe9b0baa8739497b26ec287ad13beda59f996dec8e96f8d9244b612e86",
|
||||
"packages/artplayer-plugin-multiple-subtitles/src/index.js": "02d7019e92bed7817d815f04df80605ae0bd94f03e2b8c52022b5f622ba2e2ba",
|
||||
"packages/artplayer-plugin-multiple-subtitles/src/parser.js": "ba582074d57fa2d72880e6e4253fe14646787916b2b68e2a1e748e685cf96ab1",
|
||||
"packages/artplayer-plugin-multiple-subtitles/types/artplayer-plugin-multiple-subtitles.d.ts": "6fc3107127b93b5107d679183dadd5740d4b7d5ea2cf2e51d877d576957e1386",
|
||||
"packages/artplayer-plugin-multiple-subtitles/dist/artplayer-plugin-multiple-subtitles.js": "c1cb0b511da88347165cc855185de9450a44835bb34bb802281ccdb854ef603c",
|
||||
"packages/artplayer-plugin-multiple-subtitles/dist/artplayer-plugin-multiple-subtitles.legacy.js": "0b17644827e5b199afe8293093c44bfda571821014ff5b087c7c918c630dcc18",
|
||||
"packages/artplayer-plugin-multiple-subtitles/dist/artplayer-plugin-multiple-subtitles.mjs": "e867c64303299a53d2bf6af62cc1e59044f1c7355aeb55e45b15ab2703448cb0",
|
||||
"docs/assets/example/multiple.subtitles.js": "d9ccbd334d4c77f26826144870d6700e4b62f1f00b7f8f49817b3ac2583e5cc4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
## creative commons
|
||||
|
||||
# CC0 1.0 Universal
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.
|
||||
|
||||
### Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. __Copyright and Related Rights.__ A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
|
||||
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
|
||||
iii. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
|
||||
|
||||
iv. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
|
||||
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data in a Work;
|
||||
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
|
||||
|
||||
vii. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
|
||||
|
||||
2. __Waiver.__ To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. __Public License Fallback.__ Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
|
||||
|
||||
4. __Limitations and Disclaimers.__
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
|
||||
|
||||
b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
|
||||
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
|
||||
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "webvtt-parser",
|
||||
"version": "2.1.2",
|
||||
"description": "WebVTT parser and validator",
|
||||
"main": "parser.js",
|
||||
"files": ["parser.js", "html-entities.json"],
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/w3c/webvtt.js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"WebVTT"
|
||||
],
|
||||
"author": "Anne van Kesteren <annevk@annevk.nl>",
|
||||
"contributors": [],
|
||||
"license": "CC0-1.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/w3c/webvtt.js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/w3c/webvtt.js",
|
||||
"devDependencies": {
|
||||
"chai": "^4.2.0",
|
||||
"mocha": "^8.0.1"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -0,0 +1,888 @@
|
||||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
// Not intended to be fast, but if you can make it faster, please help out!
|
||||
|
||||
(function () {
|
||||
var defaultCueSettings = {
|
||||
direction:"horizontal",
|
||||
snapToLines:true,
|
||||
linePosition:"auto",
|
||||
lineAlign:"start",
|
||||
textPosition:"auto",
|
||||
positionAlign:"auto",
|
||||
size:100,
|
||||
alignment:"center",
|
||||
};
|
||||
|
||||
var WebVTTParser = function(entities) {
|
||||
if (!entities) {
|
||||
entities = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
"&lrm": "\u200e",
|
||||
"&rlm": "\u200f",
|
||||
" ": "\u00A0"
|
||||
}
|
||||
}
|
||||
this.entities = entities
|
||||
this.parse = function(input, mode) {
|
||||
// global search and replace for \0
|
||||
input = input.replace(/\0/g, '\uFFFD');
|
||||
var NEWLINE = /\r\n|\r|\n/,
|
||||
startTime = Date.now(),
|
||||
linePos = 0,
|
||||
lines = input.split(NEWLINE),
|
||||
alreadyCollected = false,
|
||||
styles = [],
|
||||
cues = [],
|
||||
errors = []
|
||||
function err(message, col) {
|
||||
errors.push({message:message, line:linePos+1, col:col})
|
||||
}
|
||||
|
||||
var line = lines[linePos],
|
||||
lineLength = line.length,
|
||||
signature = "WEBVTT",
|
||||
bom = 0,
|
||||
signature_length = signature.length
|
||||
|
||||
/* Byte order mark */
|
||||
if (line[0] === "\ufeff") {
|
||||
bom = 1
|
||||
signature_length += 1
|
||||
}
|
||||
/* SIGNATURE */
|
||||
if (
|
||||
lineLength < signature_length ||
|
||||
line.indexOf(signature) !== 0+bom ||
|
||||
lineLength > signature_length &&
|
||||
line[signature_length] !== " " &&
|
||||
line[signature_length] !== "\t"
|
||||
) {
|
||||
err("No valid signature. (File needs to start with \"WEBVTT\".)")
|
||||
}
|
||||
|
||||
linePos++
|
||||
|
||||
/* HEADER */
|
||||
while(lines[linePos] != "" && lines[linePos] != undefined) {
|
||||
err("No blank line after the signature.")
|
||||
if(lines[linePos].indexOf("-->") != -1) {
|
||||
alreadyCollected = true
|
||||
break
|
||||
}
|
||||
linePos++
|
||||
}
|
||||
|
||||
/* CUE LOOP */
|
||||
while(lines[linePos] != undefined) {
|
||||
var cue
|
||||
while(!alreadyCollected && lines[linePos] == "") {
|
||||
linePos++
|
||||
}
|
||||
if(!alreadyCollected && lines[linePos] == undefined)
|
||||
break
|
||||
|
||||
/* CUE CREATION */
|
||||
cue = Object.assign({}, defaultCueSettings, {
|
||||
id:"",
|
||||
startTime:0,
|
||||
endTime:0,
|
||||
pauseOnExit:false,
|
||||
direction:"horizontal",
|
||||
snapToLines:true,
|
||||
linePosition:"auto",
|
||||
lineAlign:"start",
|
||||
textPosition:"auto",
|
||||
positionAlign:"auto",
|
||||
size:100,
|
||||
alignment:"center",
|
||||
text:"",
|
||||
tree:null
|
||||
})
|
||||
|
||||
var parseTimings = true
|
||||
|
||||
if(lines[linePos].indexOf("-->") == -1) {
|
||||
cue.id = lines[linePos]
|
||||
|
||||
/* COMMENTS
|
||||
Not part of the specification's parser as these would just be ignored. However,
|
||||
we want them to be conforming and not get "Cue identifier cannot be standalone".
|
||||
*/
|
||||
if(/^NOTE($|[ \t])/.test(cue.id)) { // .startsWith fails in Chrome
|
||||
linePos++
|
||||
while(lines[linePos] != "" && lines[linePos] != undefined) {
|
||||
if(lines[linePos].indexOf("-->") != -1)
|
||||
err("Cannot have timestamp in a comment.")
|
||||
linePos++
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
/* STYLES */
|
||||
if(/^STYLE($|[ \t])/.test(cue.id)) {
|
||||
var style = []
|
||||
var invalid = false
|
||||
linePos++
|
||||
while(lines[linePos] != "" && lines[linePos] != undefined) {
|
||||
if(lines[linePos].indexOf("-->") != -1) {
|
||||
err("Cannot have timestamp in a style block.")
|
||||
invalid = true
|
||||
}
|
||||
style.push(lines[linePos])
|
||||
linePos++
|
||||
}
|
||||
if(cues.length) {
|
||||
err("Style blocks cannot appear after the first cue.")
|
||||
continue
|
||||
}
|
||||
if (!invalid) {
|
||||
styles.push(style.join('\n'))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
linePos++
|
||||
|
||||
if(lines[linePos] == "" || lines[linePos] == undefined) {
|
||||
err("Cue identifier cannot be standalone.")
|
||||
continue
|
||||
}
|
||||
|
||||
if(lines[linePos].indexOf("-->") == -1) {
|
||||
parseTimings = false
|
||||
err("Cue identifier needs to be followed by timestamp.")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
/* TIMINGS */
|
||||
alreadyCollected = false
|
||||
var timings = new WebVTTCueTimingsAndSettingsParser(lines[linePos], err)
|
||||
var previousCueStart = 0
|
||||
if(cues.length > 0) {
|
||||
previousCueStart = cues[cues.length-1].startTime
|
||||
}
|
||||
if(parseTimings && !timings.parse(cue, previousCueStart)) {
|
||||
/* BAD CUE */
|
||||
|
||||
cue = null
|
||||
linePos++
|
||||
|
||||
/* BAD CUE LOOP */
|
||||
while(lines[linePos] != "" && lines[linePos] != undefined) {
|
||||
if(lines[linePos].indexOf("-->") != -1) {
|
||||
alreadyCollected = true
|
||||
break
|
||||
}
|
||||
linePos++
|
||||
}
|
||||
continue
|
||||
}
|
||||
linePos++
|
||||
|
||||
/* CUE TEXT LOOP */
|
||||
while(lines[linePos] != "" && lines[linePos] != undefined) {
|
||||
if(lines[linePos].indexOf("-->") != -1) {
|
||||
err("Blank line missing before cue.")
|
||||
alreadyCollected = true
|
||||
break
|
||||
}
|
||||
if(cue.text != "")
|
||||
cue.text += "\n"
|
||||
cue.text += lines[linePos]
|
||||
linePos++
|
||||
}
|
||||
|
||||
/* CUE TEXT PROCESSING */
|
||||
var cuetextparser = new WebVTTCueTextParser(cue.text, err, mode, entities)
|
||||
cue.tree = cuetextparser.parse(cue.startTime, cue.endTime)
|
||||
cues.push(cue)
|
||||
}
|
||||
cues.sort(function(a, b) {
|
||||
if (a.startTime < b.startTime)
|
||||
return -1
|
||||
if (a.startTime > b.startTime)
|
||||
return 1
|
||||
if (a.endTime > b.endTime)
|
||||
return -1
|
||||
if (a.endTime < b.endTime)
|
||||
return 1
|
||||
return 0
|
||||
})
|
||||
/* END */
|
||||
return {cues:cues, errors:errors, time:Date.now()-startTime, styles: styles}
|
||||
}
|
||||
}
|
||||
|
||||
var WebVTTCueTimingsAndSettingsParser = function(line, errorHandler) {
|
||||
var SPACE = /[\u0020\t\f]/,
|
||||
NOSPACE = /[^\u0020\t\f]/,
|
||||
line = line,
|
||||
pos = 0,
|
||||
err = function(message) {
|
||||
errorHandler(message, pos+1)
|
||||
},
|
||||
spaceBeforeSetting = true
|
||||
function skip(pattern) {
|
||||
while(
|
||||
line[pos] != undefined &&
|
||||
pattern.test(line[pos])
|
||||
) {
|
||||
pos++
|
||||
}
|
||||
}
|
||||
function collect(pattern) {
|
||||
var str = ""
|
||||
while(
|
||||
line[pos] != undefined &&
|
||||
pattern.test(line[pos])
|
||||
) {
|
||||
str += line[pos]
|
||||
pos++
|
||||
}
|
||||
return str
|
||||
}
|
||||
/* http://dev.w3.org/html5/webvtt/#collect-a-webvtt-timestamp */
|
||||
function timestamp() {
|
||||
var units = "minutes",
|
||||
val1,
|
||||
val2,
|
||||
val3,
|
||||
val4
|
||||
// 3
|
||||
if(line[pos] == undefined) {
|
||||
err("No timestamp found.")
|
||||
return
|
||||
}
|
||||
// 4
|
||||
if(!/\d/.test(line[pos])) {
|
||||
err("Timestamp must start with a character in the range 0-9.")
|
||||
return
|
||||
}
|
||||
// 5-7
|
||||
val1 = collect(/\d/)
|
||||
if(val1.length > 2 || parseInt(val1, 10) > 59) {
|
||||
units = "hours"
|
||||
}
|
||||
// 8
|
||||
if(line[pos] != ":") {
|
||||
err("No time unit separator found.")
|
||||
return
|
||||
}
|
||||
pos++
|
||||
// 9-11
|
||||
val2 = collect(/\d/)
|
||||
if(val2.length != 2) {
|
||||
err("Must be exactly two digits.")
|
||||
return
|
||||
}
|
||||
// 12
|
||||
if(units == "hours" || line[pos] == ":") {
|
||||
if(line[pos] != ":") {
|
||||
err("No seconds found or minutes is greater than 59.")
|
||||
return
|
||||
}
|
||||
pos++
|
||||
val3 = collect(/\d/)
|
||||
if(val3.length != 2) {
|
||||
err("Must be exactly two digits.")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if (val1.length != 2) {
|
||||
err("Must be exactly two digits.")
|
||||
return
|
||||
}
|
||||
val3 = val2
|
||||
val2 = val1
|
||||
val1 = "0"
|
||||
}
|
||||
// 13
|
||||
if(line[pos] != ".") {
|
||||
err("No decimal separator (\".\") found.")
|
||||
return
|
||||
}
|
||||
pos++
|
||||
// 14-16
|
||||
val4 = collect(/\d/)
|
||||
if(val4.length != 3) {
|
||||
err("Milliseconds must be given in three digits.")
|
||||
return
|
||||
}
|
||||
// 17
|
||||
if(parseInt(val2, 10) > 59) {
|
||||
err("You cannot have more than 59 minutes.")
|
||||
return
|
||||
}
|
||||
if(parseInt(val3, 10) > 59) {
|
||||
err("You cannot have more than 59 seconds.")
|
||||
return
|
||||
}
|
||||
return parseInt(val1, 10) * 60 * 60 + parseInt(val2, 10) * 60 + parseInt(val3, 10) + parseInt(val4, 10) / 1000
|
||||
}
|
||||
|
||||
/* http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings */
|
||||
function parseSettings(input, cue) {
|
||||
var settings = input.split(SPACE),
|
||||
seen = []
|
||||
for(var i=0; i < settings.length; i++) {
|
||||
if(settings[i] == "")
|
||||
continue
|
||||
|
||||
var index = settings[i].indexOf(':'),
|
||||
setting = settings[i].slice(0, index),
|
||||
value = settings[i].slice(index + 1)
|
||||
|
||||
if(seen.indexOf(setting) != -1) {
|
||||
err("Duplicate setting.")
|
||||
}
|
||||
seen.push(setting)
|
||||
|
||||
if(value == "") {
|
||||
err("No value for setting defined.")
|
||||
return
|
||||
}
|
||||
|
||||
if(setting == "vertical") { // writing direction
|
||||
if(value != "rl" && value != "lr") {
|
||||
err("Writing direction can only be set to 'rl' or 'rl'.")
|
||||
continue
|
||||
}
|
||||
cue.direction = value
|
||||
} else if(setting == "line") { // line position and optionally line alignment
|
||||
if (/,/.test(value)) {
|
||||
var comp = value.split(',')
|
||||
value = comp[0]
|
||||
var lineAlign = comp[1]
|
||||
}
|
||||
if(!/^[-\d](\d*)(\.\d+)?%?$/.test(value)) {
|
||||
err("Line position takes a number or percentage.")
|
||||
continue
|
||||
}
|
||||
if(value.indexOf("-", 1) != -1) {
|
||||
err("Line position can only have '-' at the start.")
|
||||
continue
|
||||
}
|
||||
if(value.indexOf("%") != -1 && value.indexOf("%") != value.length-1) {
|
||||
err("Line position can only have '%' at the end.")
|
||||
continue
|
||||
}
|
||||
if(value[0] == "-" && value[value.length-1] == "%") {
|
||||
err("Line position cannot be a negative percentage.")
|
||||
continue
|
||||
}
|
||||
var numVal = value;
|
||||
var isPercent = false;
|
||||
if(value[value.length-1] == "%") {
|
||||
isPercent = true;
|
||||
numVal = value.slice(0, value.length-1)
|
||||
if(parseInt(value, 10) > 100) {
|
||||
err("Line position cannot be >100%.")
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (numVal === '' || isNaN(numVal) || !isFinite(numVal)) {
|
||||
err("Line position needs to be a number")
|
||||
continue
|
||||
}
|
||||
if (lineAlign !== undefined) {
|
||||
if (!["start", "center", "end"].includes(lineAlign)) {
|
||||
err("Line alignment needs to be one of start, center or end")
|
||||
continue
|
||||
}
|
||||
cue.lineAlign = lineAlign
|
||||
}
|
||||
cue.snapToLines = !isPercent;
|
||||
cue.linePosition = parseFloat(numVal)
|
||||
if (parseFloat(numVal).toString() !== numVal) {
|
||||
cue.nonSerializable = true;
|
||||
}
|
||||
} else if(setting == "position") { // text position and optional positionAlign
|
||||
if (/,/.test(value)) {
|
||||
var comp = value.split(',')
|
||||
value = comp[0]
|
||||
var positionAlign = comp[1]
|
||||
}
|
||||
if(value[value.length-1] != "%") {
|
||||
err("Text position must be a percentage.")
|
||||
continue
|
||||
}
|
||||
if(parseInt(value, 10) > 100 || parseInt(value, 10) < 0) {
|
||||
err("Text position needs to be between 0 and 100%.")
|
||||
continue
|
||||
}
|
||||
numVal = value.slice(0, value.length-1)
|
||||
if (numVal === '' || isNaN(numVal) || !isFinite(numVal)) {
|
||||
err("Line position needs to be a number")
|
||||
continue
|
||||
}
|
||||
if (positionAlign !== undefined) {
|
||||
if (!["line-left", "center", "line-right"].includes(positionAlign)) {
|
||||
err("Position alignment needs to be one of line-left, center or line-right")
|
||||
continue
|
||||
}
|
||||
cue.positionAlign = positionAlign
|
||||
}
|
||||
cue.textPosition = parseFloat(numVal)
|
||||
} else if(setting == "size") { // size
|
||||
if(value[value.length-1] != "%") {
|
||||
err("Size must be a percentage.")
|
||||
continue
|
||||
}
|
||||
if(parseInt(value, 10) > 100) {
|
||||
err("Size cannot be >100%.")
|
||||
continue
|
||||
}
|
||||
var size = value.slice(0, value.length -1)
|
||||
if (size === undefined || size === "" || isNaN(size)) {
|
||||
err("Size needs to be a number")
|
||||
size = 100
|
||||
continue
|
||||
} else {
|
||||
size = parseFloat(size)
|
||||
if (size < 0 || size > 100) {
|
||||
err("Size needs to be between 0 and 100%.")
|
||||
continue;
|
||||
}
|
||||
}
|
||||
cue.size = size
|
||||
} else if(setting == "align") { // alignment
|
||||
var alignValues = ["start", "center", "end", "left", "right"]
|
||||
if(alignValues.indexOf(value) == -1) {
|
||||
err("Alignment can only be set to one of " + alignValues.join(", ") + ".")
|
||||
continue
|
||||
}
|
||||
cue.alignment = value
|
||||
} else {
|
||||
err("Invalid setting.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.parse = function(cue, previousCueStart) {
|
||||
skip(SPACE)
|
||||
cue.startTime = timestamp()
|
||||
if(cue.startTime == undefined) {
|
||||
return
|
||||
}
|
||||
if(cue.startTime < previousCueStart) {
|
||||
err("Start timestamp is not greater than or equal to start timestamp of previous cue.")
|
||||
}
|
||||
if(NOSPACE.test(line[pos])) {
|
||||
err("Timestamp not separated from '-->' by whitespace.")
|
||||
}
|
||||
skip(SPACE)
|
||||
// 6-8
|
||||
if(line[pos] != "-") {
|
||||
err("No valid timestamp separator found.")
|
||||
return
|
||||
}
|
||||
pos++
|
||||
if(line[pos] != "-") {
|
||||
err("No valid timestamp separator found.")
|
||||
return
|
||||
}
|
||||
pos++
|
||||
if(line[pos] != ">") {
|
||||
err("No valid timestamp separator found.")
|
||||
return
|
||||
}
|
||||
pos++
|
||||
if(NOSPACE.test(line[pos])) {
|
||||
err("'-->' not separated from timestamp by whitespace.")
|
||||
}
|
||||
skip(SPACE)
|
||||
cue.endTime = timestamp()
|
||||
if(cue.endTime == undefined) {
|
||||
return
|
||||
}
|
||||
if(cue.endTime <= cue.startTime) {
|
||||
err("End timestamp is not greater than start timestamp.")
|
||||
}
|
||||
|
||||
if(NOSPACE.test(line[pos])) {
|
||||
spaceBeforeSetting = false
|
||||
}
|
||||
skip(SPACE)
|
||||
parseSettings(line.substring(pos), cue)
|
||||
return true
|
||||
}
|
||||
this.parseTimestamp = function() {
|
||||
var ts = timestamp()
|
||||
if(line[pos] != undefined) {
|
||||
err("Timestamp must not have trailing characters.")
|
||||
return
|
||||
}
|
||||
return ts
|
||||
}
|
||||
}
|
||||
|
||||
var WebVTTCueTextParser = function(line, errorHandler, mode, entities) {
|
||||
this.entities = entities
|
||||
var self = this
|
||||
var line = line,
|
||||
pos = 0,
|
||||
err = function(message) {
|
||||
if(mode == "metadata")
|
||||
return
|
||||
errorHandler(message, pos+1)
|
||||
}
|
||||
|
||||
this.parse = function(cueStart, cueEnd) {
|
||||
function removeCycles(tree) {
|
||||
const cyclelessTree = {...tree};
|
||||
if (tree.children) {
|
||||
cyclelessTree.children = tree.children.map(removeCycles);
|
||||
}
|
||||
if (cyclelessTree.parent) {
|
||||
delete cyclelessTree.parent;
|
||||
}
|
||||
return cyclelessTree;
|
||||
}
|
||||
|
||||
var result = {children:[]},
|
||||
current = result,
|
||||
timestamps = []
|
||||
|
||||
function attach(token) {
|
||||
current.children.push({type:"object", name:token[1], classes:token[2], children:[], parent:current})
|
||||
current = current.children[current.children.length-1]
|
||||
}
|
||||
function inScope(name) {
|
||||
var node = current
|
||||
while(node) {
|
||||
if(node.name == name)
|
||||
return true
|
||||
node = node.parent
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
while(line[pos] != undefined) {
|
||||
var token = nextToken()
|
||||
if(token[0] == "text") {
|
||||
current.children.push({type:"text", value:token[1], parent:current})
|
||||
} else if(token[0] == "start tag") {
|
||||
if(mode == "chapters")
|
||||
err("Start tags not allowed in chapter title text.")
|
||||
var name = token[1]
|
||||
if(name != "v" && name != "lang" && token[3] != "") {
|
||||
err("Only <v> and <lang> can have an annotation.")
|
||||
}
|
||||
if(
|
||||
name == "c" ||
|
||||
name == "i" ||
|
||||
name == "b" ||
|
||||
name == "u" ||
|
||||
name == "ruby"
|
||||
) {
|
||||
attach(token)
|
||||
} else if(name == "rt" && current.name == "ruby") {
|
||||
attach(token)
|
||||
} else if(name == "v") {
|
||||
if(inScope("v")) {
|
||||
err("<v> cannot be nested inside itself.")
|
||||
}
|
||||
attach(token)
|
||||
current.value = token[3] // annotation
|
||||
if(!token[3]) {
|
||||
err("<v> requires an annotation.")
|
||||
}
|
||||
} else if(name == "lang") {
|
||||
attach(token)
|
||||
current.value = token[3] // language
|
||||
} else {
|
||||
err("Incorrect start tag.")
|
||||
}
|
||||
} else if(token[0] == "end tag") {
|
||||
if(mode == "chapters")
|
||||
err("End tags not allowed in chapter title text.")
|
||||
// XXX check <ruby> content
|
||||
if(token[1] == current.name) {
|
||||
current = current.parent
|
||||
} else if(token[1] == "ruby" && current.name == "rt") {
|
||||
current = current.parent.parent
|
||||
} else {
|
||||
err("Incorrect end tag.")
|
||||
}
|
||||
} else if(token[0] == "timestamp") {
|
||||
if(mode == "chapters")
|
||||
err("Timestamp not allowed in chapter title text.")
|
||||
var timings = new WebVTTCueTimingsAndSettingsParser(token[1], err),
|
||||
timestamp = timings.parseTimestamp()
|
||||
if(timestamp != undefined) {
|
||||
if(timestamp <= cueStart || timestamp >= cueEnd) {
|
||||
err("Timestamp must be between start timestamp and end timestamp.")
|
||||
}
|
||||
if(timestamps.length > 0 && timestamps[timestamps.length-1] >= timestamp) {
|
||||
err("Timestamp must be greater than any previous timestamp.")
|
||||
}
|
||||
current.children.push({type:"timestamp", value:timestamp, parent:current})
|
||||
timestamps.push(timestamp)
|
||||
}
|
||||
}
|
||||
}
|
||||
while(current.parent) {
|
||||
if(current.name != "v") {
|
||||
err("Required end tag missing.")
|
||||
}
|
||||
current = current.parent
|
||||
}
|
||||
return removeCycles(result)
|
||||
}
|
||||
|
||||
function nextToken() {
|
||||
var state = "data",
|
||||
result = "",
|
||||
buffer = "",
|
||||
classes = []
|
||||
while(line[pos-1] != undefined || pos == 0) {
|
||||
var c = line[pos]
|
||||
if(state == "data") {
|
||||
if(c == "&") {
|
||||
buffer = c
|
||||
state = "escape"
|
||||
} else if(c == "<" && result == "") {
|
||||
state = "tag"
|
||||
} else if(c == "<" || c == undefined) {
|
||||
return ["text", result]
|
||||
} else {
|
||||
result += c
|
||||
}
|
||||
} else if(state == "escape") {
|
||||
if(c == "<" || c == undefined) {
|
||||
err("Incorrect escape.")
|
||||
let m;
|
||||
if (m = buffer.match(/^&#([0-9]+)$/)) {
|
||||
result += String.fromCharCode(m[1])
|
||||
} else {
|
||||
if(self.entities[buffer]) {
|
||||
result += self.entities[buffer]
|
||||
} else {
|
||||
result += buffer
|
||||
}
|
||||
}
|
||||
return ["text", result]
|
||||
} else if(c == "&") {
|
||||
err("Incorrect escape.")
|
||||
result += buffer
|
||||
buffer = c
|
||||
} else if(/[a-z#0-9]/i.test(c)) {
|
||||
buffer += c
|
||||
} else if(c == ";") {
|
||||
let m;
|
||||
if (m = buffer.match(/^&#(x?[0-9]+)$/)) {
|
||||
// we prepend "0" so that x20 be interpreted as hexadecim (0x20)
|
||||
result += String.fromCharCode("0" + m[1])
|
||||
} else if(self.entities[buffer + c]) {
|
||||
result += self.entities[buffer + c]
|
||||
} else if (m = Object.keys(entities).find(n => buffer.startsWith(n))) { // partial match
|
||||
result += self.entities[m] + buffer.slice(m.length) + c
|
||||
} else {
|
||||
err("Incorrect escape.")
|
||||
result += buffer + ";"
|
||||
}
|
||||
state = "data"
|
||||
} else {
|
||||
err("Incorrect escape.")
|
||||
result += buffer + c
|
||||
state = "data"
|
||||
}
|
||||
} else if(state == "tag") {
|
||||
if(c == "\t" || c == "\n" || c == "\f" || c == " ") {
|
||||
state = "start tag annotation"
|
||||
} else if(c == ".") {
|
||||
state = "start tag class"
|
||||
} else if(c == "/") {
|
||||
state = "end tag"
|
||||
} else if(/\d/.test(c)) {
|
||||
result = c
|
||||
state = "timestamp tag"
|
||||
} else if(c == ">" || c == undefined) {
|
||||
if(c == ">") {
|
||||
pos++
|
||||
}
|
||||
return ["start tag", "", [], ""]
|
||||
} else {
|
||||
result = c
|
||||
state = "start tag"
|
||||
}
|
||||
} else if(state == "start tag") {
|
||||
if(c == "\t" || c == "\f" || c == " ") {
|
||||
state = "start tag annotation"
|
||||
} else if(c == "\n") {
|
||||
buffer = c
|
||||
state = "start tag annotation"
|
||||
} else if(c == ".") {
|
||||
state = "start tag class"
|
||||
} else if(c == ">" || c == undefined) {
|
||||
if(c == ">") {
|
||||
pos++
|
||||
}
|
||||
return ["start tag", result, [], ""]
|
||||
} else {
|
||||
result += c
|
||||
}
|
||||
} else if(state == "start tag class") {
|
||||
if(c == "\t" || c == "\f" || c == " ") {
|
||||
if (buffer) {
|
||||
classes.push(buffer)
|
||||
}
|
||||
buffer = ""
|
||||
state = "start tag annotation"
|
||||
} else if(c == "\n") {
|
||||
if (buffer) {
|
||||
classes.push(buffer)
|
||||
}
|
||||
buffer = c
|
||||
state = "start tag annotation"
|
||||
} else if(c == ".") {
|
||||
if (buffer) {
|
||||
classes.push(buffer)
|
||||
}
|
||||
buffer = ""
|
||||
} else if(c == ">" || c == undefined) {
|
||||
if(c == ">") {
|
||||
pos++
|
||||
}
|
||||
if (buffer) {
|
||||
classes.push(buffer)
|
||||
}
|
||||
return ["start tag", result, classes, ""]
|
||||
} else {
|
||||
buffer += c
|
||||
}
|
||||
} else if(state == "start tag annotation") {
|
||||
if(c == ">" || c == undefined) {
|
||||
if(c == ">") {
|
||||
pos++
|
||||
}
|
||||
buffer = buffer.split(/[\u0020\t\f\r\n]+/).filter(function(item) { if(item) return true }).join(" ")
|
||||
return ["start tag", result, classes, buffer]
|
||||
} else {
|
||||
buffer +=c
|
||||
}
|
||||
} else if(state == "end tag") {
|
||||
if(c == ">" || c == undefined) {
|
||||
if(c == ">") {
|
||||
pos++
|
||||
}
|
||||
return ["end tag", result]
|
||||
} else {
|
||||
result += c
|
||||
}
|
||||
} else if(state == "timestamp tag") {
|
||||
if(c == ">" || c == undefined) {
|
||||
if(c == ">") {
|
||||
pos++
|
||||
}
|
||||
return ["timestamp", result]
|
||||
} else {
|
||||
result += c
|
||||
}
|
||||
} else {
|
||||
err("Never happens.") // The joke is it might.
|
||||
}
|
||||
// 8
|
||||
pos++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var WebVTTSerializer = function() {
|
||||
function serializeTimestamp(seconds) {
|
||||
const ms = ("00" + (seconds - Math.floor(seconds)).toFixed(3)*1000).slice(-3);
|
||||
let h = 0, m = 0, s = 0;
|
||||
if (seconds >= 3600) {
|
||||
h = Math.floor(seconds/3600);
|
||||
}
|
||||
m = Math.floor((seconds - 3600*h) / 60);
|
||||
s = Math.floor(seconds - 3600*h - 60*m);
|
||||
return (h ? h + ":" : "") + ("" + m).padStart(2, "0") + ":" + ("" + s).padStart(2, "0") + "." + ms;
|
||||
}
|
||||
function serializeCueSettings(cue) {
|
||||
var result = ""
|
||||
const nonDefaultSettings = Object.keys(defaultCueSettings).filter(s => cue[s] !== defaultCueSettings[s]);
|
||||
if (nonDefaultSettings.includes("direction")) {
|
||||
result+= " vertical:" + cue.direction
|
||||
}
|
||||
if (nonDefaultSettings.includes("alignment")) {
|
||||
result+= " align:" + cue.alignment
|
||||
}
|
||||
if (nonDefaultSettings.includes("size")) {
|
||||
result+= " size:" + cue.size + "%"
|
||||
}
|
||||
if (nonDefaultSettings.includes("lineAlign") || nonDefaultSettings.includes("linePosition")) {
|
||||
result += " line:" + cue.linePosition + (cue.snapToLines ? "" : "%") + (cue.lineAlign && cue.lineAlign != defaultCueSettings.lineAlign ? "," + cue.lineAlign : "")
|
||||
}
|
||||
if (nonDefaultSettings.includes("textPosition") || nonDefaultSettings.includes("positionAlign")) {
|
||||
result += " position:" + cue.textPosition + "%" + (cue.positionAlign && cue.positionAlign !== defaultCueSettings.positionAlign ? "," + cue.positionAlign : "")
|
||||
}
|
||||
return result
|
||||
}
|
||||
function serializeTree(tree) {
|
||||
var result = ""
|
||||
for (var i = 0; i < tree.length; i++) {
|
||||
var node = tree[i]
|
||||
if(node.type == "text") {
|
||||
result += node.value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
} else if(node.type == "object") {
|
||||
result += "<" + node.name
|
||||
if(node.classes) {
|
||||
for(var y = 0; y < node.classes.length; y++) {
|
||||
result += "." + node.classes[y]
|
||||
}
|
||||
}
|
||||
if(node.value) {
|
||||
result += " " + node.value
|
||||
}
|
||||
result += ">"
|
||||
if(node.children)
|
||||
result += serializeTree(node.children)
|
||||
result += "</" + node.name + ">"
|
||||
} else if(node.type == "timestamp") {
|
||||
result += "<" + serializeTimestamp(node.value) + ">"
|
||||
} else {
|
||||
result += "<" + node.value + ">"
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
function serializeCue(cue) {
|
||||
return (cue.id !== undefined ? cue.id + "\n" : "")
|
||||
+ serializeTimestamp(cue.startTime)
|
||||
+ " --> "
|
||||
+ serializeTimestamp(cue.endTime)
|
||||
+ serializeCueSettings(cue)
|
||||
+ "\n" + serializeTree(cue.tree.children) + "\n\n"
|
||||
}
|
||||
function serializeStyle(style) {
|
||||
return "STYLE\n" + style + "\n\n"
|
||||
}
|
||||
this.serialize = function(cues, styles) {
|
||||
var result = "WEBVTT\n\n"
|
||||
if (styles) {
|
||||
for(var i=0;i<styles.length;i++) {
|
||||
result += serializeStyle(styles[i])
|
||||
}
|
||||
}
|
||||
for(var i=0;i<cues.length;i++) {
|
||||
result += serializeCue(cues[i])
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
function exportify(object) {
|
||||
object.WebVTTParser = WebVTTParser
|
||||
object.WebVTTCueTimingsAndSettingsParser = WebVTTCueTimingsAndSettingsParser
|
||||
object.WebVTTCueTextParser = WebVTTCueTextParser
|
||||
object.WebVTTSerializer = WebVTTSerializer
|
||||
}
|
||||
if (typeof window !== 'undefined') exportify(window);
|
||||
if (typeof exports !== 'undefined') exportify(exports);
|
||||
})()
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"revision": "380cfcce34ba8b472d3a31474874eb72a0e5f460",
|
||||
"packageVersionAtRevision": "2.1.2",
|
||||
"scope": "Pinned comparison revision, not proof of historical acquisition commit. After removing IIFE/global exportify and adding named ESM exports, normalized executable content matches local parser.",
|
||||
"sources": [
|
||||
{
|
||||
"file": "refactor/baselines/multiple-subtitles-vendor/parser.txt",
|
||||
"upstream": "https://raw.githubusercontent.com/w3c/webvtt.js/380cfcce34ba8b472d3a31474874eb72a0e5f460/parser.js",
|
||||
"sha256": "35a112e585b7cb1b4fd30350b0e8c8f6d1efa2670a6008c4a6038e07c9f8d727"
|
||||
},
|
||||
{
|
||||
"file": "refactor/baselines/multiple-subtitles-vendor/license.txt",
|
||||
"upstream": "https://raw.githubusercontent.com/w3c/webvtt.js/380cfcce34ba8b472d3a31474874eb72a0e5f460/LICENSE.md",
|
||||
"sha256": "6cc655a5df52fefac69058311c090f4e70b7c37b8f6488f9498420a930b8275d"
|
||||
},
|
||||
{
|
||||
"file": "refactor/baselines/multiple-subtitles-vendor/package.json.txt",
|
||||
"upstream": "https://raw.githubusercontent.com/w3c/webvtt.js/380cfcce34ba8b472d3a31474874eb72a0e5f460/package.json",
|
||||
"sha256": "d0102b9276839f1136ecafd9527102a28b44643e8ff403b3ddb1e51c04777a7b"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user