chore(source): determine latest 4KHDHub domain more dynamically
This commit is contained in:
parent
93a098e438
commit
f8f62db174
2 changed files with 13 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ import * as cheerio from 'cheerio';
|
|||
import { BasicAcceptedElems, CheerioAPI } from 'cheerio';
|
||||
import { AnyNode } from 'domhandler';
|
||||
import levenshtein from 'fast-levenshtein';
|
||||
import memoize from 'memoizee';
|
||||
import rot13Cipher from 'rot13-cipher';
|
||||
import { ContentType } from 'stremio-addon-sdk';
|
||||
import { Context, CountryCode, Meta } from '../types';
|
||||
|
|
@ -26,6 +27,11 @@ export class FourKHDHub extends Source {
|
|||
super();
|
||||
|
||||
this.fetcher = fetcher;
|
||||
|
||||
this.getBaseUrl = memoize(this.getBaseUrl, {
|
||||
maxAge: 3600000, // 1 hour
|
||||
normalizer: () => 'baseUrl',
|
||||
});
|
||||
}
|
||||
|
||||
public async handleInternal(ctx: Context, _type: string, id: Id): Promise<SourceResult[]> {
|
||||
|
|
@ -64,7 +70,7 @@ export class FourKHDHub extends Source {
|
|||
private readonly fetchPageUrl = async (ctx: Context, tmdbId: TmdbId): Promise<URL | undefined> => {
|
||||
const [name, year] = await getTmdbNameAndYear(ctx, this.fetcher, tmdbId);
|
||||
|
||||
const searchUrl = new URL(`/?s=${encodeURIComponent(`${name} ${year}`)}`, this.baseUrl);
|
||||
const searchUrl = new URL(`/?s=${encodeURIComponent(`${name} ${year}`)}`, await this.getBaseUrl(ctx));
|
||||
const html = await this.fetcher.text(ctx, searchUrl);
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
|
|
@ -83,7 +89,7 @@ export class FourKHDHub extends Source {
|
|||
|
||||
return levenshtein.get(movieCardTitle, name, { useCollator: true }) < 5;
|
||||
})
|
||||
.map((_i, el) => new URL($(el).attr('href') as string, this.baseUrl))
|
||||
.map(async (_i, el) => new URL($(el).attr('href') as string, await this.getBaseUrl(ctx)))
|
||||
.get(0);
|
||||
};
|
||||
|
||||
|
|
@ -127,4 +133,8 @@ export class FourKHDHub extends Source {
|
|||
|
||||
return new URL(atob(redirectData['o']));
|
||||
}
|
||||
|
||||
private readonly getBaseUrl = async (ctx: Context): Promise<URL> => {
|
||||
return await this.fetcher.getFinalRedirectUrl(ctx, new URL(this.baseUrl));
|
||||
};
|
||||
}
|
||||
|
|
|
|||
1
src/source/__fixtures__/FourKHDHub/head-https:4khdhub.dad
generated
Normal file
1
src/source/__fixtures__/FourKHDHub/head-https:4khdhub.dad
generated
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"date":"Fri, 02 Jan 2026 09:15:12 GMT","content-type":"text/html; charset=UTF-8","connection":"close","server":"cloudflare","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","x-turbo-charged-by":"LiteSpeed","expires":"Thu, 19 Nov 1981 08:52:00 GMT","cache-control":"no-store, must-revalidate","pragma":"no-cache","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=vaTDhRUw77BBpC46sTicG0HdV0%2FfymKjEvNMlQnbEfzogqB4wV0MJCfpxlJM3SG1CQYrHlLmxJTZ0y%2FqjIQ5bMs4W3%2FkMTKoCX97\"}]}","vary":"Accept-Encoding","age":"2950","cf-cache-status":"HIT","last-modified":"Fri, 02 Jan 2026 08:26:02 GMT","cf-ray":"9b79268d5ef99b9b-FRA","alt-svc":"h3=\":443\"; ma=86400"}
|
||||
Loading…
Reference in a new issue