feat(subtitle-sidebar): add sidebar config surface (#28)

This commit is contained in:
2026-03-21 23:37:42 -07:00
committed by GitHub
parent eddf6f0456
commit 3a01cffc6b
66 changed files with 5241 additions and 426 deletions
@@ -1,6 +1,7 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {
buildSubtitleSidebarSourceKey,
getActiveExternalSubtitleSource,
resolveSubtitleSourcePath,
} from './subtitle-prefetch-source';
@@ -17,6 +18,15 @@ test('getActiveExternalSubtitleSource returns the active external subtitle path'
assert.equal(source, 'https://host/subs.ass');
});
test('getActiveExternalSubtitleSource normalizes integer-like string track ids', () => {
const source = getActiveExternalSubtitleSource(
[{ type: 'sub', id: '2', external: true, 'external-filename': ' /tmp/subs.ass ' }],
'2',
);
assert.equal(source, '/tmp/subs.ass');
});
test('getActiveExternalSubtitleSource returns null when the selected track is not external', () => {
const source = getActiveExternalSubtitleSource(
[{ type: 'sub', id: 2, external: false, 'external-filename': '/tmp/subs.ass' }],
@@ -48,3 +58,38 @@ test('resolveSubtitleSourcePath returns the original source for malformed file U
assert.equal(resolveSubtitleSourcePath(source), source);
});
test('buildSubtitleSidebarSourceKey uses a stable identifier for internal subtitle tracks', () => {
const firstKey = buildSubtitleSidebarSourceKey('/media/episode01.mkv', {
id: 3,
'ff-index': 7,
title: 'English',
lang: 'eng',
codec: 'ass',
});
const secondKey = buildSubtitleSidebarSourceKey('/media/episode01.mkv', {
id: 3,
'ff-index': 7,
title: 'English',
lang: 'eng',
codec: 'ass',
});
assert.equal(firstKey, secondKey);
assert.equal(firstKey, 'internal:/media/episode01.mkv:track:3:ff:7');
});
test('buildSubtitleSidebarSourceKey normalizes integer-like string track metadata', () => {
const key = buildSubtitleSidebarSourceKey('/media/episode01.mkv', {
id: '3',
'ff-index': '7',
});
assert.equal(key, 'internal:/media/episode01.mkv:track:3:ff:7');
});
test('buildSubtitleSidebarSourceKey falls back to source path when no track metadata is available', () => {
const key = buildSubtitleSidebarSourceKey('/media/episode01.mkv', null, '/tmp/subtitle.ass');
assert.equal(key, '/tmp/subtitle.ass');
});