Skip to content

Commit

Permalink
fix: 9anime/TMDB and crawling script
Browse files Browse the repository at this point in the history
  • Loading branch information
Eltik committed Sep 28, 2023
1 parent 110fc03 commit 8aa5962
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 42 deletions.
11 changes: 6 additions & 5 deletions anify-backend/src/mappings/impl/anime/nineanime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { load } from "cheerio";
import { env } from "../../../env";
import { Format, Formats, StreamingServers, SubType } from "../../../types/enums";
import Extractor from "../../../helper/extractor";
import Http from "../../../helper/request";
import { isString } from "../../../helper";
import vm from "node:vm";

export default class NineAnime extends AnimeProvider {
override rateLimit = 250;
Expand Down Expand Up @@ -262,13 +265,12 @@ export default class NineAnime extends AnimeProvider {
return await (await this.request(`${this.resolver}/decrypt?query=${encodeURIComponent(query)}&apikey=${this.resolverKey}`, {}, false)).json();
}

/*
// This bypass works. However because it sends requests very quickly in a short amount of time, it causes proxies to get banned very quickly.
override async request(url: string, options: RequestInit = {}, proxyRequest = true): Promise<Response> {
if (url.includes(this.resolver ?? "")) {
return Http.request("ANIME", url, options, false);
}
const proxy = proxyRequest ? ((this.customProxy?.length ?? 0) > 0 ? this.customProxy : Http.getRandomUnbannedProxy()) : undefined;
const proxy = proxyRequest ? ((this.customProxy?.length ?? 0) > 0 ? this.customProxy : Http.getRandomUnbannedProxy("ANIME")) : undefined;

const headers = {
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1",
Expand Down Expand Up @@ -319,7 +321,7 @@ export default class NineAnime extends AnimeProvider {
const code = EvalDecode("${data2}");
data = code;
`,
context
context,
);

const kMatch = context.data.match(/var k='([^']+)'/);
Expand Down Expand Up @@ -347,13 +349,12 @@ export default class NineAnime extends AnimeProvider {

const cookies = req3.headers.get("set-cookie");

console.log(await req3.text())
console.log(await req3.text());

return Http.request("ANIME", url, { headers: { Cookie: cookies ?? "" }, ...options }, proxyRequest, 0, proxy);

//return Http.request(url, { headers: { Cookie: cookies?.join("; ") ?? "" }, ...options }, proxyRequest, 0, proxy);
}
*/

/*
The waf page evals this:
Expand Down
74 changes: 40 additions & 34 deletions anify-backend/src/mappings/impl/information/tmdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,46 @@ export default class TMDB extends InformationProvider<Anime | Manga, AnimeInfo |
if (!data) return undefined;

if (data.ok) {
const info = await data.json();

return {
id: tmdbId,
title: {
english: info.name,
romaji: null,
native: info.original_name,
},
currentEpisode: info.last_episode_to_air?.episode_number,
trailer: null,
duration: info.episode_run_time[0] ?? null,
color: null,
bannerImage: info.backdrop_path ? `https://image.tmdb.org/t/p/w500${info.backdrop_path}` : null,
coverImage: info.poster_path ? `https://image.tmdb.org/t/p/w500${info.poster_path}` : null,
status: null,
format: Format.UNKNOWN,
season: Season.UNKNOWN,
synonyms: [],
description: info.overview,
year: info.first_air_date ? new Date(info.first_air_date).getFullYear() : 0,
totalEpisodes: info.number_of_episodes,
genres: info.genres?.map((genre: { id: number; name: string }) => genre.name),
rating: info.vote_average,
popularity: info.popularity,
countryOfOrigin: info.origin_country[0] ?? null,
tags: [],
relations: [],
artwork: [],
characters: [],
totalChapters: null,
totalVolumes: null,
type: media.type,
} as AnimeInfo;
try {
const info = await data.json();

if (!info) return undefined;

return {
id: tmdbId,
title: {
english: info.name,
romaji: null,
native: info.original_name,
},
currentEpisode: info.last_episode_to_air?.episode_number,
trailer: null,
duration: info.episode_run_time[0] ?? null,
color: null,
bannerImage: info.backdrop_path ? `https://image.tmdb.org/t/p/w500${info.backdrop_path}` : null,
coverImage: info.poster_path ? `https://image.tmdb.org/t/p/w500${info.poster_path}` : null,
status: null,
format: Format.UNKNOWN,
season: Season.UNKNOWN,
synonyms: [],
description: info.overview,
year: info.first_air_date ? new Date(info.first_air_date).getFullYear() : 0,
totalEpisodes: info.number_of_episodes,
genres: info.genres?.map((genre: { id: number; name: string }) => genre.name),
rating: info.vote_average,
popularity: info.popularity,
countryOfOrigin: info.origin_country[0] ?? null,
tags: [],
relations: [],
artwork: [],
characters: [],
totalChapters: null,
totalVolumes: null,
type: media.type,
} as AnimeInfo;
} catch (e) {
return undefined;
}
}

return undefined;
Expand Down
8 changes: 7 additions & 1 deletion anify-backend/src/scripts/crawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,10 @@ async function before() {
}

const type = process.argv.slice(2)?.toString()?.toLowerCase() ?? "anime";
crawl(type === "anime" ? Type.ANIME : type === "manga" ? Type.MANGA : Type.ANIME, type === "anime" ? [Format.TV, Format.TV_SHORT, Format.MOVIE, Format.OVA, Format.ONA, Format.SPECIAL, Format.MUSIC] : type === "manga" ? [Format.MANGA, Format.ONE_SHOT] : type === "novel" ? [Format.NOVEL] : [Format.TV, Format.TV_SHORT, Format.MOVIE, Format.OVA, Format.ONA, Format.SPECIAL, Format.MUSIC]);
crawl(type === "anime" ? Type.ANIME : type === "manga" ? Type.MANGA : Type.ANIME, type === "anime" ? [Format.TV, Format.TV_SHORT, Format.MOVIE, Format.OVA, Format.ONA, Format.SPECIAL, Format.MUSIC] : type === "manga" ? [Format.MANGA, Format.ONE_SHOT] : type === "novel" ? [Format.NOVEL] : [Format.TV, Format.TV_SHORT, Format.MOVIE, Format.OVA, Format.ONA, Format.SPECIAL, Format.MUSIC]).then((data) => {
// Hang infinitely
console.log(data);
console.log("Successfully crawled!");

setInterval(() => {}, 1000);
});
2 changes: 0 additions & 2 deletions anify-backend/src/server/lib/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ export const apiKeyMiddleware = async (req: Request): Promise<boolean> => {
return false;
}

await redis.incr(`apikeys:${key}:requests`);

return true;
};

0 comments on commit 8aa5962

Please sign in to comment.