Merge pull request #43 from WBRK-dev/main

feat: show `raw` servers in `/servers` and `/episode-srcs`
This commit is contained in:
Ritesh Ghosh
2024-04-28 14:11:32 +05:30
committed by GitHub
6 changed files with 27 additions and 8 deletions
+12 -5
View File
@@ -903,6 +903,13 @@ console.log(data);
}, },
{...} {...}
], ],
raw: [
{
serverId: 1,
serverName: "megacloud",
},
{...}
],
} }
``` ```
@@ -918,11 +925,11 @@ https://api-aniwatch.onrender.com/anime/episode-srcs?id={episodeId}&server={serv
#### Query Parameters #### Query Parameters
| Parameter | Type | Description | Required? | Default | | Parameter | Type | Description | Required? | Default |
| :--------: | :----: | :-------------------------------------------: | :-------: | :--------------: | | :--------: | :----: | :--------------------------------------------------: | :-------: | :--------------: |
| `id` | string | The id of the episode. | Yes | -- | | `id` | string | The id of the episode. | Yes | -- |
| `server` | string | The name of the server. | No | `"vidstreaming"` | | `server` | string | The name of the server. | No | `"vidstreaming"` |
| `category` | string | The category of the episode ('sub' or 'dub'). | No | `"sub"` | | `category` | string | The category of the episode ('sub', 'dub' or 'raw'). | No | `"sub"` |
#### Request sample #### Request sample
+1 -1
View File
@@ -25,7 +25,7 @@ import { type ScrapedAnimeEpisodesSources } from "../types/parsers/index.js";
async function scrapeAnimeEpisodeSources( async function scrapeAnimeEpisodeSources(
episodeId: string, episodeId: string,
server: AnimeServers = Servers.VidStreaming, server: AnimeServers = Servers.VidStreaming,
category: "sub" | "dub" = "sub" category: "sub" | "dub" | "raw" = "sub"
): Promise<ScrapedAnimeEpisodesSources | HttpError> { ): Promise<ScrapedAnimeEpisodesSources | HttpError> {
if (episodeId.startsWith("http")) { if (episodeId.startsWith("http")) {
const serverUrl = new URL(episodeId); const serverUrl = new URL(episodeId);
+10
View File
@@ -17,6 +17,7 @@ async function scrapeEpisodeServers(
const res: ScrapedEpisodeServers = { const res: ScrapedEpisodeServers = {
sub: [], sub: [],
dub: [], dub: [],
raw: [],
episodeId, episodeId,
episodeNo: 0, episodeNo: 0,
}; };
@@ -60,6 +61,15 @@ async function scrapeEpisodeServers(
} }
); );
$(`.ps_-block.ps_-block-sub.servers-raw .ps__-list .server-item`).each(
(_, el) => {
res.raw.push({
serverName: $(el).find("a").text().toLowerCase().trim(),
serverId: Number($(el)?.attr("data-server-id")?.trim()) || null,
});
}
);
return res; return res;
} catch (err: any) { } catch (err: any) {
if (err instanceof AxiosError) { if (err instanceof AxiosError) {
+1
View File
@@ -75,6 +75,7 @@ export interface SubEpisode {
serverId: number | null; serverId: number | null;
} }
export interface DubEpisode extends SubEpisode {} export interface DubEpisode extends SubEpisode {}
export interface RawEpisode extends SubEpisode {}
export type AnimeCategories = export type AnimeCategories =
| "most-favorite" | "most-favorite"
+2 -1
View File
@@ -1,8 +1,9 @@
import type { SubEpisode, DubEpisode } from "../anime.js"; import type { SubEpisode, DubEpisode, RawEpisode } from "../anime.js";
export interface ScrapedEpisodeServers { export interface ScrapedEpisodeServers {
sub: SubEpisode[]; sub: SubEpisode[];
dub: DubEpisode[]; dub: DubEpisode[];
raw: RawEpisode[];
episodeNo: number; episodeNo: number;
episodeId: string; episodeId: string;
} }
+1 -1
View File
@@ -191,7 +191,7 @@ export const extractMostPopularAnimes = (
export function retrieveServerId( export function retrieveServerId(
$: CheerioAPI, $: CheerioAPI,
index: number, index: number,
category: "sub" | "dub" category: "sub" | "dub" | "raw"
) { ) {
return ( return (
$(`.ps_-block.ps_-block-sub.servers-${category} > .ps__-list .server-item`) $(`.ps_-block.ps_-block-sub.servers-${category} > .ps__-list .server-item`)