62 lines
2 KiB
TypeScript
62 lines
2 KiB
TypeScript
import * as cheerio from 'cheerio';
|
|
import { ContentType } from 'stremio-addon-sdk';
|
|
import { Context, CountryCode } from '../types';
|
|
import { Fetcher, getImdbId, Id, ImdbId } from '../utils';
|
|
import { Source, SourceResult } from './Source';
|
|
|
|
export class StreamKiste extends Source {
|
|
public readonly id = 'streamkiste';
|
|
|
|
public readonly label = 'StreamKiste';
|
|
|
|
public readonly contentTypes: ContentType[] = ['series'];
|
|
|
|
public readonly countryCodes: CountryCode[] = [CountryCode.de];
|
|
|
|
public readonly baseUrl = 'https://streamkiste.taxi';
|
|
|
|
private readonly fetcher: Fetcher;
|
|
|
|
public constructor(fetcher: Fetcher) {
|
|
super();
|
|
|
|
this.fetcher = fetcher;
|
|
}
|
|
|
|
public async handleInternal(ctx: Context, _type: string, id: Id): Promise<SourceResult[]> {
|
|
const imdbId = await getImdbId(ctx, this.fetcher, id);
|
|
|
|
const seriesPageUrl = await this.fetchSeriesPageUrl(ctx, imdbId);
|
|
if (!seriesPageUrl) {
|
|
return [];
|
|
}
|
|
|
|
const html = await this.fetcher.text(ctx, seriesPageUrl);
|
|
|
|
const $ = cheerio.load(html);
|
|
|
|
const title = $('meta[property="og:title"]').attr('content') as string;
|
|
|
|
return Promise.all(
|
|
$(`[data-num="${imdbId.season}x${imdbId.episode}"]`)
|
|
.siblings('.mirrors')
|
|
.children('[data-link]')
|
|
.map((_i, el) => new URL(($(el).attr('data-link') as string).replace(/^(https:)?\/\//, 'https://')))
|
|
.toArray()
|
|
.filter(url => !url.host.match(/streamkiste/))
|
|
.map(url => ({ countryCode: CountryCode.de, referer: seriesPageUrl, title: `${title.trim()} ${imdbId.season}x${imdbId.episode}`, url })),
|
|
);
|
|
};
|
|
|
|
private fetchSeriesPageUrl = async (ctx: Context, imdbId: ImdbId): Promise<URL | undefined> => {
|
|
const html = await this.fetcher.text(ctx, new URL(`/?story=${imdbId.id}&do=search&subaction=search`, this.baseUrl));
|
|
|
|
const $ = cheerio.load(html);
|
|
|
|
const url = $('.res_item a[href]:first')
|
|
.map((_i, el) => $(el).attr('href'))
|
|
.get(0);
|
|
|
|
return url !== undefined ? new URL(url) : url;
|
|
};
|
|
}
|