4anime 中文文档教程

发布于 4年前 浏览 69 更新于 3年前

4anime Web scraper

这个动漫网络抓取工具使用 4anime.to 网站来获取平台上可用的任何动漫的数据。

数据包括名称、流派、描述、节目类型、制作节目的工作室、发布日期、状态(即已完成或正在进行)、语言(即字幕或配音)、页面的 url , 和剧集。

剧集具有以下信息:剧集 ID、剧集编号和剧集 URL。

Installation

npm install 4anime

Information

Anime object structure

Anime {
  name: string,
  genres: array of strings,
  description: string,
  imageUrl: string,
  type: string,
  studio: string,
  releaseDate: string,
  status: string,
  language: string,
  url: string,
  episodes: array of objects
}

Episode object structure

    {
      id: int,
      episode: int,
      url: string
    }

Usage

这个包有两个功能。 一个接受一个字符串并返回来自搜索结果的所有动漫的列表。 另一个接受动画页面的 url,并返回与该页面有关的所有数据。

Getting data from url

Anime.getAnimeFromURL("https://4anime.to/anime/the-god-of-high-school")
    .then(res => {
        console.log(res);
    });

Sample response

Anime {
  name: 'The God of High School',
  genres: [
    'Action',
    'Adventure',
    'Comedy',
    'Fantasy',
    'Martial Arts',
    'Sci-Fi',
    'Supernatural'
  ],
  description: 'It all began as a fighting tournament to seek out for the best fighter among all high school students in Korea. Mori Jin, a Taekwondo specialist and a high school student, soon learns that there is something much greater beneath the stage of the tournament.',
  type: 'TV Series',
  studio: 'MAPPA',
  releaseDate: 'Summer, 2020',
  status: 'Currently Airing',
  language: 'Subbed',
  url: 'https://4anime.to/anime/the-god-of-high-school',
  episodes: [
    {
      id: 42172,
      episode: 1,
      url: 'https://4anime.to/the-god-of-high-school-episode-01/?id=42172'
    },
    {
      id: 42546,
      episode: 2,
      url: 'https://4anime.to/the-god-of-high-school-episode-02/?id=42546'
    },
    {
      id: 42710,
      episode: 3,
      url: 'https://4anime.to/the-god-of-high-school-episode-03/?id=42710'
    },
    {
      id: 42822,
      episode: 4,
      url: 'https://4anime.to/the-god-of-high-school-episode-04/?id=42822'
    },
    {
      id: 42950,
      episode: 5,
      url: 'https://4anime.to/the-god-of-high-school-episode-05/?id=42950'
    }
  ]
}

Getting data from a search

const Anime = require('4anime').default;

Anime.getAnimeFromSearch("enen no shouboutai")
    .then(res => {
        console.log(res);
    });

Getting the video link from an episode url

const Anime = require('4anime').default;

Anime.getVideoLinkFromUrl("https://4anime.to/one-piece-episode-938?id=43181")
    .then(res => {
        console.log(res);
    });
Anime.getOngoingLinks()
  .then(res => {
    console.log(res);
  });

此函数接收从 getVideoLinkFromURL() 函数返回的视频链接,并在 .js 文件的当前工作目录或给定路径中下载视频。

// No given path
Anime.downloadVideoFromLink("https://storage.googleapis.com/justawesome-183319.appspot.com/v2.4animu.me/Higurashi-no-Naku-Koro-ni-Gou/Higurashi-no-Naku-Koro-ni-Gou-Episode-04-1080p.mp4")

// With a given path
Anime.downloadVideoFromLink("https://storage.googleapis.com/justawesome-183319.appspot.com/v2.4animu.me/Higurashi-no-Naku-Koro-ni-Gou/Higurashi-no-Naku-Koro-ni-Gou-Episode-04-1080p.mp4", "./test")

Changes

  • Fixed "undefined" TypeError in getAnimeFromURL
  • Fixed 403 errors in episode links
  • Added video download functionality

4anime Web scraper

This anime web scraper uses the 4anime.to website to get data of any anime available on the platform.

The data includes the name, the genres, the description, the type of show, the studio that produced the show, the release date, the status- i.e. completed or ongoing-, the language- i.e. subbed or dubbed, the url of the page, and the episodes.

The episodes have the following information: the episode id, the episode number, and the episode url.

Installation

npm install 4anime

Information

Anime object structure

Anime {
  name: string,
  genres: array of strings,
  description: string,
  imageUrl: string,
  type: string,
  studio: string,
  releaseDate: string,
  status: string,
  language: string,
  url: string,
  episodes: array of objects
}

Episode object structure

    {
      id: int,
      episode: int,
      url: string
    }

Usage

There are two functions to this package. One takes in a string and returns a list of all anime that came from the search result. The other takes in a url to the anime page and returns all the data regarding that page alone.

Getting data from url

Anime.getAnimeFromURL("https://4anime.to/anime/the-god-of-high-school")
    .then(res => {
        console.log(res);
    });

Sample response

Anime {
  name: 'The God of High School',
  genres: [
    'Action',
    'Adventure',
    'Comedy',
    'Fantasy',
    'Martial Arts',
    'Sci-Fi',
    'Supernatural'
  ],
  description: 'It all began as a fighting tournament to seek out for the best fighter among all high school students in Korea. Mori Jin, a Taekwondo specialist and a high school student, soon learns that there is something much greater beneath the stage of the tournament.',
  type: 'TV Series',
  studio: 'MAPPA',
  releaseDate: 'Summer, 2020',
  status: 'Currently Airing',
  language: 'Subbed',
  url: 'https://4anime.to/anime/the-god-of-high-school',
  episodes: [
    {
      id: 42172,
      episode: 1,
      url: 'https://4anime.to/the-god-of-high-school-episode-01/?id=42172'
    },
    {
      id: 42546,
      episode: 2,
      url: 'https://4anime.to/the-god-of-high-school-episode-02/?id=42546'
    },
    {
      id: 42710,
      episode: 3,
      url: 'https://4anime.to/the-god-of-high-school-episode-03/?id=42710'
    },
    {
      id: 42822,
      episode: 4,
      url: 'https://4anime.to/the-god-of-high-school-episode-04/?id=42822'
    },
    {
      id: 42950,
      episode: 5,
      url: 'https://4anime.to/the-god-of-high-school-episode-05/?id=42950'
    }
  ]
}

Getting data from a search

const Anime = require('4anime').default;

Anime.getAnimeFromSearch("enen no shouboutai")
    .then(res => {
        console.log(res);
    });

Getting the video link from an episode url

const Anime = require('4anime').default;

Anime.getVideoLinkFromUrl("https://4anime.to/one-piece-episode-938?id=43181")
    .then(res => {
        console.log(res);
    });
Anime.getOngoingLinks()
  .then(res => {
    console.log(res);
  });

This function takes in the video link returned from the getVideoLinkFromURL() function and downloads the video either in current working directory of the .js file or a given path.

// No given path
Anime.downloadVideoFromLink("https://storage.googleapis.com/justawesome-183319.appspot.com/v2.4animu.me/Higurashi-no-Naku-Koro-ni-Gou/Higurashi-no-Naku-Koro-ni-Gou-Episode-04-1080p.mp4")

// With a given path
Anime.downloadVideoFromLink("https://storage.googleapis.com/justawesome-183319.appspot.com/v2.4animu.me/Higurashi-no-Naku-Koro-ni-Gou/Higurashi-no-Naku-Koro-ni-Gou-Episode-04-1080p.mp4", "./test")

Changes

  • Fixed "undefined" TypeError in getAnimeFromURL
  • Fixed 403 errors in episode links
  • Added video download functionality
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文