chore(source): retry also blocking errors with different VidSrc TLD

This commit is contained in:
WebStreamr 2025-09-04 11:36:07 +00:00
parent fde6128757
commit af4d0010fb
No known key found for this signature in database
3 changed files with 31 additions and 2 deletions

View file

@ -38,4 +38,20 @@ describe('VidSrc', () => {
expect(await vidSrc.extract(ctx, new URL('https://vidsrc.xyz/embed/movie/tt33043892/1/1'))).toMatchSnapshot();
});
test('blocking issues are retried and fail if no tlds are left', async () => {
const mockAgent = new MockAgent({ enableCallHistory: true });
mockAgent.disableNetConnect();
setGlobalDispatcher(mockAgent);
mockAgent.get('https://vidsrc.xyz')
.intercept({ path: '/embed/movie/tt33043892/1/1' }).reply(403);
mockAgent.get('https://vidsrc.net')
.intercept({ path: '/embed/movie/tt33043892/1/1' }).reply(403);
const fetcher = new Fetcher(winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }));
const vidSrc = new VidSrc(fetcher, ['net', 'xyz']);
expect(await vidSrc.extract(ctx, new URL('https://vidsrc.xyz/embed/movie/tt33043892/1/1'))).toMatchSnapshot();
});
});

View file

@ -1,6 +1,6 @@
import * as cheerio from 'cheerio';
import slugify from 'slugify';
import { NotFoundError, TooManyRequestsError } from '../error';
import { BlockedError, NotFoundError, TooManyRequestsError } from '../error';
import { Context, Format, Meta, NonEmptyArray, UrlResult } from '../types';
import { Fetcher, guessHeightFromPlaylist } from '../utils';
import { Extractor } from './Extractor';
@ -41,7 +41,7 @@ export class VidSrc extends Extractor {
try {
html = await this.fetcher.text(ctx, newUrl);
} catch (error) {
if (error instanceof TooManyRequestsError && tlds.length) {
if (tlds.length && (error instanceof TooManyRequestsError || error instanceof BlockedError)) {
return this.extractUsingRandomTld(ctx, url, meta, tlds);
}

View file

@ -34,6 +34,19 @@ exports[`VidSrc Full Metal Jacket 1`] = `
]
`;
exports[`VidSrc blocking issues are retried and fail if no tlds are left 1`] = `
[
{
"error": [Error],
"format": "unknown",
"isExternal": true,
"label": "VidSrc",
"sourceId": "vidsrc",
"url": "https://vidsrc.xyz/embed/movie/tt33043892/1/1",
},
]
`;
exports[`VidSrc not found 1`] = `[]`;
exports[`VidSrc rate limit issues are retried and fail if no tlds are left 1`] = `