Skip to content

Commit

Permalink
Merge pull request #162 from koikiss-dev/provider-models
Browse files Browse the repository at this point in the history
feat(provider)!: add provider abstract classes and interfaces
  • Loading branch information
koikiss-dev authored Jun 20, 2024
2 parents cdcd627 + d60ba03 commit 079c249
Show file tree
Hide file tree
Showing 25 changed files with 211 additions and 212 deletions.
8 changes: 8 additions & 0 deletions src/models/AnimeScraperModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { AnimeMedia } from "@animetypes/anime";
import type { Episode } from "@animetypes/episode";
import type { IAnimeResult } from "@animetypes/search";
import { BaseScraperModel } from "./BaseScraperModel";

export abstract class AnimeScraperModel extends BaseScraperModel<AnimeMedia, IAnimeResult> {
public abstract GetEpisodeServers(...args: unknown[]): Promise<Episode>;
}
9 changes: 9 additions & 0 deletions src/models/BaseScraperModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { BaseMedia, BaseResult } from "@animetypes/base";
import type { IResultSearch } from "@animetypes/search";

export abstract class BaseScraperModel<MediaInfoType extends BaseMedia, FilterResultType extends BaseResult> {
public abstract readonly url: string;

public abstract GetItemInfo(item: string): Promise<MediaInfoType>;
public abstract GetItemByFilter(...args: unknown[]): Promise<IResultSearch<FilterResultType>>;
}
6 changes: 6 additions & 0 deletions src/models/MangaScraperModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { MangaMedia, MangaChapter, MangaVolume, IMangaResult } from "@animetypes/manga";
import { BaseScraperModel } from "./BaseScraperModel";

export abstract class MangaScraperModel extends BaseScraperModel<MangaMedia, IMangaResult> {
public abstract GetMangaChapters(...args: unknown[]): Promise<MangaChapter | MangaVolume>
}
4 changes: 2 additions & 2 deletions src/routes/v1/anime/animeblix/AnimeBlixRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const router = Router();
router.get("/anime/animeblix/filter", async (req, res) => {
const { search, type, page, year, genre } = req.query;

const data = await Anime.GetAnimeByFilter(
const data = await Anime.GetItemByFilter(
search as string,
type as unknown as number,
page as unknown as number,
Expand All @@ -21,7 +21,7 @@ router.get("/anime/animeblix/filter", async (req, res) => {
// Anime Info +(Episodes list)
router.get("/anime/animeblix/name/:name", async (req, res) => {
const { name } = req.params;
const data = await Anime.GetAnimeInfo(
const data = await Anime.GetItemInfo(
name.includes("ver-") ? name.replace("ver-", "") : name,
);
res.send(data);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/v1/anime/animeflv/AnimeflvRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ r.get("/anime/flv/name/:name", async (req, res) => {
try {
const { name } = req.params;
const flv = new AnimeFlv();
const animeInfo = await flv.GetAnimeInfo(name);
const animeInfo = await flv.GetItemInfo(name);
res.send(animeInfo);
} catch (error) {
console.log(error);
Expand Down Expand Up @@ -46,7 +46,7 @@ r.get("/anime/flv/filter", async (req, res) => {
const title = req.query.title as string;

const flv = new AnimeFlv();
const animeInfo = await flv.GetAnimeByFilter(
const animeInfo = await flv.GetItemByFilter(
gen,
date,
type,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/v1/anime/animelatinohd/AnimeLatinoHDRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const router = Router();
router.get("/anime/animelatinohd/filter", async (req, res) => {
const { search, type, page, year, genre } = req.query;

const data = await Anime.GetAnimeByFilter(
const data = await Anime.GetItemByFilter(
search as string,
type as unknown as number,
page as unknown as number,
Expand All @@ -20,7 +20,7 @@ router.get("/anime/animelatinohd/filter", async (req, res) => {
// Anime Info +(Episodes list)
router.get("/anime/animelatinohd/name/:name", async (req, res) => {
const { name } = req.params;
const data = await Anime.GetAnimeInfo(name);
const data = await Anime.GetItemInfo(name);
res.send(data);
});

Expand Down
4 changes: 2 additions & 2 deletions src/routes/v1/anime/animevostfr/AnimevostfrRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const router = Router();
router.get("/anime/animevostfr/filter", async (req, res) => {
const { search, type, page, year, genre } = req.query;

const data = await Anime.GetAnimeByFilter(
const data = await Anime.GetItemByFilter(
search as string,
type as unknown as number,
page as unknown as number,
Expand All @@ -20,7 +20,7 @@ router.get("/anime/animevostfr/filter", async (req, res) => {
// Anime Info +(Episodes list)
router.get("/anime/animevostfr/name/:name", async (req, res) => {
const { name } = req.params;
const data = await Anime.GetAnimeInfo(name);
const data = await Anime.GetItemInfo(name);
res.send(data);
});

Expand Down
4 changes: 2 additions & 2 deletions src/routes/v1/anime/wcostream/wcostreamRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const router = Router();

router.get("/anime/wcostream/name/:name", async (req, res) => {
const { name } = req.params;
const data = await Anime.GetAnimeInfo(name);
const data = await Anime.GetItemInfo(name);

res.send(data);
});
Expand All @@ -24,7 +24,7 @@ router.get("/anime/wcostream/episode/:episode", async (req, res) => {

router.get("/anime/wcostream/filter", async (req, res) => {
const { search, page } = req.query;
const data = await Anime.GetAnimeByFilter(
const data = await Anime.GetItemByFilter(
search as string,
page as unknown as number,
);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/v1/anime/zoro/ZoroRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ r.get("/anime/zoro/name/:name", async (req, res) => {
try {
const { name } = req.params;
const zoro = new Zoro();
const animeInfo = await zoro.GetAnimeInfo(name);
const animeInfo = await zoro.GetItemInfo(name);
res.send(animeInfo);
} catch (error) {
console.log(error);
Expand Down Expand Up @@ -41,7 +41,7 @@ r.get("/anime/zoro/filter", async (req, res) => {
const page = req.query.page as string;

const zoro = new Zoro();
const animeInfo = await zoro.GetAnimeByFilter(
const animeInfo = await zoro.GetItemByFilter(
type,
rated,
score,
Expand Down
15 changes: 0 additions & 15 deletions src/scraper/ScraperAnimeModel.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/scraper/sites/anime/animeBlixs/AnimeBlix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type IResultSearch,
type IAnimeSearch,

Check failure on line 9 in src/scraper/sites/anime/animeBlixs/AnimeBlix.ts

View workflow job for this annotation

GitHub Actions / build

Module '"../../../../types/search"' has no exported member 'IAnimeSearch'.
} from "../../../../types/search";
import { AnimeProviderModel } from "../../../ScraperAnimeModel";
import { AnimeScraperModel } from "../../../../models/AnimeScraperModel";
//import { Calendar } from "@animetypes/date";

/** List of Domains
Expand All @@ -20,11 +20,11 @@ import { AnimeProviderModel } from "../../../ScraperAnimeModel";
*
*/

export class AnimeBlix extends AnimeProviderModel {
export class AnimeBlix extends AnimeScraperModel {
readonly url = "https://vwv.animeblix.org";
readonly api = "https://api.animelatinohd.com";

async GetAnimeInfo(anime: string): Promise<Anime> {
async GetItemInfo(anime: string): Promise<Anime> {
try {
const { data } = await axios.get(
`${this.url}/animes/${anime.includes("ver-") ? anime : "ver-" + anime}`
Expand Down Expand Up @@ -165,7 +165,7 @@ export class AnimeBlix extends AnimeProviderModel {
}
}

async GetAnimeByFilter(
async GetItemByFilter(
search?: string,
type?: number,
page?: number,
Expand Down
8 changes: 4 additions & 4 deletions src/scraper/sites/anime/animeflv/AnimeFlv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
type IResultSearch,
type IAnimeSearch,

Check failure on line 15 in src/scraper/sites/anime/animeflv/AnimeFlv.ts

View workflow job for this annotation

GitHub Actions / build

Module '"../../../../types/search"' has no exported member 'IAnimeSearch'.
} from "../../../../types/search";
import { AnimeProviderModel } from "../../../ScraperAnimeModel";
import { AnimeScraperModel } from "../../../../models/AnimeScraperModel";

export class AnimeFlv extends AnimeProviderModel {
export class AnimeFlv extends AnimeScraperModel {
readonly url = "https://animeflv.ws";

async GetAnimeInfo(anime: string): Promise<Anime> {
async GetItemInfo(anime: string): Promise<Anime> {
try {
const { data } = await axios.get(`${this.url}/anime/${anime}`);
const $ = load(data);
Expand Down Expand Up @@ -76,7 +76,7 @@ export class AnimeFlv extends AnimeProviderModel {
}
}

async GetAnimeByFilter(
async GetItemByFilter(
gen?: Genres | string,
date?: string,
type?: TypeAnimeflv,
Expand Down
8 changes: 4 additions & 4 deletions src/scraper/sites/anime/animelatinohd/AnimeLatinoHD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
type IResultSearch,
type IAnimeSearch,
} from "../../../../types/search";
import { AnimeProviderModel } from "../../../ScraperAnimeModel";
import { AnimeScraperModel } from "../../../../models/AnimeScraperModel";

export class AnimeLatinoHD extends AnimeProviderModel {
export class AnimeLatinoHD extends AnimeScraperModel {
readonly url = "https://www.animelatinohd.com";
readonly api = "https://api.animelatinohd.com";

async GetAnimeInfo(anime: string): Promise<Anime> {
async GetItemInfo(anime: string): Promise<Anime> {
try {
const { data } = await axios.get(`${this.url}/anime/${anime}`);
const $ = cheerio.load(data);
Expand Down Expand Up @@ -143,7 +143,7 @@ export class AnimeLatinoHD extends AnimeProviderModel {
}
}

async GetAnimeByFilter(
async GetItemByFilter(
search?: string,
type?: number,
page?: number,
Expand Down
16 changes: 8 additions & 8 deletions src/scraper/sites/anime/animevostfr/Animevostfr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type IResultSearch,
type IAnimeSearch,
} from "../../../../types/search";
import { AnimeProviderModel } from "../../../ScraperAnimeModel";
import { AnimeScraperModel } from "../../../../models/AnimeScraperModel";
//import { Calendar } from "@animetypes/date";

/** List of Domains
Expand All @@ -17,11 +17,11 @@ import { AnimeProviderModel } from "../../../ScraperAnimeModel";
*
*/

export class Animevostfr extends AnimeProviderModel {
export class Animevostfr extends AnimeScraperModel {
readonly url = "https://animevostfr.tv";
readonly api = "https://api.animelatinohd.com";

async GetAnimeInfo(anime: string): Promise<Anime> {
async GetItemInfo(anime: string): Promise<Anime> {
try {
const { data } = await axios.get(`${this.url}/${anime}`);
const $ = cheerio.load(data);
Expand Down Expand Up @@ -120,12 +120,12 @@ export class Animevostfr extends AnimeProviderModel {
"SERVER_VIP"
"SERVER_HYDRAX"
"SERVER_PHOTOSS"
"SERVER_DOWNLOAD"
"SERVER_PHOTOS"
"SERVER_DOWNLOAD"
"SERVER_PHOTOS"
"SERVER_OPEN_LOAD"
"SERVER_OPEN_LOADS"
"SERVER_OPEN_LOADS"
"SERVER_OPEN_CDN"
"SERVER_OPEN_CDNO"
"SERVER_OPEN_CDNO"
"SERVER_PHOTO"
"SERVER_STREAM_MANGO"
"SERVER_RAPID_VIDEO"
Expand Down Expand Up @@ -167,7 +167,7 @@ export class Animevostfr extends AnimeProviderModel {
}
}

async GetAnimeByFilter(
async GetItemByFilter(
search?: string,
type?: number,
page?: number,
Expand Down
8 changes: 4 additions & 4 deletions src/scraper/sites/anime/wcostream/WcoStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
AnimeSearch,
} from "../../../../types/search";
import { UnPacked } from "../../../../types/utils";
import { AnimeProviderModel } from "../../../ScraperAnimeModel";
import { AnimeScraperModel } from "../../../../models/AnimeScraperModel";

/** List of Domains
* https://wcostream.tv
Expand All @@ -36,10 +36,10 @@ axios.defaults.withCredentials = true;
axios.defaults.headers.common["User-Agent"] =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.55";

export class WcoStream extends AnimeProviderModel {
export class WcoStream extends AnimeScraperModel {
readonly url = "https://www.wcostream.tv";

async GetAnimeInfo(anime: string): Promise<Anime> {
async GetItemInfo(anime: string): Promise<Anime> {
try {
const { data } = await axios.get(`${this.url}/anime/${anime}`, {
headers: {
Expand Down Expand Up @@ -222,7 +222,7 @@ export class WcoStream extends AnimeProviderModel {
}
}

async GetAnimeByFilter(
async GetItemByFilter(
search?: string,
page?: number
): Promise<IResultSearch<IAnimeSearch>> {
Expand Down
8 changes: 4 additions & 4 deletions src/scraper/sites/anime/zoro/Zoro.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import axios from "axios";
import { load } from "cheerio";
import { AnimeScraperModel } from "../../../../models/AnimeScraperModel";
import { Anime, Chronology } from "../../../../types/anime";
import { Episode, EpisodeServer } from "../../../../types/episode";
import {
AnimeSearch,
ResultSearch,
type IAnimeSearch,
} from "../../../../types/search";
import { AnimeProviderModel } from "../../../ScraperAnimeModel";

export class Zoro extends AnimeProviderModel {
export class Zoro extends AnimeScraperModel {
readonly url = "https://aniwatch.to";

async GetAnimeInfo(animeName: string): Promise<Anime> {
async GetItemInfo(animeName: string): Promise<Anime> {
try {
const response = await axios.get(`${this.url}/${animeName}`);
const $ = load(response.data);
Expand Down Expand Up @@ -63,7 +63,7 @@ export class Zoro extends AnimeProviderModel {
}
}
//filter
async GetAnimeByFilter(
async GetItemByFilter(
type?: string,
rated?: string,
score?: string,
Expand Down
11 changes: 0 additions & 11 deletions src/scraper/sites/manga/mangaStructure.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/Animeflv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("AnimeFlv", () => {
});

it("should get anime info successfully", async () => {
const animeInfo = await animeFlv.GetAnimeInfo("wonder-egg-priority");
const animeInfo = await animeFlv.GetItemInfo("wonder-egg-priority");
expect(animeInfo.name).toBe("Wonder Egg Priority");
expect(animeInfo.alt_name).toContain("ワンダーエッグ・プライオリティ");
expect(animeInfo.image.url).toContain(".jpg");
Expand All @@ -23,7 +23,7 @@ describe("AnimeFlv", () => {
});

it("should filter anime successfully", async () => {
const result = await animeFlv.GetAnimeByFilter(
const result = await animeFlv.GetItemByFilter(
Genres.Action,
"all",
"all",
Expand Down
4 changes: 2 additions & 2 deletions src/test/Animelatinohd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("AnimeLatinohd", () => {
});

it("should get anime info successfully", async () => {
const animeInfo = await animelatinohd.GetAnimeInfo("wonder-egg-priority");
const animeInfo = await animelatinohd.GetItemInfo("wonder-egg-priority");
expect(animeInfo.name).toBe("Wonder Egg Priority");
expect(animeInfo.alt_name).toContain("ワンダーエッグ・プライオリティ");
expect(animeInfo.image.url).toContain(".jpg");
Expand All @@ -19,7 +19,7 @@ describe("AnimeLatinohd", () => {
});

it("should filter anime successfully", async () => {
const result = await animelatinohd.GetAnimeByFilter();
const result = await animelatinohd.GetItemByFilter();
expect(result.results.length).toBeGreaterThan(0);
}, 10000);
});
Loading

0 comments on commit 079c249

Please sign in to comment.