mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-10 01:56:16 -08:00
* feat(playback): record recently viewed only after the stream plays A channel, movie or episode used to enter Recently Viewed (and the dashboard's Continue Watching hero) the moment it was selected or its link was resolved, so streams that failed straight away cluttered the history. Writers now defer the write to a root PlaybackHistoryGate, keyed by the stream URL and/or the playback session key. The inline players confirm those keys once the owned engine's position has advanced by two seconds (seeks, stalls, pauses and a previous stream's progress do not count), the radio player does the same, and a launched MPV/VLC session confirms on `opened`/`playing`. M3U with MPV/VLC configured keeps recording on selection. Covers M3U (live, radio, movie detail), Stalker (live, radio, VOD, series), Xtream VOD and series, and the global live collection. The M3U host's embeddedPlayback is now compared by value: the history write updates the playlist meta mid-playback, and a new but identical playback object remounted the engine and restarted the stream. E2E flows that relied on recording-on-click now play local fixtures (HLS/TS/WebM routed in place of unreachable or public streams) and wait for confirmed playback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(playback): tighten recently viewed confirmation per review - Correlate by session key first: when both the deferred write and the confirmation carry a playbackSessionKey, only that is compared, so the same stream URL played in another playlist no longer records a failed attempt. URLs remain the fallback (portal writes, MPV/VLC sessions). The M3U radio player now receives the host's session key. - Count only playing progress: engines report `playing` (not paused, not seeking) with each time update, so short seeks of paused media no longer confirm a view. - Xtream: a write confirmed after a playlist switch still saves to its own playlist but no longer replaces the current playlist's recent list. - Global live tab: a row confirmed after another row was selected still moves to the top of an open Recently Viewed list (only a disposed tab skips the notification). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(playback): confirm session-keyed history only by its own session A write deferred with a playback session key (M3U) is now confirmed only by that key. The app-wide MPV/VLC session confirmation carries just the URL, so opening the same stream externally from another playlist could still commit an abandoned attempt. An "Open in MPV/VLC" recovery launch is instead confirmed by the WebPlayerViewComponent that requested it, under its own session key, once the launch has opened. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(playback): keep the history gate off the initial bundle The `@iptvnator/services` barrel ships in the initial bundle, so adding PlaybackHistoryGate there (and subscribing to it from the app-wide ExternalPlaybackService) grew renderer.initialBytes by 1,141 bytes. - Move the gate to a new lazy-only `playback-data-access` project (`@iptvnator/playback/data-access`; scope:shared, domain:playback, type:data-access) and register it in the coverage policy. - The gate subscribes to MPV/VLC session updates itself; it is created by the first deferred write, which precedes the launch it waits for. ExternalPlaybackService is back to master. - The Xtream "playlist switched before confirmation" check moves to the lazy helper; the initial-path store only takes a `skipListRefresh` flag. Net effect on this branch: +27 bytes over master (master itself is 108 bytes over the ratchet baseline already). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(playback): drop late Xtream confirmations off the initial path The Xtream store ships in the initial bundle, so even the small `skipListRefresh` flag cost 27 bytes there. A confirmation can only arrive after a switch to another playlist from a slow MPV/VLC launch (the inline player goes with the page), so the lazy helper now drops it instead: recording it would misfile the item or replace the other playlist's recent list. with-recent-items is back to master. This branch is now 3 bytes below master on renderer.initialBytes; the ratchet still reports master's pre-existing overage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(playback): pass the spec type-check gate from master - playback-data-access: align tsconfig.spec.json with the epg-data-access config #1705 updated (bundler resolution, global.d.ts for window.electron). - M3U recent-history spec: type the selectSignal override. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(playback): keep late Xtream confirmations in their own playlist history A confirmation that arrives after a switch to another playlist (a slow MPV/VLC launch) is no longer dropped: the lazy helper saves it to the captured playlist through the data source, without reloading the store's recent list, which belongs to the other playlist by then. The store and its barrel ship in the initial bundle, so the save path stays in the feature helper; renderer.initialBytes stays under the baseline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(playback): correlate global live-tab history by its session key The unified Favorites/Recent live tab deferred its history write by stream URL only, so the same URL played from another playlist could confirm a failed selection, and a switch to catch-up before confirmation could never match. It now defers with the tab's playlist-scoped playbackSessionKey (the key its players confirm with), and the tab's radio player receives it too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(playback): keep MPV/VLC rows of the live tab confirmable by URL The live tab's session key can only be confirmed by its own inline players; MPV/VLC confirm the launched URL alone. A row that goes to an external player (also later, after a double-click) now defers by URL, and only rows played inline carry the session key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(playback): per-channel M3U history attempts, capability-based Xtream fallback - M3U: the recently-viewed dedupe key now includes the channel id, so a second row of the same URL defers its own write (its session key) and is recorded when it plays after the first row failed. - Xtream late write: key uncached content by Xtream id per supportsXtreamSqliteDataSource (the data-source factory's contract), not by a generic Electron bridge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: 4gray <fourgray@proton.me> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
380 lines
14 KiB
TypeScript
380 lines
14 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
||
import { join } from 'node:path';
|
||
import type { Page } from '@playwright/test';
|
||
import { expect, test } from './fixtures';
|
||
|
||
/**
|
||
* DASH + ClearKey playback (offline fixture, no network).
|
||
*
|
||
* The fixture host is virtual: every request to it is fulfilled from
|
||
* `fixtures/dash/` via route interception, including HTTP Range requests
|
||
* (Shaka fetches the init segment and sidx via byte ranges).
|
||
*/
|
||
|
||
const FIXTURE_DIR = join(__dirname, 'fixtures/dash');
|
||
const FIXTURE_HOST = 'https://dash-fixture.local';
|
||
|
||
const CLEARKEY_KID = '00112233445566778899aabbccddeeff';
|
||
const CLEARKEY_KEY = 'ffeeddccbbaa99887766554433221100';
|
||
// Regression for #1466: accept standard Base64 JSON without padding in PWA.
|
||
const CLEARKEY_LICENSE = JSON.stringify({
|
||
keys: [
|
||
{
|
||
kty: 'oct',
|
||
kid: Buffer.from(CLEARKEY_KID, 'hex')
|
||
.toString('base64')
|
||
.replace(/=+$/, ''),
|
||
k: Buffer.from(CLEARKEY_KEY, 'hex')
|
||
.toString('base64')
|
||
.replace(/=+$/, ''),
|
||
},
|
||
],
|
||
type: 'temporary',
|
||
});
|
||
|
||
const DASH_PLAYLIST = [
|
||
'#EXTM3U',
|
||
'#EXTINF:-1 tvg-id="ck-dash" group-title="DASH",ClearKey DASH',
|
||
'#KODIPROP:inputstream.adaptive.license_type=clearkey',
|
||
`#KODIPROP:inputstream.adaptive.license_key=${CLEARKEY_LICENSE}`,
|
||
`${FIXTURE_HOST}/clearkey.mpd`,
|
||
'#EXTINF:-1 tvg-id="clear-dash" group-title="DASH",Clear DASH',
|
||
`${FIXTURE_HOST}/clear.mpd`,
|
||
'#EXTINF:-1 tvg-id="wv-dash" group-title="DASH",Widevine DASH',
|
||
'#KODIPROP:inputstream.adaptive.license_type=com.widevine.alpha',
|
||
'#KODIPROP:inputstream.adaptive.license_key=https://license.example.com/wv',
|
||
`${FIXTURE_HOST}/clearkey.mpd?widevine=1`,
|
||
].join('\n');
|
||
|
||
// The inline player starts playback programmatically; without this flag the
|
||
// bundled Chromium blocks play() before a user gesture reaches the video.
|
||
// The Angular service worker must be blocked: requests going through it
|
||
// bypass Playwright route interception, so the virtual fixture host would
|
||
// never resolve.
|
||
test.use({
|
||
launchOptions: {
|
||
args: ['--autoplay-policy=no-user-gesture-required'],
|
||
},
|
||
serviceWorkers: 'block',
|
||
});
|
||
|
||
// ClearKey EME + VP9 support is only deterministic in Chromium among the
|
||
// bundled Playwright browsers (WebKit lacks ClearKey); the Electron e2e suite
|
||
// covers the real desktop runtime.
|
||
test.skip(
|
||
({ browserName }) => browserName !== 'chromium',
|
||
'DASH ClearKey coverage targets Chromium'
|
||
);
|
||
|
||
test.beforeEach(async ({ page }) => {
|
||
await page.addInitScript(() => {
|
||
const play = HTMLMediaElement.prototype.play;
|
||
HTMLMediaElement.prototype.play = function () {
|
||
// Keep real decoding while avoiding the host's audio-output clock.
|
||
// Muting must happen before play, including replacement players.
|
||
this.muted = true;
|
||
return play.call(this);
|
||
};
|
||
});
|
||
});
|
||
|
||
async function serveDashFixtures(page: Page): Promise<void> {
|
||
await page.route(`${FIXTURE_HOST}/**`, async (route) => {
|
||
const url = new URL(route.request().url());
|
||
let body: Buffer;
|
||
try {
|
||
body = readFileSync(join(FIXTURE_DIR, url.pathname.slice(1)));
|
||
} catch {
|
||
await route.fulfill({ status: 404, body: 'not found' });
|
||
return;
|
||
}
|
||
|
||
const contentType = url.pathname.endsWith('.mpd')
|
||
? 'application/dash+xml'
|
||
: 'video/mp4';
|
||
const rangeHeader = route.request().headers()['range'];
|
||
const range = rangeHeader
|
||
? /bytes=(\d+)-(\d+)?/.exec(rangeHeader)
|
||
: null;
|
||
if (!range) {
|
||
await route.fulfill({
|
||
status: 200,
|
||
headers: {
|
||
'Content-Type': contentType,
|
||
'Accept-Ranges': 'bytes',
|
||
},
|
||
body,
|
||
});
|
||
return;
|
||
}
|
||
|
||
const start = Number(range[1]);
|
||
const end = range[2] ? Number(range[2]) : body.length - 1;
|
||
await route.fulfill({
|
||
status: 206,
|
||
headers: {
|
||
'Content-Type': contentType,
|
||
'Accept-Ranges': 'bytes',
|
||
'Content-Range': `bytes ${start}-${end}/${body.length}`,
|
||
},
|
||
body: body.subarray(start, end + 1),
|
||
});
|
||
});
|
||
}
|
||
|
||
async function importDashPlaylist(page: Page): Promise<void> {
|
||
await page.goto('/');
|
||
await page.getByRole('button', { name: 'Add playlist' }).click();
|
||
const dialog = page.locator('mat-dialog-container');
|
||
await expect(dialog).toBeVisible();
|
||
await dialog.getByRole('radio', { name: /Raw m3u text/i }).click();
|
||
await dialog.locator('textarea').fill(DASH_PLAYLIST);
|
||
await Promise.all([
|
||
page.waitForURL(/\/workspace\/playlists\/.+\/all$/),
|
||
dialog.getByRole('button', { name: 'Import', exact: true }).click(),
|
||
]);
|
||
await expect(page.getByText('3 channels')).toBeVisible();
|
||
}
|
||
|
||
async function expectVideoPlaying(page: Page): Promise<void> {
|
||
const video = page.locator('app-web-player-view video').first();
|
||
await expect(video).toBeVisible({ timeout: 15_000 });
|
||
await expect
|
||
.poll(
|
||
() =>
|
||
video.evaluate(
|
||
(element: HTMLVideoElement) => element.currentTime
|
||
),
|
||
{ timeout: 20_000 }
|
||
)
|
||
.toBeGreaterThan(0.5);
|
||
await expect(
|
||
page.locator('[data-test-id="playback-diagnostic-banner"]')
|
||
).toBeHidden();
|
||
}
|
||
|
||
test('@web @m3u @dash ClearKey and clear DASH channels play inline', async ({
|
||
page,
|
||
}) => {
|
||
await serveDashFixtures(page);
|
||
await importDashPlaylist(page);
|
||
|
||
await page.getByText('1. ClearKey DASH').click();
|
||
await expectVideoPlaying(page);
|
||
|
||
const clearKeyVideo = await page
|
||
.locator('app-web-player-view video')
|
||
.first()
|
||
.elementHandle();
|
||
if (!clearKeyVideo) {
|
||
throw new Error('Missing playing ClearKey video');
|
||
}
|
||
await page.getByText('2. Clear DASH').click();
|
||
// The new source mounts asynchronously; never accept the old video's time.
|
||
await page.waitForFunction(
|
||
(previous) => !previous.isConnected,
|
||
clearKeyVideo
|
||
);
|
||
await expectVideoPlaying(page);
|
||
});
|
||
|
||
test('@web @m3u @dash ClearKey reopens from recent and favorites collections', async ({
|
||
page,
|
||
}) => {
|
||
// Five cold loads of the dev-served app (import + four collection routes)
|
||
// cost ~6 s each on the CI runner, so the default 30 s budget expired on
|
||
// the last route (#1630). Sized like the other multi-load specs.
|
||
test.setTimeout(90_000);
|
||
await serveDashFixtures(page);
|
||
await importDashPlaylist(page);
|
||
await page.getByText('1. ClearKey DASH').click();
|
||
await expectVideoPlaying(page);
|
||
// Recent history records the channel once it has played two seconds.
|
||
await expect
|
||
.poll(
|
||
() =>
|
||
page
|
||
.locator('app-web-player-view video')
|
||
.first()
|
||
.evaluate(
|
||
(element: HTMLVideoElement) => element.currentTime
|
||
),
|
||
{ timeout: 20_000 }
|
||
)
|
||
.toBeGreaterThan(2.5);
|
||
const playlistUrl = page.url().replace(/\/all$/, '');
|
||
const channel = page.locator('.channel-list-item').filter({
|
||
hasText: '1. ClearKey DASH',
|
||
});
|
||
await channel.locator('.favorite-button').click();
|
||
await expect(channel.locator('.favorite-button mat-icon')).toHaveText(
|
||
'star'
|
||
);
|
||
|
||
for (const route of [
|
||
`${playlistUrl}/recent`,
|
||
`${playlistUrl}/favorites`,
|
||
'/workspace/global-recent',
|
||
'/workspace/global-favorites',
|
||
]) {
|
||
// Full navigation also proves persisted channels survive a cold load.
|
||
await page.goto(route);
|
||
if (route.startsWith('/workspace/global-')) {
|
||
const allPlaylists = page
|
||
.locator('.scope-toggle')
|
||
.getByRole('radio', { name: 'All playlists' });
|
||
await allPlaylists.click();
|
||
// The global routes default to the active playlist's scope; make
|
||
// sure the toggle took before waiting for a row only "All
|
||
// playlists" can show, or a lost click surfaces as a missing row.
|
||
await expect(allPlaylists).toBeChecked();
|
||
}
|
||
const collection = page.locator('app-unified-live-tab');
|
||
await collection
|
||
.locator('.channel-name')
|
||
.filter({
|
||
hasText: 'ClearKey DASH',
|
||
})
|
||
.click();
|
||
await expectVideoPlaying(page);
|
||
}
|
||
});
|
||
|
||
test('@web @m3u @dash unsupported DRM shows the encryption diagnostic', async ({
|
||
page,
|
||
}) => {
|
||
await serveDashFixtures(page);
|
||
await importDashPlaylist(page);
|
||
|
||
await page.getByText('3. Widevine DASH').click();
|
||
|
||
const banner = page.locator('[data-test-id="playback-diagnostic-banner"]');
|
||
await expect(banner).toBeVisible({ timeout: 15_000 });
|
||
await expect(banner).toContainText(
|
||
'This player does not support the stream’s DRM configuration.'
|
||
);
|
||
await banner.locator('summary').click();
|
||
const details = banner.locator(
|
||
'[data-test-id="playback-diagnostic-details"]'
|
||
);
|
||
await expect(details).toContainText('DRM declared by source');
|
||
await expect(details).toContainText('Widevine');
|
||
await expect(
|
||
banner.locator('[data-test-id="playback-fallback-mpv"]')
|
||
).toHaveCount(0);
|
||
await expect(
|
||
banner.locator('[data-test-id="playback-fallback-vlc"]')
|
||
).toHaveCount(0);
|
||
await expect(
|
||
banner.locator('[data-test-id^="playback-recommendation-"]')
|
||
).toHaveCount(0);
|
||
});
|
||
|
||
test('@web @m3u @dash manifest DRM and codecs survive a startup failure', async ({
|
||
page,
|
||
}) => {
|
||
await serveDashFixtures(page);
|
||
let manifestRequests = 0;
|
||
const body = readFileSync(
|
||
join(FIXTURE_DIR, 'clear.mpd'),
|
||
'utf8'
|
||
).replaceAll(
|
||
'<Representation ',
|
||
'<ContentProtection schemeIdUri="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"/>' +
|
||
'<ContentProtection schemeIdUri="urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95"/>' +
|
||
'<!-- private-license-marker -->' +
|
||
'<Representation '
|
||
);
|
||
await page.route(`${FIXTURE_HOST}/clear.mpd`, async (route) => {
|
||
manifestRequests += 1;
|
||
await route.fulfill({
|
||
status: 200,
|
||
contentType: 'application/dash+xml',
|
||
body,
|
||
});
|
||
});
|
||
await importDashPlaylist(page);
|
||
await page.getByText('2. Clear DASH').click();
|
||
const banner = page.locator('[data-test-id="playback-diagnostic-banner"]');
|
||
await expect(banner).toBeVisible({ timeout: 20_000 });
|
||
await banner.locator('summary').click();
|
||
const details = banner.locator(
|
||
'[data-test-id="playback-diagnostic-details"]'
|
||
);
|
||
await expect(details).toContainText('Widevine, PlayReady');
|
||
await expect(details).toContainText('vp09.00.11.08.01.02.02.02.00');
|
||
await expect(details).toContainText('opus');
|
||
await expect(details).not.toContainText('private-license-marker');
|
||
expect(manifestRequests).toBe(1);
|
||
});
|
||
|
||
test('@web @m3u @dash segment failures show their stage and preserve codecs', async ({
|
||
page,
|
||
context,
|
||
}) => {
|
||
await serveDashFixtures(page);
|
||
await page.route(`${FIXTURE_HOST}/clear-video.mp4`, (route) =>
|
||
route.fulfill({ status: 403, body: 'private-response-marker' })
|
||
);
|
||
await importDashPlaylist(page);
|
||
await page.getByText('2. Clear DASH').click();
|
||
const banner = page.locator('[data-test-id="playback-diagnostic-banner"]');
|
||
await expect(banner).toBeVisible({ timeout: 20_000 });
|
||
await banner.locator('summary').click();
|
||
const details = banner.locator(
|
||
'[data-test-id="playback-diagnostic-details"]'
|
||
);
|
||
await expect(details).toContainText('Media segment loading');
|
||
await expect(details).toContainText('vp09.00.11.08.01.02.02.02.00');
|
||
await expect(details).toContainText('HTTP 403');
|
||
await expect(details).not.toContainText('private-response-marker');
|
||
await expect(details).not.toContainText('DRM declared by source');
|
||
await expect(banner).toContainText(
|
||
'The server denied access to the media segments.'
|
||
);
|
||
await expect(banner).not.toContainText(/token.*expired/i);
|
||
await context.grantPermissions(['clipboard-read', 'clipboard-write']);
|
||
const copy = banner.getByRole('button', {
|
||
name: 'Copy diagnostics',
|
||
exact: true,
|
||
});
|
||
await copy.click();
|
||
await expect(
|
||
banner.locator('[data-test-id="playback-copy-diagnostic-status"]')
|
||
).toHaveText('Diagnostics copied');
|
||
const reportText = await page.evaluate(() =>
|
||
navigator.clipboard.readText()
|
||
);
|
||
expect(JSON.parse(reportText)).toMatchObject({
|
||
app: 'IPTVnator',
|
||
engine: 'shaka',
|
||
stage: 'segment',
|
||
httpStatus: 403,
|
||
videoCodecs: ['vp09.00.11.08.01.02.02.02.00'],
|
||
});
|
||
for (const secret of [
|
||
'private-response-marker',
|
||
FIXTURE_HOST,
|
||
'sourceUrl',
|
||
]) {
|
||
expect(reportText).not.toContain(secret);
|
||
}
|
||
await page.getByText('3. Widevine DASH').click();
|
||
await expect(banner).toContainText(
|
||
'This player does not support the stream’s DRM configuration.'
|
||
);
|
||
await expect(
|
||
banner.locator('[data-test-id="playback-copy-diagnostic-status"]')
|
||
).toBeEmpty();
|
||
await copy.click();
|
||
const next = JSON.parse(
|
||
await page.evaluate(() => navigator.clipboard.readText())
|
||
);
|
||
expect(next).toMatchObject({
|
||
code: 'drm-or-encryption',
|
||
drmSystems: ['widevine'],
|
||
});
|
||
expect(next).not.toHaveProperty('httpStatus');
|
||
expect(next).not.toHaveProperty('stage');
|
||
});
|