Skip to content

Commit 474c157

Browse files
authored
Merge pull request #178 from koikiss-dev/yako-fin
Fix routes and scrapers
2 parents bbcf118 + c69166e commit 474c157

File tree

5 files changed

+152
-92
lines changed

5 files changed

+152
-92
lines changed

src/routes/v1/anime/animeflv/AnimeflvRoutes.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
StatusAnimeflv,
77
OrderAnimeflv,
88
} from "../../../../scraper/sites/anime/animeflv/animeflv_helper";
9+
import { ScraperErrorResponse } from "utils/ScraperError";
910
const r = Router();
1011

1112
//anime info
@@ -16,8 +17,9 @@ r.get("/anime/flv/name/:name", async (req, res) => {
1617
const animeInfo = await flv.GetItemInfo(name);
1718
res.send(animeInfo);
1819
} catch (error) {
19-
console.log(error);
20-
res.status(500).send(error);
20+
if (error instanceof ScraperErrorResponse) {
21+
res.status(404).send(error);
22+
}
2123
}
2224
});
2325

@@ -29,16 +31,17 @@ r.get("/anime/flv/episode/:episode", async (req, res) => {
2931
const animeInfo = await flv.GetEpisodeServers(episode);
3032
res.send(animeInfo);
3133
} catch (error) {
32-
console.log(error);
33-
res.status(500).send(error);
34+
if (error instanceof ScraperErrorResponse) {
35+
res.status(404).send(error);
36+
}
3437
}
3538
});
3639

3740
//filter
3841
r.get("/anime/flv/filter", async (req, res) => {
3942
try {
4043
const gen = req.query.gen as Genres;
41-
const date = req.query.date as string;
44+
const year = req.query.year as string;
4245
const type = req.query.type as TypeAnimeflv;
4346
const status = req.query.status as StatusAnimeflv;
4447
const ord = req.query.ord as OrderAnimeflv;
@@ -48,17 +51,18 @@ r.get("/anime/flv/filter", async (req, res) => {
4851
const flv = new AnimeFlv();
4952
const animeInfo = await flv.GetItemByFilter(
5053
gen,
51-
date,
54+
year,
5255
type,
5356
status,
5457
ord,
5558
page,
56-
title,
59+
title
5760
);
5861
res.send(animeInfo);
5962
} catch (error) {
60-
console.log(error);
61-
res.status(500).send(error);
63+
if (error instanceof ScraperErrorResponse) {
64+
res.status(404).send(error);
65+
}
6266
}
6367
});
6468

src/scraper/sites/anime/animeflv/AnimeFlv.ts

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from "axios";
1+
import axios, { AxiosResponse } from "axios";
22
import { load } from "cheerio";
33
import { AnimeMedia, Chronology } from "../../../../types/anime";
44
import { Episode } from "../../../../types/episode";
@@ -15,6 +15,7 @@ import {
1515
AnimeResult,
1616
} from "../../../../types/search";
1717
import { AnimeScraperModel } from "../../../../models/AnimeScraperModel";
18+
import { ScraperErrorResponse } from "utils/ScraperError";
1819

1920
export class AnimeFlv extends AnimeScraperModel {
2021
readonly url = "https://m.animeflv.net";
@@ -72,7 +73,6 @@ export class AnimeFlv extends AnimeScraperModel {
7273
const link = $(e).find("a");
7374
const name = link.text().trim();
7475
const numberEpisode = Number(name.split(" ").slice(-1));
75-
console.log(numberEpisode);
7676
const episode = new Episode();
7777
episode.name = name;
7878
episode.url = `/anime/flv/episode/${link
@@ -89,45 +89,51 @@ export class AnimeFlv extends AnimeScraperModel {
8989
"An error occurred while getting the anime info: invalid name",
9090
error
9191
);
92-
throw new Error(
92+
throw new ScraperErrorResponse(
9393
"An error occurred while getting the anime info: invalid name"
9494
);
9595
}
9696
}
9797

9898
async GetItemByFilter(
9999
gen?: Genres | string,
100-
date?: string,
100+
year?: string,
101101
type?: TypeAnimeflv,
102102
status?: StatusAnimeflv,
103103
ord?: OrderAnimeflv,
104104
page?: number,
105105
title?: string
106106
): Promise<IResultSearch<IAnimeResult>> {
107107
try {
108-
const { data } = await axios.get(`${this.url}/browse`, {
109-
params: {
110-
genres: gen || "all",
111-
year: date || "all",
112-
status: status || "all",
113-
Tipo: type || "all",
114-
order: ord || 1,
115-
page: page || 1,
116-
q: title,
117-
},
118-
});
108+
const { data, request }: AxiosResponse = await axios.get(
109+
`${this.url}/browse`,
110+
{
111+
params: {
112+
page: page,
113+
genre: gen,
114+
year: year,
115+
status: status,
116+
type: type,
117+
order: ord,
118+
q: title,
119+
},
120+
}
121+
);
122+
console.log(request);
119123
const $ = load(data);
120-
const infoList = $("ul.ListAnimes li");
124+
const infoList = $("ul.List-Animes li");
121125
const data_filter = new ResultSearch<IAnimeResult>();
122126
data_filter.results = [];
123127
infoList.each((_i, e) => {
124128
const info = new AnimeResult();
125-
info.name = $(e).find("h3").text().trim();
126-
info.image =
127-
$(e)
128-
.find("a")
129-
.attr("href")
130-
.replace("/anime/", "https://img.animeflv.ws/cover/") + ".jpg";
129+
info.name = $(e).find("h2").text().trim();
130+
info.image = $(e)
131+
.find("img")
132+
.attr("src")
133+
.replace(
134+
"/uploads/animes/",
135+
"https://m.animeflv.net/uploads/animes/"
136+
);
131137
info.url = `/anime/flv/name/${$(e)
132138
.find("a")
133139
.attr("href")
@@ -138,13 +144,17 @@ export class AnimeFlv extends AnimeScraperModel {
138144
return data_filter;
139145
} catch (error) {
140146
console.log("An error occurred while getting the filter values", error);
141-
throw new Error("An error occurred while getting the filter values");
147+
throw new ScraperErrorResponse("An error occurred while getting the filter values");
142148
}
143149
}
144150

145151
async GetEpisodeServers(episode: string): Promise<Episode> {
146152
try {
147153
const { data } = await axios.get(`${this.url}/ver/${episode}`);
154+
/* const test: AxiosResponse = await axios.get(
155+
"https://streamtape.com/e/ybVywBZRXMheQ2/"
156+
);
157+
const $t = load(test.data); */
148158
const $ = load(data);
149159
const title = $("h1").text().trim();
150160
const getLinks = $("script");
@@ -155,6 +165,10 @@ export class AnimeFlv extends AnimeScraperModel {
155165
episodeReturn.num = Number(numberEpisode);
156166
episodeReturn.servers = [];
157167

168+
/* const player = $t("div.plyr__video-wrapper").html();
169+
170+
console.log(player); */
171+
158172
getLinks.each((_i, e) => {
159173
interface VideoObject {
160174
title: string;
@@ -223,7 +237,7 @@ export class AnimeFlv extends AnimeScraperModel {
223237
return episodeReturn;
224238
} catch (error) {
225239
console.log("An error occurred while getting the episode servers", error);
226-
throw new Error("An error occurred while getting the episode servers");
240+
throw new ScraperErrorResponse("An error occurred while getting the episode servers");
227241
}
228242
}
229243

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,63 @@
11
//genres animeflf
22
export enum Genres {
3-
Action = "Acción",
4-
MartialArts = "Artes Marciales",
5-
Adventure = "Aventuras",
6-
Racing = "Carreras",
7-
ScienceFiction = "Ciencia Ficción",
8-
Comedy = "Comedia",
9-
Dementia = "Demencia",
10-
Demons = "Demonios",
11-
Sports = "Deportes",
12-
Drama = "Drama",
13-
Ecchi = "Ecchi",
14-
School = "Escolares",
15-
Space = "Espacial",
16-
Fantasy = "Fantasía",
17-
Harem = "Harem",
18-
Historical = "Histórico",
19-
Kids = "Infantil",
20-
Josei = "Josei",
21-
Games = "Juegos",
22-
Magic = "Magia",
23-
Mecha = "Mecha",
24-
Military = "Militar",
25-
Mystery = "Misterio",
26-
Music = "Música",
27-
Parody = "Parodia",
28-
Police = "Policía",
29-
Psychological = "Psicológico",
30-
SliceOfLife = "Recuentos de la vida",
31-
Romance = "Romance",
32-
Samurai = "Samurai",
33-
Seinen = "Seinen",
34-
Shoujo = "Shoujo",
35-
Shounen = "Shounen",
36-
Supernatural = "Sobrenatural",
37-
Superpowers = "Superpoderes",
38-
Suspense = "Suspenso",
39-
Horror = "Terror",
40-
Vampires = "Vampiros",
41-
Yaoi = "Yaoi",
42-
Yuri = "Yuri",
3+
Action = "accion",
4+
MartialArts = "artes-marciales",
5+
Adventure = "aventura",
6+
Racing = "carreras",
7+
ScienceFiction = "ciencia-ficcion",
8+
Comedy = "comedia",
9+
Dementia = "demencia",
10+
Demons = "demonios",
11+
Sports = "deportes",
12+
Drama = "drama",
13+
Ecchi = "ecchi",
14+
School = "escolares",
15+
Space = "espacial",
16+
Fantasy = "fantasia",
17+
Harem = "harem",
18+
Historical = "historico",
19+
Kids = "infantil",
20+
Josei = "josei",
21+
Games = "juegos",
22+
Magic = "magia",
23+
Mecha = "mecha",
24+
Military = "militar",
25+
Mystery = "misterio",
26+
Music = "musica",
27+
Parody = "parodia",
28+
Police = "policia",
29+
Psychological = "psicologico",
30+
SliceOfLife = "recuentos-de-la-vida",
31+
Romance = "romance",
32+
Samurai = "samurai",
33+
Seinen = "seinen",
34+
Shoujo = "shoujo",
35+
Shounen = "shounen",
36+
Supernatural = "sobrenatural",
37+
Superpowers = "superpoderes",
38+
Suspense = "suspenso",
39+
Horror = "terror",
40+
Vampires = "vampiros",
41+
Yaoi = "yaoi",
42+
Yuri = "yuri",
4343
}
4444

4545
export enum StatusAnimeflv {
46-
OnGoing = "En emision",
47-
Finished = "Finalizado",
48-
Upcoming = "Próximamente",
46+
OnGoing = "1",
47+
Finished = "2",
48+
Upcoming = "3",
4949
}
5050

51-
export type TypeAnimeflv = "all" | 1 | 2 | 3 | 4;
52-
export type OrderAnimeflv = "all" | 1 | 2 | 3 | 4 | 5;
51+
export enum TypeAnimeflv {
52+
TV = "tv",
53+
MOVIE = "movie",
54+
SPECIAL = "special",
55+
OVA = "ova",
56+
}
57+
export enum OrderAnimeflv {
58+
DEFAULT = "default",
59+
UPDATED = "updated",
60+
ADDED = "added",
61+
TITLE = "title",
62+
RATING = "rating",
63+
}

src/test/Animeflv.spec.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
import { AnimeFlv } from "../scraper/sites/anime/animeflv/AnimeFlv";
22
import { AnimeMedia } from "../types/anime";
3-
import { Episode } from "../types/episode";
3+
/* import { Episode } from "../types/episode";
4+
import {
5+
Genres,
6+
StatusAnimeflv,
7+
} from "../scraper/sites/anime/animeflv/animeflv_helper"; */
48
import {
59
Genres,
610
StatusAnimeflv,
711
} from "../scraper/sites/anime/animeflv/animeflv_helper";
812

9-
describe("AnimeFlv", () => {
13+
describe("AnimeFlv test", () => {
1014
let animeFlv: AnimeFlv;
1115

1216
beforeEach(() => {
1317
animeFlv = new AnimeFlv();
1418
});
1519

16-
it("should get anime info successfully", async () => {
17-
const animeInfo: AnimeMedia =
18-
await animeFlv.GetItemInfo("25jigen-no-ririsa");
19-
expect(animeInfo.name).toBe("Wonder Egg Priority");
20-
expect(animeInfo.alt_names).toContain("ワンダーエッグ・プライオリティ");
21-
expect(animeInfo.image.url).toContain(".jpg");
22-
expect(animeInfo.status).toBe("Finalizado");
23-
expect(animeInfo.synopsis?.length).toBeGreaterThan(0);
24-
expect(animeInfo.chronology?.length).toBeGreaterThan(0);
25-
expect(animeInfo.genres?.length).toBeGreaterThan(0);
26-
expect(animeInfo.episodes?.length).toBeGreaterThan(0);
20+
test("should get anime info successfully", async () => {
21+
const animeInfo: AnimeMedia = await animeFlv.GetItemInfo("horimiya-piece");
22+
23+
const alt_names_expected: string[] = ["Horimiya: Piece"];
24+
const genres_expected: string[] = ["Escolares", "Romance", "Shounen"];
25+
26+
expect(animeInfo.name).toBe("Horimiya: Piece");
27+
expect(animeInfo.alt_names).toEqual(
28+
expect.arrayContaining(alt_names_expected)
29+
);
30+
expect(animeInfo.image.url).toContain(".jp");
31+
expect(animeInfo.synopsis).toBe(
32+
"Historias del manga no adaptadas en el anime principal."
33+
);
34+
expect(animeInfo.chronology?.length).toBeGreaterThanOrEqual(0);
35+
expect(animeInfo.genres).toEqual(expect.arrayContaining(genres_expected));
36+
expect(animeInfo.episodes?.length).toBeGreaterThanOrEqual(12);
2737
});
2838

2939
it("should filter anime successfully", async () => {
@@ -38,6 +48,18 @@ describe("AnimeFlv", () => {
3848
expect(result.results.length).toBeGreaterThan(0);
3949
});
4050

51+
/* it("should filter anime successfully", async () => {
52+
const result = await animeFlv.GetItemByFilter(
53+
Genres.Action,
54+
"all",
55+
"all",
56+
StatusAnimeflv.OnGoing,
57+
1,
58+
1
59+
);
60+
expect(result.results.length).toBeGreaterThan(0);
61+
});
62+
4163
it("should get episode servers successfully", async () => {
4264
const episode: Episode = await animeFlv.GetEpisodeServers(
4365
"wonder-egg-priority-01"
@@ -46,5 +68,5 @@ describe("AnimeFlv", () => {
4668
expect(episode.url).toContain("/anime/flv/episode/wonder-egg-priority-01");
4769
expect(episode.num).toBe(1);
4870
expect(episode?.servers?.length).toBeGreaterThan(0);
49-
});
71+
}); */
5072
});

src/utils/ScraperError.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { AxiosError } from "axios";
2+
3+
export class ScraperErrorResponse extends AxiosError {
4+
constructor(message: string, name?: string) {
5+
super(message);
6+
this.name = name || "Server error";
7+
this.stack = null;
8+
}
9+
}

0 commit comments

Comments
 (0)