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
| Parameter | Type | Description | Required? | Default |
| :--------: | :----: | :-------------------------------------------: | :-------: | :--------------: |
| `id` | string | The id of the episode. | Yes | -- |
| `server` | string | The name of the server. | No | `"vidstreaming"` |
| `category` | string | The category of the episode ('sub' or 'dub'). | No | `"sub"` |
| Parameter | Type | Description | Required? | Default |
| :--------: | :----: | :--------------------------------------------------: | :-------: | :--------------: |
| `id` | string | The id of the episode. | Yes | -- |
| `server` | string | The name of the server. | No | `"vidstreaming"` |
| `category` | string | The category of the episode ('sub', 'dub' or 'raw'). | No | `"sub"` |
#### Request sample
+1 -1
View File
@@ -25,7 +25,7 @@ import { type ScrapedAnimeEpisodesSources } from "../types/parsers/index.js";
async function scrapeAnimeEpisodeSources(
episodeId: string,
server: AnimeServers = Servers.VidStreaming,
category: "sub" | "dub" = "sub"
category: "sub" | "dub" | "raw" = "sub"
): Promise<ScrapedAnimeEpisodesSources | HttpError> {
if (episodeId.startsWith("http")) {
const serverUrl = new URL(episodeId);
+10
View File
@@ -17,6 +17,7 @@ async function scrapeEpisodeServers(
const res: ScrapedEpisodeServers = {
sub: [],
dub: [],
raw: [],
episodeId,
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;
} catch (err: any) {
if (err instanceof AxiosError) {
+1
View File
@@ -75,6 +75,7 @@ export interface SubEpisode {
serverId: number | null;
}
export interface DubEpisode extends SubEpisode {}
export interface RawEpisode extends SubEpisode {}
export type AnimeCategories =
| "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 {
sub: SubEpisode[];
dub: DubEpisode[];
raw: RawEpisode[];
episodeNo: number;
episodeId: string;
}
+1 -1
View File
@@ -191,7 +191,7 @@ export const extractMostPopularAnimes = (
export function retrieveServerId(
$: CheerioAPI,
index: number,
category: "sub" | "dub"
category: "sub" | "dub" | "raw"
) {
return (
$(`.ps_-block.ps_-block-sub.servers-${category} > .ps__-list .server-item`)