fix(source): move countryCode filtering into central place
This commit is contained in:
parent
12ac42ef5f
commit
5547fd5486
6 changed files with 24 additions and 31 deletions
|
|
@ -36,9 +36,6 @@ export class CineHDPlus extends Source {
|
|||
const $ = cheerio.load(html);
|
||||
|
||||
const countryCode: CountryCode = ($('.details__langs').html() as string).includes('Latino') ? CountryCode.mx : CountryCode.es;
|
||||
if (!(countryCode in ctx.config)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const title = $('meta[property="og:title"]').attr('content') as string;
|
||||
|
||||
|
|
|
|||
|
|
@ -58,19 +58,15 @@ export class Cuevana extends Source {
|
|||
return [];
|
||||
}
|
||||
|
||||
const isLatino = elText.includes('Latino');
|
||||
|
||||
if (isLatino && CountryCode.mx in ctx.config) {
|
||||
if (elText.includes('Latino')) {
|
||||
return $('[data-tr], [data-video]', el)
|
||||
.map((_i, el) => ({ countryCode: CountryCode.mx, title, url: new URL($(el).attr('data-tr') ?? $(el).attr('data-video') as string) }))
|
||||
.toArray();
|
||||
} else if (!isLatino && CountryCode.es in ctx.config) {
|
||||
return $('[data-tr], [data-video]', el)
|
||||
.map((_i, el) => ({ countryCode: CountryCode.es, title, url: new URL($(el).attr('data-tr') ?? $(el).attr('data-video') as string) }))
|
||||
.toArray();
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $('[data-tr], [data-video]', el)
|
||||
.map((_i, el) => ({ countryCode: CountryCode.es, title, url: new URL($(el).attr('data-tr') ?? $(el).attr('data-video') as string) }))
|
||||
.toArray();
|
||||
})
|
||||
.toArray();
|
||||
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ export class HomeCine extends Source {
|
|||
return $('.les-content a')
|
||||
.map((_i, el) => {
|
||||
let countryCode: CountryCode;
|
||||
if ($(el).text().toLowerCase().includes('latino') && CountryCode.mx in ctx.config) {
|
||||
if ($(el).text().toLowerCase().includes('latino')) {
|
||||
countryCode = CountryCode.mx;
|
||||
} else if ($(el).text().toLowerCase().includes('castellano') && CountryCode.es in ctx.config) {
|
||||
} else if ($(el).text().toLowerCase().includes('castellano')) {
|
||||
countryCode = CountryCode.es;
|
||||
} else {
|
||||
return [];
|
||||
|
|
|
|||
|
|
@ -39,23 +39,23 @@ export abstract class Source {
|
|||
public async handle(ctx: Context, type: ContentType, id: Id): Promise<(SourceResult[])> {
|
||||
const cacheKey = `${this.id}_${id.toString()}`;
|
||||
|
||||
let sourceResults = await this.sourceResultCache.get<SourceResult[]>(cacheKey);
|
||||
if (sourceResults) {
|
||||
return sourceResults.map(sourceResult => ({ ...sourceResult, url: new URL(sourceResult.url) }));
|
||||
}
|
||||
let sourceResults = (await this.sourceResultCache.get<SourceResult[]>(cacheKey))
|
||||
?.map(sourceResult => ({ ...sourceResult, url: new URL(sourceResult.url) }));
|
||||
|
||||
try {
|
||||
sourceResults = await this.handleInternal(ctx, type, id);
|
||||
} catch (error) {
|
||||
if (error instanceof NotFoundError) {
|
||||
sourceResults = [];
|
||||
} else {
|
||||
throw error;
|
||||
if (!sourceResults) {
|
||||
try {
|
||||
sourceResults = await this.handleInternal(ctx, type, id);
|
||||
} catch (error) {
|
||||
if (error instanceof NotFoundError) {
|
||||
sourceResults = [];
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
await this.sourceResultCache.set<SourceResult[]>(cacheKey, sourceResults);
|
||||
}
|
||||
|
||||
await this.sourceResultCache.set<SourceResult[]>(cacheKey, sourceResults);
|
||||
|
||||
return sourceResults;
|
||||
return sourceResults.filter(sourceResult => sourceResult.countryCode in ctx.config);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ export class VerHdLink extends Source {
|
|||
return $('._player-mirrors')
|
||||
.map((_i, el) => {
|
||||
let countryCode: CountryCode;
|
||||
if ($(el).hasClass('latino') && 'mx' in ctx.config) {
|
||||
if ($(el).hasClass('latino')) {
|
||||
countryCode = CountryCode.mx;
|
||||
} else if ($(el).hasClass('castellano') && 'es' in ctx.config) {
|
||||
} else if ($(el).hasClass('castellano')) {
|
||||
countryCode = CountryCode.es;
|
||||
} else {
|
||||
return [];
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ describe('resolve', () => {
|
|||
test('returns ytId instead of url for YouTube video', async () => {
|
||||
const streamResolver = new StreamResolver(logger, new ExtractorRegistry(logger, createExtractors(fetcher)));
|
||||
|
||||
const streams = await streamResolver.resolve(ctx, [primeWire], 'movie', new ImdbId('tt0069293', undefined, undefined));
|
||||
const streams = await streamResolver.resolve({ ...ctx, config: { ...ctx.config, en: 'on' } }, [primeWire], 'movie', new ImdbId('tt0069293', undefined, undefined));
|
||||
expect(streams.ttl).not.toBeUndefined();
|
||||
expect(streams.streams).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue