fix(multiple-subtitles): repair old ASS conversion line breaks [PKG-MULTI-SUB-11]

This commit is contained in:
Harvey Zhao committed 2026-09-14 13:42:46 +08:00
1 parent 8ae2762a23
commit 318de37e8a
22 files changed
+3268 -27

No files matched your search

+9 -3
View File
@@ -270,10 +270,16 @@ the earlier hidden-preview screenshot timeout remains in the checkpoint evidence
`multiple-subtitles-legacy.spec.js` uses real 5.1.2/5.1.7 cores and the candidate
plugin to check three independently timed captions, VTT/SRT, semantic HTML/CSS,
the original update method and native cue identities, scalar event payloads,
repeated updates, selection/reset and empty intervals. It uses ASS for the third
track on5.1.7; the5.1.2 published converter's malformed VTT remains a separate
task11 failure and is not covered by substituting a VTT fixture. Use
repeated updates, selection/reset and empty intervals. It now uses ASS for the third
track on both hosts: task11 repairs the exact5.1.2 main converter defect inside
the plugin. Task10's historical VTT substitution was not ASS acceptance. Use
`ARTPLAYER_MULTIPLE_SUBTITLES_ARTIFACT` for actual main/legacy package bytes.
The combination suite retains explicit published1.1/1.2 overlap-loss observations
while requiring candidate captions to contain both languages. A passing historical
observation is not a compatibility pass.
`multiple-subtitles-ass.spec.js` checks UTF16 decoding, explicit ASS type selection,
multiline text/HTML, overlapping translation, selection/reset and empty intervals
on5.1.2/5.1.7/5.3.0/5.4.0/candidate. The attachment records the unchanged original
host converter output alongside actual native cues and browser/artifact hashes.
It covers desktop video/track playback, not full ASS layout or physical devices.
@@ -0,0 +1,58 @@
import { Buffer } from 'node:buffer'
import { hash } from '../../refactor/scripts/releases.mjs'
import { multipleSubtitlesCandidate } from '../helpers/multiple-subtitles.js'
import { expect, test } from './fixtures.js'
const candidate = await multipleSubtitlesCandidate()
const ass = '[Events]\r\nDialogue: 0,0:00:01.25,0:00:03.75,Default,,0,0,0,,漢字 café, comma <b>bold</b>\\NSecond line\r\nDialogue: 0,0:00:04.25,0:00:06.75,Default,,0,0,0,,Later cue'
for (const core of ['published-5.1.2', 'published-5.1.7', 'published-5.3.0', 'published', 'candidate']) {
test(`Multiple subtitles ASS / ${core}: encoded multiline cues, overlapping translation and selection`, async ({ page, browser }, testInfo) => {
await page.route('**/test/ass-data.bin', route => route.fulfill({ contentType: 'application/octet-stream', body: Buffer.from(ass, 'utf16le') }))
await page.route('**/test/ass-translation.vtt', route => route.fulfill({ contentType: 'text/vtt', body: 'WEBVTT\n\n00:02.000 --> 00:04.000\nTranslation\n' }))
await page.goto(`/test/player.html?core=${core}`)
await page.addScriptTag({ content: candidate.code })
await page.evaluate(() => window.createPlayer('/test/pattern.mp4'))
await expect.poll(() => page.evaluate(() => window.art.isReady)).toBe(true)
await page.evaluate(async () => {
await window.art.plugins.add(window.artplayerPluginMultipleSubtitles({ subtitles: [
{ name: 'ass', url: '/test/ass-data.bin', type: 'ass', encoding: 'utf-16le' },
{ name: 'translation', url: '/test/ass-translation.vtt' },
] }))
})
await expect.poll(() => page.evaluate(() => window.art.template.$track.track.cues?.length)).toBe(3)
const native = await page.evaluate(() => Array.from(window.art.template.$track.track.cues, cue => ({ start: cue.startTime, end: cue.endTime, text: cue.getCueAsHTML().textContent })))
expect(native.map(cue => [cue.start, cue.end])).toEqual([[1.25, 3.75], [2, 4], [4.25, 6.75]])
expect(native[0].text).toContain('漢字 café, comma bold')
expect(native[0].text).toContain('Second line')
await page.locator('#play').click()
await expect.poll(() => page.evaluate(() => window.art.currentTime)).toBeGreaterThan(0.1)
await page.locator('#pause').click()
async function seek(time) {
await page.evaluate(time => new Promise((resolve) => {
window.art.once('video:seeked', resolve)
window.art.seek = time
}), time)
}
await seek(1.5)
await expect(page.locator('.art-subtitle-ass b')).toHaveText('bold')
await expect(page.locator('.art-subtitle')).toContainText('Second line')
await expect(page.locator('.art-subtitle-translation')).toHaveCount(0)
await seek(2.5)
await expect(page.locator('.art-subtitle-ass b')).toBeVisible()
await expect(page.locator('.art-subtitle-translation')).toHaveText('Translation')
await page.evaluate(() => window.art.plugins.multipleSubtitles.tracks(['translation']))
await expect(page.locator('.art-subtitle-ass')).toHaveCount(0)
await expect(page.locator('.art-subtitle-translation')).toHaveText('Translation')
await page.evaluate(() => window.art.plugins.multipleSubtitles.reset())
await expect(page.locator('.art-subtitle-ass b')).toBeVisible()
await seek(5)
await expect(page.locator('.art-subtitle-ass')).toHaveText('Later cue')
await expect(page.locator('.art-subtitle-translation')).toHaveCount(0)
await seek(7.5)
await expect(page.locator('.art-subtitle-ass, .art-subtitle-translation')).toHaveCount(0)
const rawHostOutput = await page.evaluate(ass => window.Artplayer.utils.assToVtt(ass), ass)
await testInfo.attach('ass-conversion', { contentType: 'application/json', body: JSON.stringify({ core, browser: browser.version(), pluginSha256: hash(candidate.code), sourceSha256: hash(Buffer.from(ass, 'utf16le')), rawHostOutput, native, scope: 'Desktop native playback with UTF16 ASS, explicit type override, independently timed multiline/semantic captions, overlap, selection/reset and clearing; original core converter is unchanged.' }) })
await page.evaluate(() => window.art.destroy())
})
}
@@ -9,7 +9,6 @@ for (const core of ['published-5.1.2', 'published-5.1.7']) {
await page.route('**/test/legacy-a.vtt', route => route.fulfill({ contentType: 'text/vtt', body: 'WEBVTT\n\n00:01.000 --> 00:03.000\n<b>A &amp; safe</b>\n' }))
await page.route('**/test/legacy-b.srt', route => route.fulfill({ contentType: 'text/plain', body: '1\n00:00:02,000 --> 00:00:04,000\nB\n' }))
await page.route('**/test/legacy-c.ass', route => route.fulfill({ contentType: 'text/plain', body: 'Dialogue: 0,0:00:02.25,0:00:02.75,Default,,0,0,0,,C' }))
await page.route('**/test/legacy-c.vtt', route => route.fulfill({ contentType: 'text/vtt', body: 'WEBVTT\n\n00:02.250 --> 00:02.750\nC\n' }))
await page.goto(`/test/player.html?core=${core}`)
await page.addScriptTag({ content: candidate.code })
await page.addStyleTag({ content: '.art-subtitle-a { color: rgb(255, 0, 0); } .art-subtitle-b { color: rgb(0, 0, 255); }' })
@@ -20,7 +19,7 @@ for (const core of ['published-5.1.2', 'published-5.1.7']) {
window.art.on('subtitleUpdate', text => window.legacyPayloads.push(text))
})
await expect.poll(() => page.evaluate(() => window.art.isReady)).toBe(true)
const thirdFormat = core === 'published-5.1.2' ? 'vtt' : 'ass'
const thirdFormat = 'ass'
await page.evaluate(async (thirdFormat) => {
await window.art.plugins.add(window.artplayerPluginMultipleSubtitles({ subtitles: [{ name: 'a', url: '/test/legacy-a.vtt' }, { name: 'b', url: '/test/legacy-b.srt' }, { name: 'c', url: `/test/legacy-c.${thirdFormat}` }] }))
}, thirdFormat)
@@ -70,7 +69,7 @@ for (const core of ['published-5.1.2', 'published-5.1.7']) {
await expect(page.locator('.art-subtitle-c')).toHaveText('C')
await seek(4.5)
await expect(page.locator('.art-subtitle-a, .art-subtitle-b, .art-subtitle-c')).toHaveCount(0)
await testInfo.attach('legacy-captions', { contentType: 'application/json', body: JSON.stringify({ core, browser: browser.version(), pluginSha256: hash(candidate.code), thirdFormat, state, scope: 'Native VTT/SRT overlaps (ASS additionally on 5.1.7), semantic HTML/CSS, legacy scalar event payload, original host method and cue identities, repeated update/selection/reset/empty intervals', limitation: '5.1.2 published ASS converter loses required VTT line breaks; tracked separately in PKG-MULTI-SUB-11.' }) })
await testInfo.attach('legacy-captions', { contentType: 'application/json', body: JSON.stringify({ core, browser: browser.version(), pluginSha256: hash(candidate.code), thirdFormat, state, scope: 'Native VTT/SRT/ASS overlaps on both old cores, semantic HTML/CSS, legacy scalar event payload, original host method and cue identities, repeated update/selection/reset/empty intervals' }) })
await page.evaluate(() => window.art.destroy())
})
}