diff --git a/README.md b/README.md index 01f39ff..7264846 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,124 @@ -# AruppiAPI -Aruppi is a custom API for use on android app (Under Construction) +# **Aruppi API** (v2.0.0) + +> This API has everything about Japan, from anime, music, radio, images, videos ... to japanese culture +> +> These are the services used for the Aruppi App (only available in Spanish language) + + +![node version](https://img.shields.io/badge/node->=12.17.x-brightgreen.svg) +![npm version](https://img.shields.io/badge/npm->=6.14.x-brightgreen.svg) +![type code](https://img.shields.io/badge/aruppi-API-brightgreen.svg) +![maintenance](https://img.shields.io/badge/maintained-Yes-brightgreen.svg) +![now](https://badgen.net/badge/icon/now?icon=now&label) +![gitrepo](https://img.shields.io/github/stars/aruppi/aruppi-api?style=social) +--- + + + +## 📖 API Documentation +Soon we will add the documentation information in a link + +## :rocket: Custom Aruppi API Link +Link to access the [Aruppi API](https://aruppi-api.jeluchu.now.sh/api/v2) + +## 📚 **Development Diary** +Describe the purpose of the project and give clues about what the code does. +For more information go to the following link [Diary Reference](./development_diary/README.md). + +## **:wrench: Developer usage** + +### **Set up project** + +Before cloning the repo **be sure** you have installed: + +- [**NODE**](https://www.google.com/search?q=how+to+install+node) (version >= 12.17.x) +- [**NPM**](https://www.google.com/search?q=how+to+install+npm) (version >= 6.14.x) + +Then: + +- Choose a folder project in your system and switch in `cd [folder path]` +- Clone the repo in your folder path `git clone https://github.com/aruppi/aruppi-api` + +--- + +### **Installation** + +In order to install the project and all dependencies, enter in the project folder and run `npm install` + +--- + +### Start the project + +```bash +npm start +``` + +### Test the project + +```bash +npm test +``` + +--- + +## Deprecated v1 for API +Aruppi has grown since it was launched and we need to continue improving the application along with the services to be able to give new features. + +But if you need to see the code or the operation of the old version you can do it + +- [Aruppi API GitHub (v1) [Deprecated]](https://github.com/aruppi/aruppi-api-v1) +- [Aruppi API Custom Link(v1) [Deprecated]](https://aruppi.herokuapp.com/api/Aruppi/) + +## **:handshake: Contributing** + +- Fork it! +- Create your feature branch: `git checkout -b my-new-feature` +- Commit your changes: `git commit -am 'Add some feature'` +- Push to the branch: `git push origin my-new-feature` +- Submit a pull request + +--- + +### **:busts_in_silhouette: Credits** + +- [Darkangeel](https://github.com/Darkangeel-hd) (System administration authority (SYSADM)) +- [Jéluchu](https://github.com/Jeluchu) (Android Developer, designer, and others) + +--- + +### **:heart: Show your support** + +Please :star: this repository if you like it or this project helped you!\ +Feel free to open issues or submit pull-requests to help me improving my work. + + +--- + +### **📚 Projects that use the API** + + + + + +
+ + Jeluchu
+ + Aruppi + +

+ Anime y Manga + +
+ + +### **:robot: Author** + +_*Jéluchu*_ + +> You can follow me on +[github](https://github.com/Jeluchu) · [twitter](https://twitter.com/Jeluchu) + +--- + +Copyright © 2020 [Jéluchu](https://about.jeluchu.com/). diff --git a/assets/img/logo.png b/assets/img/logo.png new file mode 100644 index 0000000..5d1e1c9 Binary files /dev/null and b/assets/img/logo.png differ diff --git a/package-lock.json b/package-lock.json index 8d9560c..c3a0eac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,15 +4,60 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@sindresorhus/is": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-2.1.1.tgz", + "integrity": "sha512-/aPsuoj/1Dw/kzhkgz+ES6TxG0zfTMGLwuK2ZG00k/iJzYHTLCE8mVU8EPqEOp/lmxPoq1C1C9RYToRKb2KEfg==" + }, + "@szmarczak/http-timer": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.5.tgz", + "integrity": "sha512-PyRA9sm1Yayuj5OIoJ1hGt2YISX45w9WcFbh6ddT0Z/0yaFxOtGLInr4jUfU1EAFVs0Yfyfev4RNwBlUaHdlDQ==", + "requires": { + "defer-to-connect": "^2.0.0" + } + }, + "@types/cacheable-request": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.1.tgz", + "integrity": "sha512-ykFq2zmBGOCbpIXtoVbz4SKY5QriWPh3AjyU4G74RYbtt5yOc5OfaY75ftjg7mikMOla1CTGpX3lLbuJh8DTrQ==", + "requires": { + "@types/http-cache-semantics": "*", + "@types/keyv": "*", + "@types/node": "*", + "@types/responselike": "*" + } + }, "@types/debug": { "version": "0.0.31", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-0.0.31.tgz", "integrity": "sha512-LS1MCPaQKqspg7FvexuhmDbWUhE2yIJ+4AgVIyObfc06/UKZ8REgxGNjZc82wPLWmbeOm7S+gSsLgo75TanG4A==" }, + "@types/http-cache-semantics": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz", + "integrity": "sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A==" + }, + "@types/keyv": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.1.tgz", + "integrity": "sha512-MPtoySlAZQ37VoLaPcTHCu1RWJ4llDkULYZIzOYxlhxBqYPB0RsRlmMU0R6tahtFe27mIdkHV+551ZWV4PLmVw==", + "requires": { + "@types/node": "*" + } + }, "@types/node": { - "version": "14.0.10", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.10.tgz", - "integrity": "sha512-Bz23oN/5bi0rniKT24ExLf4cK0JdvN3dH/3k0whYkdN4eI4vS2ZW/2ENNn2uxHCzWcbdHIa/GRuWQytfzCjRYw==" + "version": "14.0.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.13.tgz", + "integrity": "sha512-rouEWBImiRaSJsVA+ITTFM6ZxibuAlTuNOCyxVbwreu6k6+ujs7DfnU9o+PShFhET78pMBl3eH+AGSI5eOTkPA==" + }, + "@types/responselike": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz", + "integrity": "sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==", + "requires": { + "@types/node": "*" + } }, "accepts": { "version": "1.3.7", @@ -128,6 +173,25 @@ "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" }, + "cacheable-lookup": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.3.tgz", + "integrity": "sha512-W+JBqF9SWe18A72XFzN/V/CULFzPm7sBXzzR6ekkE+3tLG72wFZrBiBZhrZuDoYexop4PHJVdFAKb/Nj9+tm9w==" + }, + "cacheable-request": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.1.tgz", + "integrity": "sha512-lt0mJ6YAnsrBErpTMWeu5kl/tg9xMAWjavYTN6VQXM1A/teBITuNcccXsCxF0tDQQJf9DfAaX5O4e0zp0KlfZw==", + "requires": { + "clone-response": "^1.0.2", + "get-stream": "^5.1.0", + "http-cache-semantics": "^4.0.0", + "keyv": "^4.0.0", + "lowercase-keys": "^2.0.0", + "normalize-url": "^4.1.0", + "responselike": "^2.0.0" + } + }, "camelize": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/camelize/-/camelize-1.0.0.tgz", @@ -151,6 +215,14 @@ "parse5": "^3.0.1" } }, + "clone-response": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", + "integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=", + "requires": { + "mimic-response": "^1.0.0" + } + }, "cloudscraper": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/cloudscraper/-/cloudscraper-4.6.0.tgz", @@ -278,6 +350,26 @@ "ms": "2.0.0" } }, + "decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "requires": { + "mimic-response": "^3.1.0" + }, + "dependencies": { + "mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==" + } + } + }, + "defer-to-connect": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.0.tgz", + "integrity": "sha512-bYL2d05vOSf1JEZNx5vSAtPuBMkX8K9EUutg7zlKvTqKXHt7RhWJFbmd7qakVuf13i+IkGmp6FwSsONOf6VYIg==" + }, "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -353,6 +445,14 @@ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" }, + "end-of-stream": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "requires": { + "once": "^1.4.0" + } + }, "entities": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", @@ -514,6 +614,14 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "get-stream": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", + "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", + "requires": { + "pump": "^3.0.0" + } + }, "getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", @@ -522,6 +630,25 @@ "assert-plus": "^1.0.0" } }, + "got": { + "version": "11.3.0", + "resolved": "https://registry.npmjs.org/got/-/got-11.3.0.tgz", + "integrity": "sha512-yi/kiZY2tNMtt5IfbfX8UL3hAZWb2gZruxYZ72AY28pU5p0TZjZdl0uRsuaFbnC0JopdUi3I+Mh1F3dPQ9Dh0Q==", + "requires": { + "@sindresorhus/is": "^2.1.1", + "@szmarczak/http-timer": "^4.0.5", + "@types/cacheable-request": "^6.0.1", + "@types/responselike": "^1.0.0", + "cacheable-lookup": "^5.0.3", + "cacheable-request": "^7.0.1", + "decompress-response": "^6.0.0", + "get-stream": "^5.1.0", + "http2-wrapper": "^1.0.0-beta.4.5", + "lowercase-keys": "^2.0.0", + "p-cancelable": "^2.0.0", + "responselike": "^2.0.0" + } + }, "har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", @@ -624,6 +751,11 @@ "readable-stream": "^3.1.1" } }, + "http-cache-semantics": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", + "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==" + }, "http-errors": { "version": "1.7.2", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", @@ -646,6 +778,15 @@ "sshpk": "^1.7.0" } }, + "http2-wrapper": { + "version": "1.0.0-beta.4.6", + "resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.0-beta.4.6.tgz", + "integrity": "sha512-9oB4BiGDTI1FmIBlOF9OJ5hwJvcBEmPCqk/hy314Uhy2uq5TjekUZM8w8SPLLlUEM+mxNhXdPAXfrJN2Zbb/GQ==", + "requires": { + "quick-lru": "^5.0.0", + "resolve-alpn": "^1.0.0" + } + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -709,6 +850,11 @@ "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, + "json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==" + }, "json-schema": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", @@ -735,11 +881,24 @@ "verror": "1.10.0" } }, + "keyv": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.0.1.tgz", + "integrity": "sha512-xz6Jv6oNkbhrFCvCP7HQa8AaII8y8LRpoSm661NOKLr4uHuBwhX4epXrPQgF3+xdJnN4Esm5X0xwY4bOlALOtw==", + "requires": { + "json-buffer": "3.0.1" + } + }, "lodash": { "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, + "lowercase-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", + "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -773,6 +932,11 @@ "mime-db": "1.44.0" } }, + "mimic-response": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", + "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -810,6 +974,11 @@ "nan": "^2.13.2" } }, + "normalize-url": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", + "integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==" + }, "nth-check": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz", @@ -836,6 +1005,19 @@ "ee-first": "1.1.1" } }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, + "p-cancelable": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.0.0.tgz", + "integrity": "sha512-wvPXDmbMmu2ksjkB4Z3nZWTSkJEb9lqVdMaCKpZUGJG9TMiNp9XcbG3fn9fPKjem04fJMJnXoyFPk2FmgiaiNg==" + }, "parse5": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz", @@ -873,6 +1055,15 @@ "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==" }, + "pump": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", + "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -883,6 +1074,11 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" }, + "quick-lru": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", + "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==" + }, "range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", @@ -967,6 +1163,19 @@ "lodash": "^4.17.15" } }, + "resolve-alpn": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.0.0.tgz", + "integrity": "sha512-rTuiIEqFmGxne4IovivKSDzld2lWW9QCjqv80SYjPgf+gS35eaCAjaP54CCwGAwBtnCsvNLYtqxe1Nw+i6JEmA==" + }, + "responselike": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.0.tgz", + "integrity": "sha512-xH48u3FTB9VsZw7R+vvgaKeLKzT6jOogbQhEe/jewwnZgzPcnyWui2Av6JpoYZF/91uueC+lqhWqeURw5/qhCw==", + "requires": { + "lowercase-keys": "^2.0.0" + } + }, "rss-to-json": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/rss-to-json/-/rss-to-json-1.1.1.tgz", @@ -1157,6 +1366,11 @@ "extsprintf": "^1.2.0" } }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, "x-xss-protection": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/x-xss-protection/-/x-xss-protection-1.3.0.tgz", diff --git a/package.json b/package.json index a489a25..0e3387c 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ } ], "engines": { - "node": ">= 10.16.x", - "npm": ">= 6.9.x" + "node": ">= 12.17.x", + "npm": ">= 6.14.x" }, "bugs": { "url": "https://github.com/aruppi/aruppi-api/issues" @@ -47,6 +47,7 @@ "compose-middleware": "^5.0.1", "cors": "^2.8.5", "express": "^4.16.4", + "got": "^11.3.0", "helmet": "^3.22.0", "node-base64-image": "^2.0.1", "request": "^2.88.2", diff --git a/src/api/api.js b/src/api/api.js index 0ca3e7d..2cbaee0 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -1,5 +1,5 @@ const rss = require('rss-to-json'); -const cloudscraper = require('cloudscraper'); +const html = require('got'); const { animeflvInfo, @@ -10,17 +10,18 @@ const { searchAnime, transformUrlServer, obtainPreviewNews, - structureThemes + structureThemes, + getAnimes } = require('../utils/index'); const { - BASE_ANIMEFLV, BASE_ANIMEFLV_JELU, BASE_JIKAN, BASE_IVOOX, BASE_QWANT, BASE_YOUTUBE, BASE_THEMEMOE + BASE_ANIMEFLV_JELU, BASE_JIKAN, BASE_IVOOX, BASE_QWANT, BASE_YOUTUBE, BASE_THEMEMOE } = require('./urls'); const schedule = async (day) =>{ - const data = await cloudscraper.get(`${BASE_JIKAN}schedule/${day.current}`); - const body = JSON.parse(data)[day.current] + const data = await html(`${BASE_JIKAN}schedule/${day.current}`).json(); + const body = data[day.current]; const promises = [] body.map(doc =>{ @@ -38,18 +39,15 @@ const schedule = async (day) =>{ }; const top = async (type, subtype, page) =>{ - - const data = await cloudscraper.get(`${BASE_JIKAN}top/${type}/${page}/${subtype}`); - - return JSON.parse(data).top; - + const data = await html(`${BASE_JIKAN}top/${type}/${page}/${subtype}`).json(); + return data.top; }; const getAllAnimes = async () =>{ - const data = await cloudscraper.get(`${BASE_ANIMEFLV}api/animes/list`); - const body = JSON.parse(data); - return body.map(item => ({ + let data = await getAnimes() + + return data.map(item => ({ index: item[0], animeId: item[3], title: item[1], @@ -127,8 +125,8 @@ const getNews = async (pageRss) =>{ const season = async (year, type) =>{ - const data = await cloudscraper.get(`${BASE_JIKAN}season/${year}/${type}`); - let body = JSON.parse(data).anime; + const data = await html(`${BASE_JIKAN}season/${year}/${type}`).json(); + let body = data.anime; const promises = [] body.map(doc =>{ @@ -147,8 +145,8 @@ const season = async (year, type) =>{ const getLastEpisodes = async () =>{ - const data = await cloudscraper.get(`${BASE_ANIMEFLV_JELU}LatestEpisodesAdded`); - let body = JSON.parse(data).episodes; + const data = await html(`${BASE_ANIMEFLV_JELU}LatestEpisodesAdded`).json(); + let body = data.episodes; const promises = [] body.map(doc =>{ @@ -168,8 +166,8 @@ const getLastEpisodes = async () =>{ const getSpecials = async (type, subType, page) =>{ - const data = await cloudscraper.get(`${BASE_ANIMEFLV_JELU}${type.url}/${subType}/${page}`); - let body = JSON.parse(data)[type.prop]; + const data = await html(`${BASE_ANIMEFLV_JELU}${type.url}/${subType}/${page}`).json(); + let body = data[type.prop]; const promises = [] body.map(doc =>{ @@ -214,59 +212,10 @@ const getMoreInfo = async (title) =>{ ) }); - - try{ - switch (animeType) { - - case "tv": - promises.push(await animeflvInfo(animeId, animeIndex).then(async extra => ({ - title: animeTitle || null, - poster: await imageUrlToBase64(extra.animeExtraInfo[0].poster) || null, - synopsis: extra.animeExtraInfo[0].synopsis || null, - status: extra.animeExtraInfo[0].debut || null, - type: extra.animeExtraInfo[0].type || null, - rating: extra.animeExtraInfo[0].rating || null, - genres: extra.genres || null, - episodes: extra.listByEps || null, - moreInfo: await animeExtraInfo(title).then(info =>{ - return info || null - }), - promo: await getAnimeVideoPromo(title).then(promo =>{ - return promo || null - }), - characters: await getAnimeCharacters(animeTitle).then(characters =>{ - return characters || null - }) - }))); - break; - case "movie": - promises.push(await animeflvInfo(animeId).then(async extra => ({ - title: animeTitle || null, - poster: await imageUrlToBase64(extra.animeExtraInfo[0].poster) || null, - synopsis: extra.animeExtraInfo[0].synopsis || null, - status: extra.animeExtraInfo[0].debut || null, - type: extra.animeExtraInfo[0].type || null, - rating: extra.animeExtraInfo[0].rating || null, - genres: extra.genres || null, - episodes: extra.listByEps || null, - }))); - break; - case "ova": - promises.push(await animeflvInfo(animeId).then(async extra => ({ - title: animeTitle || null, - poster: await imageUrlToBase64(extra.animeExtraInfo[0].poster) || null, - synopsis: extra.animeExtraInfo[0].synopsis || null, - status: extra.animeExtraInfo[0].debut || null, - type: extra.animeExtraInfo[0].type || null, - rating: extra.animeExtraInfo[0].rating || null, - genres: extra.genres || null, - episodes: extra.listByEps || null, - }))); - break; - default: - promises.push(await animeflvInfo(animeId).then(async extra => ({ + if (animeType === 'tv') { + promises.push(await animeflvInfo(animeId, animeIndex).then(async extra => ({ title: animeTitle || null, poster: await imageUrlToBase64(extra.animeExtraInfo[0].poster) || null, synopsis: extra.animeExtraInfo[0].synopsis || null, @@ -275,7 +224,27 @@ const getMoreInfo = async (title) =>{ rating: extra.animeExtraInfo[0].rating || null, genres: extra.genres || null, episodes: extra.listByEps || null, + moreInfo: await animeExtraInfo(title).then(info =>{ + return info || null + }), + promo: await getAnimeVideoPromo(title).then(promo =>{ + return promo || null + }), + characters: await getAnimeCharacters(animeTitle).then(characters =>{ + return characters || null + }) }))); + } else { + promises.push(await animeflvInfo(animeId).then(async extra => ({ + title: animeTitle || null, + poster: await imageUrlToBase64(extra.animeExtraInfo[0].poster) || null, + synopsis: extra.animeExtraInfo[0].synopsis || null, + status: extra.animeExtraInfo[0].debut || null, + type: extra.animeExtraInfo[0].type || null, + rating: extra.animeExtraInfo[0].rating || null, + genres: extra.genres || null, + episodes: extra.listByEps || null, + }))); } }catch(err){ @@ -288,8 +257,8 @@ const getMoreInfo = async (title) =>{ const getAnimeServers = async (id) => { - const data = await cloudscraper.get(`${BASE_ANIMEFLV_JELU}GetAnimeServers/${id}`); - let body = JSON.parse(data).servers; + const data = await html(`${BASE_ANIMEFLV_JELU}GetAnimeServers/${id}`).json(); + let body = data.servers; return await transformUrlServer(body); @@ -299,8 +268,8 @@ const search = async (title) =>{ return await searchAnime(title); }; const getImages = async (query) => { - const data = await cloudscraper.get(`${BASE_QWANT}count=${query.count}&q=${query.title}&t=${query.type}&safesearch=${query.safesearch}&locale=${query.country}&uiv=4`); - const body = JSON.parse(data).data.result.items; + const data = await html(`${BASE_QWANT}count=${query.count}&q=${query.title}&t=${query.type}&safesearch=${query.safesearch}&locale=${query.country}&uiv=4`).json(); + const body = data.data.result.items; const promises = [] body.map(doc =>{ @@ -319,8 +288,8 @@ const getImages = async (query) => { const getYoutubeVideos = async (channelId) => { - const data = await cloudscraper.get(`${BASE_YOUTUBE}${channelId.id}&part=${channelId.part}&order=${channelId.order}&maxResults=${channelId.maxResults}`); - const body = JSON.parse(data)[channelId.prop]; + const data = await html(`${BASE_YOUTUBE}${channelId.id}&part=${channelId.part}&order=${channelId.order}&maxResults=${channelId.maxResults}`).json(); + const body = data[channelId.prop]; const promises = [] body.map(doc =>{ @@ -344,12 +313,8 @@ const getRadioStations = async () => { } const getOpAndEd = async (title) => { - - const data = await cloudscraper.get(`${BASE_THEMEMOE}anime/search/${title}`); - const body = JSON.parse(data); - - return await structureThemes(body, true, 0) - + const data = await html(`${BASE_THEMEMOE}anime/search/${title}`).json(); + return await structureThemes(data, true, 0) }; const getThemesSeason = async (year, season) => { @@ -357,37 +322,29 @@ const getThemesSeason = async (year, season) => { let data if (season === undefined) { - data = await cloudscraper.get(`${BASE_THEMEMOE}seasons/${year}`); + data = await html(`${BASE_THEMEMOE}seasons/${year}`).json(); } else { - data = await cloudscraper.get(`${BASE_THEMEMOE}seasons/${year}/${season}`); + data = await html(`${BASE_THEMEMOE}seasons/${year}/${season}`).json(); } - const body = JSON.parse(data); - return await structureThemes(body, false, 0) + return await structureThemes(data, false, 0) }; const getRandomTheme = async () => { - - const data = await cloudscraper.get(`${BASE_THEMEMOE}roulette`); - const body = JSON.parse(data); - - return await structureThemes(body, true) - + const data = await html(`${BASE_THEMEMOE}roulette`).json(); + return await structureThemes(data, true) }; const getArtist = async (id) => { let data - let body let promises = [] if (id === undefined) { - data = await cloudscraper.get(`${BASE_THEMEMOE}artists`); - body = JSON.parse(data); - - body.map(doc => { + data = await html(`${BASE_THEMEMOE}artists`).json(); + data.map(doc => { promises.push({ id: doc.artistID, @@ -399,11 +356,8 @@ const getArtist = async (id) => { return promises; } else { - - data = await cloudscraper.get(`${BASE_THEMEMOE}artists/${id}`); - body = JSON.parse(data); - - return await structureThemes(body, false, 1) + data = await html(`${BASE_THEMEMOE}artists/${id}`).json(); + return await structureThemes(data, false, 1) } }; diff --git a/src/api/routes/index.js b/src/api/routes/index.js index 47f1114..02af8e1 100644 --- a/src/api/routes/index.js +++ b/src/api/routes/index.js @@ -10,9 +10,13 @@ router.get('/schedule/:day' , (req, res) =>{ api.schedule(day) .then(day =>{ - res.status(200).json({ - day - }); + if (day.length > 0) { + res.status(200).json({ + day + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -27,9 +31,13 @@ router.get('/top/:type/:subtype/:page' , (req, res) =>{ api.top(type, subtype, page) .then(top =>{ - res.status(200).json({ - top - }); + if (top.length > 0) { + res.status(200).json({ + top + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -40,9 +48,13 @@ router.get('/allAnimes' , (req, res) =>{ api.getAllAnimes() .then(animes =>{ - res.status(200).json({ - animes - }); + if (animes.length > 0) { + res.status(200).json({ + animes + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -53,9 +65,13 @@ router.get('/anitakume' , (req, res) =>{ api.getAnitakume() .then(podcast =>{ - res.status(200).json({ - podcast - }); + if (podcast.length > 0) { + res.status(200).json({ + podcast + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -73,9 +89,13 @@ router.get('/news' , (req, res) =>{ api.getNews(pagesRss) .then(news =>{ - res.status(200).json({ - news - }); + if (news.length > 0) { + res.status(200).json({ + news + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -89,9 +109,13 @@ router.get('/season/:year/:type' , (req, res) =>{ api.season(year, type) .then(season =>{ - res.status(200).json({ - season - }); + if (season.length > 0) { + res.status(200).json({ + season + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -102,9 +126,13 @@ router.get('/lastEpisodes' , (req, res) =>{ api.getLastEpisodes() .then(episodes =>{ - res.status(200).json({ - episodes - }); + if (episodes.length > 0) { + res.status(200).json({ + episodes + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -119,9 +147,13 @@ router.get('/movies/:type/:page' , (req, res) =>{ api.getSpecials(type, subType, page) .then(movies =>{ - res.status(200).json({ - movies - }); + if (movies.length > 0) { + res.status(200).json({ + movies + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -136,9 +168,13 @@ router.get('/ovas/:type/:page' , (req, res) =>{ api.getSpecials(type, subType, page) .then(ovas =>{ - res.status(200).json({ - ovas - }); + if (ovas.length > 0) { + res.status(200).json({ + ovas + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -153,9 +189,13 @@ router.get('/specials/:type/:page' , (req, res) =>{ api.getSpecials(type, subType, page) .then(specials =>{ - res.status(200).json({ - specials - }); + if (specials.length > 0) { + res.status(200).json({ + specials + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -170,9 +210,13 @@ router.get('/tv/:type/:page' , (req, res) =>{ api.getSpecials(type, subType, page) .then(tv =>{ - res.status(200).json({ - tv - }); + if (tv.length > 0) { + res.status(200).json({ + tv + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -190,7 +234,7 @@ router.get('/moreInfo/:title' , (req, res) =>{ info }); } else ( - res.status(404).json({ message: 'Aruppi lost in the shell'}) + res.status(500).json({ message: 'Aruppi lost in the shell'}) ) }).catch((err) =>{ console.error(err); @@ -204,9 +248,13 @@ router.get('/getAnimeServers/:id([^/]+/[^/]+)' , (req, res) =>{ api.getAnimeServers(id) .then(servers =>{ - res.status(200).json({ - servers - }); + if (servers.length > 0) { + res.status(200).json({ + servers + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -219,9 +267,13 @@ router.get('/search/:title' , (req, res) =>{ api.search(title) .then(search =>{ - res.status(200).json({ - search - }); + if (search.length > 0) { + res.status(200).json({ + search + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -234,9 +286,13 @@ router.get('/images/:query' , (req, res) =>{ api.getImages(query) .then(images =>{ - res.status(200).json({ - images - }); + if (images.length > 0) { + res.status(200).json({ + images + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -249,9 +305,13 @@ router.get('/videos/:channelId' , (req, res) =>{ api.getYoutubeVideos(channelId) .then(videos =>{ - res.status(200).json({ - videos - }); + if (videos.length > 0) { + res.status(200).json({ + videos + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -262,9 +322,13 @@ router.get('/radio' , (req, res) =>{ api.getRadioStations() .then(stations =>{ - res.status(200).json({ - stations - }); + if (stations.length > 0) { + res.status(200).json({ + stations + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -277,9 +341,13 @@ router.get('/themes/:title' , (req, res) =>{ api.getOpAndEd(title) .then(themes =>{ - res.status(200).json({ - themes - }); + if (themes.length > 0) { + res.status(200).json({ + themes + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -293,9 +361,13 @@ router.get('/themeSeason/:year/:season?', (req, res) =>{ api.getThemesSeason(year, season) .then(themes =>{ - res.status(200).json({ - themes - }); + if (themes.length > 0) { + res.status(200).json({ + themes + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -306,9 +378,13 @@ router.get('/randomTheme', (req, res) =>{ api.getRandomTheme() .then(random =>{ - res.status(200).json({ - random - }); + if (random.length > 0) { + res.status(200).json({ + random + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); @@ -321,9 +397,13 @@ router.get('/artists/:id?', (req, res) =>{ api.getArtist(id) .then(artists =>{ - res.status(200).json({ - artists - }); + if (artists.length > 0) { + res.status(200).json({ + artists + }); + } else ( + res.status(500).json({ message: 'Aruppi lost in the shell'}) + ) }).catch((err) =>{ console.error(err); }); diff --git a/src/app.js b/src/app.js index 873e9f7..edc0ea4 100644 --- a/src/app.js +++ b/src/app.js @@ -15,6 +15,10 @@ app.use(bodyParser.urlencoded({ extended: false })); app.get('/', (req, res) => { + res.redirect('/api/') +}); + +app.get('/api/', (req, res) => { res.json({ message: 'Tu~tu~ruuu! You have traveled to the API Black Hole' }); diff --git a/src/utils/index.js b/src/utils/index.js index 39a7d81..81ed896 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,6 +1,7 @@ const cloudscraper = require('cloudscraper') const cheerio = require('cheerio'); const base64 = require('node-base64-image'); +const html = require('got'); const { BASE_ANIMEFLV, BASE_JIKAN, BASE_EPISODE_IMG_URL, SEARCH_URL, BASE_ARUPPI, BASE_THEMEMOE @@ -15,12 +16,19 @@ const animeflvInfo = async (id, index) => { let debut = "" let type = "" + let res + let $ + try { - const res = await cloudscraper(`${BASE_ANIMEFLV}anime/${id}`); - const body = await res; + try { + res = await html(`${BASE_ANIMEFLV}anime/${id}`); + $ = await cheerio.load(res.body); + } catch (error) { + res = await cloudscraper.get(`${BASE_ANIMEFLV}anime/${id}`); + $ = await cheerio.load(res) + } - const $ = await cheerio.load(body); const scripts = $('script'); const anime_info_ids = []; const anime_eps_data = []; @@ -109,15 +117,14 @@ const animeflvInfo = async (id, index) => { }; const getAnimeCharacters = async (title) => { - const res = await cloudscraper(`${BASE_JIKAN}search/anime?q=${title}`); - const matchAnime = JSON.parse(res).results.filter(x => x.title === title); + const res = await html(`${BASE_JIKAN}search/anime?q=${title}`).json(); + const matchAnime = res.results.filter(x => x.title === title); const malId = matchAnime[0].mal_id; if (typeof matchAnime[0].mal_id === 'undefined') return null; - const jikanCharactersURL = `${BASE_JIKAN}anime/${malId}/characters_staff`; - const data = await cloudscraper.get(jikanCharactersURL); - let body = JSON.parse(data).characters; + const data = await html(`${BASE_JIKAN}anime/${malId}/characters_staff`).json(); + let body = data.characters; if (typeof body === 'undefined') return null; @@ -147,15 +154,14 @@ const getAnimeCharacters = async (title) => { }; const getAnimeVideoPromo = async (title) => { - const res = await cloudscraper(`${BASE_JIKAN}search/anime?q=${title}`); - const matchAnime = JSON.parse(res).results.filter(x => x.title === title); + const res = await html(`${BASE_JIKAN}search/anime?q=${title}`).json(); + const matchAnime = res.results.filter(x => x.title === title); const malId = matchAnime[0].mal_id; if (typeof matchAnime[0].mal_id === 'undefined') return null; - const jikanCharactersURL = `${BASE_JIKAN}anime/${malId}/videos`; - const data = await cloudscraper.get(jikanCharactersURL); - const body = JSON.parse(data).promo; + const data = await html(`${BASE_JIKAN}anime/${malId}/videos`).json(); + const body = data.promo; const promises = []; body.map(doc => { @@ -170,67 +176,35 @@ const getAnimeVideoPromo = async (title) => { }; const animeExtraInfo = async (title) => { - const res = await cloudscraper(`${BASE_JIKAN}search/anime?q=${title}`); - const matchAnime = JSON.parse(res).results.filter(x => x.title === title); + const res = await html(`${BASE_JIKAN}search/anime?q=${title}`).json(); + const matchAnime = res.results.filter(x => x.title === title); const malId = matchAnime[0].mal_id; if (typeof matchAnime[0].mal_id === 'undefined') return null; - const animeDetails = `${BASE_JIKAN}anime/${malId}`; - const data = await cloudscraper.get(animeDetails); - const body = Array(JSON.parse(data)); + const data = await html(`${BASE_JIKAN}anime/${malId}`).json(); + const body = Array(data); const promises = []; body.map(doc => { - let airDay - - switch (doc.broadcast.split('at')[0].replace(" ", "").toLowerCase()) { - case "mondays": - airDay = "Lunes"; - break; - case "monday": - airDay = "Lunes"; - break; - case "tuesdays": - airDay = "Martes"; - break; - case "tuesday": - airDay = "Martes"; - break; - case "wednesdays": - airDay = "Miércoles"; - break; - case "wednesday": - airDay = "Miércoles"; - break; - case "thursdays": - airDay = "Jueves"; - break; - case "thursday": - airDay = "Jueves"; - break; - case "fridays": - airDay = "Viernes"; - break; - case "friday": - airDay = "Viernes"; - break; - case "saturdays": - airDay = "Sábados"; - break; - case "saturday": - airDay = "Sábados"; - break; - case "sundays": - airDay = "Domingos"; - break; - case "sunday": - airDay = "Domingos"; - break; - default: - airDay = "Sin emisión"; - } + let airDay = { + 'mondays': 'Lunes', + 'monday': 'Lunes', + 'tuesdays': 'Martes', + 'tuesday': 'Martes', + 'wednesdays': 'Miércoles', + 'wednesday': 'Miércoles', + 'thursdays': 'Jueves', + 'thursday': 'Jueves', + 'fridays': 'Viernes', + 'friday': 'Viernes', + 'saturdays': 'Sábados', + 'saturday': 'Sábados', + 'sundays': 'Domingos', + 'sunday': 'Domingos', + 'default': 'Sin emisión' + }; promises.push({ titleJapanese: doc.title_japanese, @@ -240,9 +214,9 @@ const animeExtraInfo = async (title) => { from: doc.aired.from, to: doc.aired.to }, - duration: doc.duration.split('per')[0].replace(" ", ""), + duration: doc.duration.split('per')[0], rank: doc.rank, - broadcast: airDay, + broadcast: airDay[doc.broadcast.split('at')[0].replace(" ", "").toLowerCase()], producers: doc.producers.map(x => x.name) || null, licensors: doc.licensors.map(x => x.name) || null, studios: doc.studios.map(x => x.name) || null, @@ -257,15 +231,21 @@ const imageUrlToBase64 = async (url) => { return await base64.encode(url, {string: true}); }; -const search = async () => { -} +const search = async () => {} const searchAnime = async (query) => { - const res = await cloudscraper(`${SEARCH_URL}${query}`); - const body = await res; - const $ = await cheerio.load(body); - const promises = []; + let res + let $ + let promises = [] + + try { + res = await html(`${SEARCH_URL}${query}`); + $ = await cheerio.load(res.body); + } catch (error) { + res = await cloudscraper.get(`${SEARCH_URL}${query}`); + $ = await cheerio.load(res) + } $('div.Container ul.ListAnimes li article').each((index, element) => { const $element = $(element); @@ -274,7 +254,7 @@ const searchAnime = async (query) => { let poster = $element.find('a div.Image figure img').attr('src') || $element.find('a div.Image figure img').attr('data-cfsrc'); const type = $element.find('div.Description p span.Type').text(); - promises.push(search().then(async extra => ({ + promises.push(search().then(async () => ({ id: id || null, title: title || null, type: type || null, @@ -290,21 +270,18 @@ const searchAnime = async (query) => { const transformUrlServer = async (urlReal) => { let res - let body const promises = [] for (i = 0; i <= urlReal.length - 1; i++) { switch (urlReal[i].server) { case "amus": - res = await cloudscraper(urlReal[i].code.replace("embed", "check")); - body = await res; - urlReal[i].code = JSON.parse(body).file + res = await html(urlReal[i].code.replace("embed", "check")).json(); + urlReal[i].code = res.file urlReal[i].direct = true break; case "natsuki": - res = await cloudscraper(urlReal[i].code.replace("embed", "check")); - body = await res; - urlReal[i].code = JSON.parse(body).file + res = await html(urlReal[i].code.replace("embed", "check")).json(); + urlReal[i].code = res.file urlReal[i].direct = true break; default: @@ -357,21 +334,20 @@ const structureThemes = async (body, indv, task) => { const promises = [] let themes - let respFinal + let data if (task === 0) { for (let i = 0; i <= body.length - 1; i++) { if (indv === true) { - const data = await cloudscraper.get(`${BASE_THEMEMOE}themes/${body[i]}`); - respFinal = JSON.parse(data) - themes = await getThemes(respFinal[0].themes) + data = await html(`${BASE_THEMEMOE}themes/${body[i]}`).json(); + themes = await getThemes(data[0].themes) } else { - respFinal = body + data = body themes = await getThemes(body[0].themes) } - respFinal.map(doc => { + data.map(doc => { promises.push({ title: doc.name, @@ -383,25 +359,26 @@ const structureThemes = async (body, indv, task) => { }); } } else if (task === 1) { - respFinal = body - themes = await getHeaderTheme(respFinal.themes) + + data = body + themes = await getHeaderTheme(data.themes) promises.push({ - title: respFinal.artistName, - season: respFinal.season, - year: respFinal.year, + title: data.artistName, + season: data.season, + year: data.year, series: themes, }); } else { - respFinal = body - themes = await getThemes(respFinal.themes) + data = body + themes = await getThemes(data.themes) promises.push({ - title: respFinal.name, - season: respFinal.season, - year: respFinal.year, + title: data.name, + season: data.season, + year: data.year, themes: themes, }); @@ -451,6 +428,22 @@ const getThemes = async (themes) => { }; +const getAnimes = async () => { + + let res + let data + + try { + data = await html(`${BASE_ANIMEFLV}api/animes/list`).json(); + } catch (error) { + res = await cloudscraper.get(`${BASE_ANIMEFLV}api/animes/list`); + data = JSON.parse(res); + } + + return data; + +}; + module.exports = { animeflvInfo, getAnimeCharacters, @@ -461,5 +454,6 @@ module.exports = { transformUrlServer, obtainPreviewNews, structureThemes, - getThemes + getThemes, + getAnimes }