webstreamr-github/src/source/XPrime.ts
2025-09-03 19:55:58 +00:00

44 lines
1.4 KiB
TypeScript

import { ContentType } from 'stremio-addon-sdk';
import { Context, CountryCode } from '../types';
import { Fetcher, getTmdbId, getTmdbNameAndYear, Id } from '../utils';
import { Source, SourceResult } from './Source';
export class XPrime extends Source {
public readonly id = 'xprime';
public readonly label = 'XPrime';
public readonly contentTypes: ContentType[] = ['movie', 'series'];
public readonly countryCodes: CountryCode[] = [CountryCode.en];
public readonly baseUrl = 'https://backend.xprime.tv';
private readonly fetcher: Fetcher;
public constructor(fetcher: Fetcher) {
super();
this.fetcher = fetcher;
}
public async handleInternal(ctx: Context, _type: string, id: Id): Promise<SourceResult[]> {
const tmdbId = await getTmdbId(ctx, this.fetcher, id);
const [name, year] = await getTmdbNameAndYear(ctx, this.fetcher, tmdbId);
if (tmdbId.season) {
const title = `${name} ${tmdbId.season}x${tmdbId.episode}`;
const urlPrimebox = new URL(`/primebox?name=${encodeURIComponent(name)}&year=${year}&season=${tmdbId.season}&episode=${tmdbId.episode}`, this.baseUrl);
return [{ url: urlPrimebox, meta: { countryCodes: [CountryCode.en], title } }];
}
const title = `${name} (${year})`;
const urlPrimebox = new URL(`/primebox?name=${encodeURIComponent(name)}&year=${year}`, this.baseUrl);
return [{ url: urlPrimebox, meta: { countryCodes: [CountryCode.en], title } }];
};
}