aboutsummaryrefslogtreecommitdiff
path: root/src/utils/methods.ts
diff options
context:
space:
mode:
authorRitesh Ghosh <[email protected]>2023-08-17 23:13:01 +0530
committerRitesh Ghosh <[email protected]>2023-08-17 23:13:01 +0530
commit1c74ecf27ee1144e7bbd441e3eee542074b5b409 (patch)
tree7396392d3ab7062ae2d77b8d5328025cb34ddf54 /src/utils/methods.ts
parent5d1bf2fcc91cad695a054bf838eff668a316a7b4 (diff)
downloadaniwatch-api-1c74ecf27ee1144e7bbd441e3eee542074b5b409.tar.xz
aniwatch-api-1c74ecf27ee1144e7bbd441e3eee542074b5b409.zip
feat: added anime extraction util methods
Diffstat (limited to 'src/utils/methods.ts')
-rw-r--r--src/utils/methods.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utils/methods.ts b/src/utils/methods.ts
index 3f2a8a7..04be65c 100644
--- a/src/utils/methods.ts
+++ b/src/utils/methods.ts
@@ -176,3 +176,28 @@ export const extractMostPopularAnimes = (
);
}
};
+
+export function retrieveServerId(
+ $: CheerioAPI,
+ index: number,
+ category: "sub" | "dub"
+) {
+ return (
+ $(`.ps_-block.ps_-block-sub.servers-${category} > .ps__-list .server-item`)
+ ?.map((_, el) =>
+ $(el).attr("data-server-id") == `${index}` ? $(el) : null
+ )
+ ?.get()[0]
+ ?.attr("data-id") || null
+ );
+}
+
+export function substringAfter(str: string, toFind: string) {
+ const index = str.indexOf(toFind);
+ return index == -1 ? "" : str.substring(index + toFind.length);
+}
+
+export function substringBefore(str: string, toFind: string) {
+ const index = str.indexOf(toFind);
+ return index == -1 ? "" : str.substring(0, index);
+}