Add resumable admin deep search

This commit is contained in:
Jonathan Sykes
2026-10-14 01:47:35 +08:00
parent ca10fe6486
commit 58d0e6f140
12 changed files with 600 additions and 22 deletions

View File

@@ -7,7 +7,7 @@ test('parses video renderers into slim cards', () => {
const r = parseSearch(fixture);
expect(r.length).toBe(4);
expect(r[0]).toEqual({
id: 'nQWFzMvCfLE', title: 'What A Beautiful Name - Hillsong Worship', channel: 'Hillsong Worship',
id: 'nQWFzMvCfLE', url: 'https://www.youtube.com/watch?v=nQWFzMvCfLE', title: 'What A Beautiful Name - Hillsong Worship', channel: 'Hillsong Worship',
channelId: 'UC4q12NoPNySbVqwpw4iO5Vg', channelUrl: 'https://www.youtube.com/channel/UC4q12NoPNySbVqwpw4iO5Vg',
duration: 343, thumbnail: 'https://i.ytimg.com/vi/nQWFzMvCfLE/mqdefault.jpg',
});
@@ -60,3 +60,18 @@ test('related HTTP failures and unsupported shapes throw for search fallback', a
expect(() => parseRelated({ error: {} })).toThrow('response shape');
await expect(related('aaaaaaaaaaa', { fetchImpl: async () => ({ ok: false, status: 429 }) })).rejects.toThrow('429');
});
test('channel and playlist browse parses uploads and resolves handle URLs', async () => {
const { browseUploads, parseBrowseVideos } = await import('./innertube.js');
const renderer = { videoRenderer: { videoId: 'abcdefghijk', title: { simpleText: 'Upload' }, ownerText: { runs: [{ text: 'Choir', navigationEndpoint: { browseEndpoint: { browseId: 'UC1234567890123456789012', canonicalBaseUrl: '/@choir' } } }] }, lengthText: { simpleText: '2:10' } } };
expect(parseBrowseVideos({ contents: [{ gridVideoRenderer: { videoId: 'abcdefghijk', title: { simpleText: 'Upload' } } }] })[0].title).toBe('Upload');
const calls = [];
const fetchImpl = async (url, init = {}) => {
calls.push([String(url), init.body && JSON.parse(init.body)]);
if (String(url).includes('/@choir')) return new Response('"browseId":"UC1234567890123456789012"');
return Response.json({ contents: [{ gridVideoRenderer: renderer.videoRenderer }] });
};
const result = await browseUploads('https://www.youtube.com/@choir', { fetchImpl, limit: 5 });
expect(result[0].id).toBe('abcdefghijk');
expect(calls[1][1].browseId).toBe('UU1234567890123456789012');
});