Files
Nodecast/test/channelVariantGrouping.test.js
blomios ce11ecc757 feat: add optional Laya engine mode for grouping and language detection (#12)
Add a languageDetectionMode setting (algo | laya | laya+algo) exposed
in Settings with three engine choices. When Laya is enabled, a laya
service (Dockerfile.laya, optional compose profile, models stored
outside the repo under ./data/models/laya) can be started, with model
download and deletion from the UI via /laya routes to manage disk
space. Add a channelLanguageFusion service combining Laya results
with the existing algorithm, and wire detection mode through
grouping, channel list and player. Cover engine selection, fusion
and laya service behavior with tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-02 11:13:34 +02:00

78 lines
3.6 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const grouping = require('../public/js/services/channelVariantGrouping.js');
const channel = (id, name, extra = {}) => ({ id, streamId: id, sourceId: 1, name, groupTitle: 'Sports', ...extra });
test('normalizes regional prefixes and quality markers into one logical channel', () => {
const names = ['|FR| BEIN SPORTS uhd 1', '|FR| BEIN SPORTS 1 4K', 'FR-CAR| bein sports 1'];
assert.deepEqual(names.map(grouping.normalizeChannelName), ['bein sports 1', 'bein sports 1', 'bein sports 1']);
const logical = grouping.groupChannels(names.map((name, index) => channel(String(index + 1), name)));
assert.equal(logical.length, 1);
assert.equal(logical[0].displayName, 'beIN Sports 1');
assert.equal(logical[0].variants.length, 3);
});
test('does not merge distinct numbered channels', () => {
const logical = grouping.groupChannels([
channel('1', 'beIN Sports 1 HD'),
channel('2', 'beIN Sports 2 HD')
]);
assert.deepEqual(logical.map(item => item.fingerprint), ['bein sports 1', 'bein sports 2']);
});
test('logical favorite and hidden state are derived from individual streams', () => {
const variants = [channel('1', 'BEIN SPORTS 1 HD'), channel('2', 'BEIN SPORTS 1 4K')];
const logical = grouping.groupChannels(variants, {
isFavorite: item => item.id === '1',
isHidden: item => item.id === '2'
})[0];
assert.equal(logical.isFavorite, true);
assert.equal(logical.isHidden, false);
assert.equal(logical.preferredVariant.id, '1');
assert.equal(grouping.groupChannels(variants, { isHidden: () => true }).length, 0);
assert.equal(grouping.groupChannels(variants, { isHidden: () => true, showHidden: true })[0].isHidden, true);
});
test('an explicit visible selection overrides the automatic quality preference', () => {
const hd = channel('1', 'BEIN SPORTS 1 HD');
const uhd = channel('2', 'BEIN SPORTS 1 UHD');
const selectedVariants = new Map([['bein sports 1', grouping.getVariantKey(hd)]]);
const logical = grouping.groupChannels([hd, uhd], { selectedVariants })[0];
assert.equal(logical.preferredVariant.id, '1');
});
test('flat list ordering promotes favorites without duplicating channels', () => {
const channels = [
{ id: 'one', isFavorite: false },
{ id: 'two', isFavorite: true },
{ id: 'three', isFavorite: false },
{ id: 'four', isFavorite: true }
];
const ordered = grouping.orderFlatChannels(channels);
assert.deepEqual(ordered.map(item => item.id), ['two', 'four', 'one', 'three']);
assert.equal(new Set(ordered.map(item => item.id)).size, channels.length);
});
test('favorites group updates are disabled for flat lists', () => {
assert.equal(grouping.shouldUseFavoritesGroup('flat'), false);
assert.equal(grouping.shouldUseFavoritesGroup('grouped'), true);
});
test('Laya language results participate in variant selection', () => {
const lowQualityFrench = channel('1', 'Sports One SD');
const highQualityEnglish = channel('2', 'Sports One 4K');
const languageResults = new Map([
[grouping.getVariantKey(lowQualityFrench), { language: 'fr', confidence: 0.92 }],
[grouping.getVariantKey(highQualityEnglish), { language: 'en', confidence: 0.94 }]
]);
const logical = grouping.groupChannels([lowQualityFrench, highQualityEnglish], {
languageMode: 'laya',
languageResults,
preferredLanguage: 'fr'
})[0];
assert.equal(logical.preferredVariant.id, '1');
assert.deepEqual(logical.availableLanguages.map(item => item.code), ['fr', 'en']);
});