aboutsummaryrefslogtreecommitdiff
path: root/lib/anify/getMangaId.js
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-10-22 19:43:17 +0700
committerGitHub <[email protected]>2023-10-22 19:43:17 +0700
commitf801f8f422954b884a6541321dba0669ee9d6173 (patch)
treee0d5e106b99e9b4e0a4c4bf7bb0464617db85b8d /lib/anify/getMangaId.js
parentBump @babel/traverse from 7.22.8 to 7.23.2 (#90) (diff)
downloadmoopa-4.2.0.tar.xz
moopa-4.2.0.zip
Update v4.2.0 (#93)v4.2.0
Diffstat (limited to 'lib/anify/getMangaId.js')
-rw-r--r--lib/anify/getMangaId.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/anify/getMangaId.js b/lib/anify/getMangaId.js
new file mode 100644
index 0000000..e18da65
--- /dev/null
+++ b/lib/anify/getMangaId.js
@@ -0,0 +1,40 @@
+import axios from "axios";
+
+export async function fetchInfo(romaji, english, native) {
+ try {
+ const { data: getManga } = await axios.get(
+ `https://api.anify.tv/search-advanced?query=${
+ english || romaji
+ }&type=manga`
+ );
+
+ const findManga = getManga.find(
+ (manga) =>
+ manga.title.romaji === romaji ||
+ manga.title.english === english ||
+ manga.title.native === native
+ );
+
+ if (!findManga) {
+ return null;
+ }
+
+ return { id: findManga.id };
+ } catch (error) {
+ console.error("Error fetching data:", error);
+ return null;
+ }
+}
+
+export default async function getMangaId(romaji, english, native) {
+ try {
+ const data = await fetchInfo(romaji, english, native);
+ if (data) {
+ return data;
+ } else {
+ return { message: "Schedule not found" };
+ }
+ } catch (error) {
+ return { error };
+ }
+}