mirror of
https://github.com/vega-org/vega-providers.git
synced 2026-06-19 13:07:44 +00:00
fix: update animetsu and movies4u providers
This commit is contained in:
+84
-58
@@ -8,15 +8,33 @@ export const getMeta = async function ({
|
||||
providerContext: ProviderContext;
|
||||
}): Promise<Info> {
|
||||
try {
|
||||
const { axios } = providerContext;
|
||||
const baseUrl = "https://backend.animetsu.to";
|
||||
const url = `${baseUrl}/api/anime/info/${link}`;
|
||||
const { axios, openWebView, commonHeaders } = providerContext;
|
||||
const baseUrl = "https://animetsu.net";
|
||||
const url = `${baseUrl}/v2/api/anime/${link}`;
|
||||
|
||||
const res = await axios.get(url, {
|
||||
headers: {
|
||||
Referer: "https://animetsu.to/",
|
||||
},
|
||||
});
|
||||
let cookies: string | undefined;
|
||||
let res: any;
|
||||
try {
|
||||
res = await axios.get(url, {
|
||||
headers: { ...commonHeaders, Referer: baseUrl },
|
||||
});
|
||||
} catch (error: any) {
|
||||
if (error.response?.status === 403) {
|
||||
const wafResult = await openWebView(baseUrl, {
|
||||
title: "Solve the captcha below and click done",
|
||||
description: "Required to bypass Animetsu anti-bot protection.",
|
||||
headers: { ...commonHeaders, Referer: baseUrl },
|
||||
force: true,
|
||||
waitForCookie: "cf_clearance",
|
||||
});
|
||||
cookies = wafResult.cookies;
|
||||
res = await axios.get(url, {
|
||||
headers: { ...commonHeaders, Referer: baseUrl, Cookie: cookies },
|
||||
});
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
const data = res.data;
|
||||
|
||||
const meta = {
|
||||
@@ -24,12 +42,12 @@ export const getMeta = async function ({
|
||||
data.title?.english || data.title?.romaji || data.title?.native || "",
|
||||
synopsis: data.description || "",
|
||||
image:
|
||||
data.coverImage?.extraLarge ||
|
||||
data.coverImage?.large ||
|
||||
data.coverImage?.medium ||
|
||||
data.cover_image?.large ||
|
||||
data.cover_image?.medium ||
|
||||
data.cover_image?.small ||
|
||||
"",
|
||||
tags: [data?.format, data?.status, ...(data?.genres || [])].filter(
|
||||
Boolean
|
||||
Boolean,
|
||||
),
|
||||
imdbId: "",
|
||||
type: data.format === "MOVIE" ? "movie" : "series",
|
||||
@@ -37,58 +55,66 @@ export const getMeta = async function ({
|
||||
|
||||
const linkList: Link[] = [];
|
||||
|
||||
// Get episodes data
|
||||
try {
|
||||
const episodesRes = await axios.get(`${baseUrl}/api/anime/eps/${link}`, {
|
||||
headers: {
|
||||
Referer: "https://animetsu.to/",
|
||||
},
|
||||
});
|
||||
const episodes = episodesRes.data;
|
||||
const seasons = data.seasons;
|
||||
if (seasons && seasons.length > 0) {
|
||||
await Promise.all(
|
||||
seasons.map(async (season: any) => {
|
||||
const seasonTitle =
|
||||
season.title?.english ||
|
||||
season.title?.romaji ||
|
||||
season.title?.native;
|
||||
const directLinks: Link["directLinks"] = [];
|
||||
|
||||
if (episodes && episodes.length > 0) {
|
||||
const directLinks: Link["directLinks"] = [];
|
||||
try {
|
||||
const epsRes = await axios.get(
|
||||
`${baseUrl}/api/anime/eps/${season.id}`,
|
||||
{
|
||||
headers: {
|
||||
...commonHeaders,
|
||||
Referer: baseUrl,
|
||||
...(cookies ? { Cookie: cookies } : {}),
|
||||
},
|
||||
},
|
||||
);
|
||||
const episodes = epsRes.data;
|
||||
if (episodes && episodes.length > 0) {
|
||||
episodes.forEach((ep: any) => {
|
||||
directLinks.push({
|
||||
title: `Episode ${ep.number}`,
|
||||
link: `${season.id}:${ep.number}`,
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
// fallback: use total_eps count
|
||||
const total = season.total_eps || 1;
|
||||
for (let i = 1; i <= total; i++) {
|
||||
directLinks.push({
|
||||
title: `Episode ${i}`,
|
||||
link: `${season.id}:${i}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
episodes.forEach((episode: any) => {
|
||||
const title = `Episode ${episode.number}`;
|
||||
const episodeLink = `${link}:${episode.number}`;
|
||||
|
||||
if (episodeLink && title) {
|
||||
directLinks.push({
|
||||
title,
|
||||
link: episodeLink,
|
||||
if (directLinks.length > 0) {
|
||||
linkList.push({
|
||||
title: seasonTitle || meta.title,
|
||||
directLinks,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
linkList.push({
|
||||
title: meta.title,
|
||||
directLinks: directLinks,
|
||||
});
|
||||
} else {
|
||||
// Movie case - single episode
|
||||
linkList.push({
|
||||
title: meta.title,
|
||||
directLinks: [
|
||||
{
|
||||
title: "Movie",
|
||||
link: `${link}:1`,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
// Movie or single-season fallback
|
||||
const total = data.total_eps || 1;
|
||||
const directLinks: Link["directLinks"] = [];
|
||||
for (let i = 1; i <= total; i++) {
|
||||
directLinks.push({
|
||||
title: total === 1 ? "Movie" : `Episode ${i}`,
|
||||
link: `${link}:${i}`,
|
||||
});
|
||||
}
|
||||
} catch (episodeErr) {
|
||||
console.error("Error fetching episodes:", episodeErr);
|
||||
// Fallback for movie or single episode
|
||||
linkList.push({
|
||||
title: meta.title,
|
||||
directLinks: [
|
||||
{
|
||||
title: meta.title,
|
||||
link: `${link}:1`,
|
||||
},
|
||||
],
|
||||
});
|
||||
linkList.push({ title: meta.title, directLinks });
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user