From d6fb4c971b7b79f41e09ec2205831d5ac3ce7afc Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Tue, 30 Sep 2025 14:49:26 +0000 Subject: [PATCH] fix(source): dynamically determine MegaKino base URL --- src/source/MegaKino.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/source/MegaKino.ts b/src/source/MegaKino.ts index 55d15e9..41c9859 100644 --- a/src/source/MegaKino.ts +++ b/src/source/MegaKino.ts @@ -27,9 +27,12 @@ export class MegaKino extends Source { public async handleInternal(ctx: Context, _type: string, id: Id): Promise { const imdbId = await getImdbId(ctx, this.fetcher, id); - const cookie = await this.getCookie(ctx); + const tokenResponse = await this.fetcher.fetch(ctx, new URL('/?yg=token', this.baseUrl), { method: 'HEAD' }); - const pageUrl = await this.fetchPageUrl(ctx, imdbId, cookie); + const cookie = Cookie.parse(tokenResponse.headers['set-cookie'] as string) as Cookie; + const baseUrl = new URL('/', tokenResponse.url); + + const pageUrl = await this.fetchPageUrl(ctx, baseUrl, imdbId, cookie); if (!pageUrl) { return []; } @@ -48,9 +51,7 @@ export class MegaKino extends Source { ); }; - private fetchPageUrl = async (ctx: Context, imdbId: ImdbId, cookie: Cookie): Promise => { - const postUrl = new URL(this.baseUrl); - + private fetchPageUrl = async (ctx: Context, postUrl: URL, imdbId: ImdbId, cookie: Cookie): Promise => { const form = new URLSearchParams(); form.append('do', 'search'); form.append('subaction', 'search'); @@ -75,10 +76,4 @@ export class MegaKino extends Source { .map((_i, el) => new URL($(el).attr('href') as string)) .get(0); }; - - private getCookie = async (ctx: Context): Promise => { - const headers = await this.fetcher.head(ctx, new URL('/?yg=token', this.baseUrl)) as Record; - - return Cookie.parse(headers['set-cookie'] as string) as Cookie; - }; }