mirror of
https://github.com/vega-org/vega-providers.git
synced 2026-04-17 23:51:44 +00:00
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import {EpisodeLink, ProviderContext} from '../types';
|
|
|
|
export const vadapavGetEpisodeLinks = async function ({
|
|
url,
|
|
providerContext,
|
|
}: {
|
|
url: string;
|
|
providerContext: ProviderContext;
|
|
}): Promise<EpisodeLink[]> {
|
|
const {axios, cheerio} = providerContext;
|
|
try {
|
|
const baseUrl = url?.split('/').slice(0, 3).join('/');
|
|
const res = await axios.get(url);
|
|
const html = res.data;
|
|
let $ = cheerio.load(html);
|
|
const episodeLinks: EpisodeLink[] = [];
|
|
|
|
$('.file-entry:not(:contains("Parent Directory"))').map((i, element) => {
|
|
const link = $(element).attr('href');
|
|
if (
|
|
link &&
|
|
($(element).text()?.includes('.mp4') ||
|
|
$(element).text()?.includes('.mkv'))
|
|
) {
|
|
episodeLinks.push({
|
|
title:
|
|
$(element).text()?.match(/E\d+/)?.[0]?.replace('E', 'Episode ') ||
|
|
i + 1 + '. ' + $(element).text()?.replace('.mkv', ''),
|
|
link: baseUrl + link,
|
|
});
|
|
}
|
|
});
|
|
|
|
return episodeLinks;
|
|
} catch (err) {
|
|
return [];
|
|
}
|
|
};
|