2.1.1 • Published 2 years ago

anify.js v2.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Anify-API

JavaScript API server for scraping anime and manga sites.

Information

Scraping

Anify API scrapes numerous anime and manga sites, from Zoro, to GogoAnime, to AnimePahe, and more. The API is built on top of AniSync to map AniList information to streaming sites, allowing for multiple providers in case one ever goes down. To avoid rate limits, the API also caches data for a set amount of time and retrieves it when necessary. This is meant to be a robust web server, so there are a ton of features from optional Redis caching, PostgreSQL and SQLite support, etc.

Anime

The API supports the following anime sites:

Manga

The API supports the following manga sites:

Meta

The API supports the following meta providers:

Using as a Library

Anify API can be used as a library. It is mainly meant to be used as a REST API, but it is entirely possible to be used as an NPM package. You can install the NPM package like this:

npm i anify.js

Then import the class in your JavaScript project:

// ES6
import Anify from "anify.js"

// CommonJS
const Anify = require("anify.js").default;

const anify = new Anify();

Building the Repository

If you wish to use Anify-API for yourself, feel free to follow the instructions below. However, a fully-populated database will NOT be provided. Support can be directed to Anify's Discord.

Prerequisites

Anify-API requires at a minimum NodeJS version 16.0.0 and NPM version 8.0.0. For using this repository as a web server, installation is relatively simple. 1. Clone the repository via git clone https://github.com/Eltik/Anify-API. 2. cd into the folder (cd Anify-API). 3. Run npm i. If necessary, reinstall axios via npm i axios@0.27.2. 4. If necessary, setup the .env file (see below). 5. Run npm run start to start the web server or npm run start:pm2 if you want to use pm2.

.env File

You can configure the web server via a .env file (not included). Default values are shown below (might be slightly different). Change the values shown below to your liking:

DEBUG="true"
CACHE_TIMEOUT="14400000"
ENCRYPTION_KEY="myheroacademia"
STORAGE_PATH="/root/Anify-API/storage"
IS_MACOS="false"
POPPLER_PATH="/opt/homebrew/Cellar/poppler/22.12.0/bin"
WEB_SERVER_URL="https://api.anify.tv"
WEB_SERVER_MAIN_URL="https://anify.tv"
WEB_SERVER_PORT="3060"
ANILIST_SEASON="WINTER"
ANILIST_SEASON_YEAR="2023"
ANILIST_NEXT_SEASON="SPRING"
ANILIST_NEXT_SEASON_YEAR="2023"
ANILIST_OATH_ID="-1"
ANILIST_OATH_SECRET=""
DATABASE_URL="postgresql://postgres:password@localhost:3306"
IS_SQLITE="true"
NineAnime="https://9anime.pl"
PUP_TIMEOUT="1000000"
REDIS_URL="redis://localhost:6379"

Some basic documentation on .env values:

  • DEBUG: Whether to enable debug mode or not. Recommended to turn it on. Turning it off essentially removes all logging since there isn't much that needs to be printed.
  • CACHE_TIMEOUT: How long to cache episodes, chapters, sources, and pages for in milliseconds.
  • ENCRYPTION_KEY: Basic encryption/decryption mainly for pages. Can be anything.
  • STORAGE_PATH: Storage path for light novels. No documentation provided. If you want support, join the Discord.
  • IS_MACOS: Boolean of whether using MacOS or not. For light novels.
  • POPPLER_PATH: PDF Poppler path. Used only if IS_MACOS is true. For light novels.
  • WEB_SERVER_URL: API server URL. Required for AniList authentication.
  • WEB_SERVER_MAIN_URL: Frontend server URL. Required for AniList authentication.
  • ANILIST_SEASON: The current AniList season. Used for /season routes.
  • ANILIST_SEASON_YEAR: Current AniList season year. Used for /season routes.
  • ANILIST_NEXT_SEASON: Next AniList season. Used for /season routes.
  • ANILIST_NEXT_SEASON_YEAR: Next AniList season year. Used for /season routes.
  • ANILIST_OAUTH_ID: AniList authentication ID. Authentication can be setup here.
  • ANILIST_OAUTH_SECRET: AniList authentication secret. Authentication can be setup here.
  • DATABASE_URL: PostgreSQL database URL. View the PostgreSQL section for more information.
  • IS_SQLITE: Whether to use SQLite or not.
  • NineAnime: Custom 9anime URL.
  • PUP_TIMEOUT: How long to try bypassing CloudFlare for before timing out.
  • REDIS_URL: Redis caching URL.

Using Redis

It is highly recommended that you use Redis for caching. On MacOS, you can install Redis via Homebrew like this:

# Installation
brew install redis

# Start the server
brew services start redis

# Testing
redis-server

# To delete everything from the cache
redis-cli flushall

For Linux:

# Prerequisite
sudo apt install lsb-release

# Installation
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis

Using Puppeteer

Anify-API requires the use of Puppeteer in some cases for bypassing CloudFlare. This is required for very few providers, so if you absolutely cannot use it, you can just disable the providers in question. As of now, only 9anime requires a CloudFlare bypass if you are crawling it/get permanently captchaed by them. I use my own CloudFlare bypass system, so more detailed instructions are on the GitHub page. Essentially, Puppeteer only becomes an issue dependency-wise on Linux. Since Linux is terminal based and Puppeteer requires a GUI/Window-based solution, you will need to setup xrdp or xvfb. As for Windows/MacOS, it's not as much of an issue as long as you have Google Chrome installed. Please view the GitHub page as mentioned before for more detailed installation instructions.

Using SQLite

If you don't want to use PostgreSQL, you can use SQLite. This is a more wildly-supported database, but it is not recommended for production (it's marginally slower and less efficient). In your project, just add the is_sqlite configuration option into the options path:

import Anify from "anify.js";
const anify = new Anify({ is_sqlite: true });

That's it!

Using Prisma/PostegreSQL

By default, Anify uses Prisma and @prisma/client. After installing the NPM package, create a prisma folder in your project and download the schema.prisma file found here into the folder. Your project should look like this:

├── node_modules
├── prisma
│   └── schema.prisma
├── package.json
└── other_files_here

You will also need to create a file called .env in your project folder. Put DATABASE_URL="postgresql://postgres:password@localhost:3306" in the file. You can change the database URL to whatever you want, but make sure to change the database_url in the options path to match the URL in the .env file.

# .env
# The URL is formatted as postgres://{username}:{password}@{host}:{port}/{database_name}
DATABASE_URL="postgres://username:password@localhost:5432/anify"

# Here is an example that I use
DATABASE_URL="postgresql://postgres:password@localhost:3306"

Anify-API requires PostgreSQL to run. On MacOS, you can install PostgreSQL via Homebrew:

# Installation
brew install postgresql
brew install postgis

# Start the server
brew services start postgresql

# Stop the server
brew services stop postgresql

On Linux, you can install PostgreSQL via this:

# Installation
sudo apt update
# Custom functions/pg_trgm
sudo apt install postgresql postgresql-contrib
sudo apt-get install postgresql-contrib

# Start the server
sudo systemctl start postgresql.service

# Stop the server
sudo systemctl stop postgresql.service

This is helpful for installation. Make sure you install at least version 15. You can then run sudo -u postgres psql and execute commands from there. For example, for creating a new role:

sudo -u postgres psql createuser --interactive

Please note that for searching via PostgreSQL, you need to get into the PSQL shell via psql and run:

CREATE EXTENSION IF NOT EXISTS "pg_trgm";

create or replace function most_similar(text, text[]) returns double precision
language sql as $$
    select max(similarity($1,x)) from unnest($2) f(x)
$$;

The init:db script (see below) runs these for you, but it is recommended that you execute the scripts in your terminal just in case the script fails. FYI, if you have an issue running psql saying, "role root does not exist", run this:

sudo -i
sudo -i -u postgres
psql

To create a user, run:

# Creates an user
CREATE USER python with PASSWORD 'python';

# Changes the password
ALTER USER postgres WITH PASSWORD 'password';

And then update the .env file with the correct database URL. Then, run the following commands:

# Generate the Prisma client
npx prisma generate

# Migrates the database
npx prisma migrate dev

# Push the Prisma schema to the database
npx prisma db push

# You can also use yarn
yarn prisma db migrate dev
yarn prisma db push

# Initialize the database and adds necessary extensions.
npm run init:db

Then you can use the library like so:

// You will likely need to provide a database URL in the options path
// The URL is postgresql://{username}:{password}@{host}:{port}/{database_name}
// database_name can be an optional value as shown below
const anify = new Anify({ database_url: "postgresql://postgres:password@localhost:3306" });

If you don't have MacOS, you can download PostgreSQL and follow the tutorial on their website. If you want to use a GUI, you can use other tools like Postico.

Please view this for more information. If you need help with development, join our Discord and view the #help channel.

Contribution

This API is a work-in-progress, so contribution would be appreciated. If you'd like to contribute, feel free to open a Pull Request.

TBD

The README for this project isn't done! Join our Discord for more information.