项目作者: md-y

项目描述 :
The largest MangaDex API
高级语言: JavaScript
项目地址: git://github.com/md-y/mangadex-full-api.git
创建时间: 2019-02-02T05:33:47Z
项目社区:https://github.com/md-y/mangadex-full-api

开源协议:MIT License

下载


MangaDex Full API

An unofficial MangaDex API built with the official JSON API. Supports Node.js and browsers.

Documentation

Version
License
Downloads

  1. npm install mangadex-full-api@6.0.0
  1. // Demo
  2. Manga.search({
  3. title: 'One Piece',
  4. limit: Infinity, // API Max is 100 per request, but this function accepts more
  5. hasAvailableChapters: true,
  6. }).then((mangas) => {
  7. console.log('There are', mangas.length, 'mangas with One Piece in the title!');
  8. mangas.forEach((manga) => {
  9. console.log(manga.localTitle);
  10. });
  11. });

Tutorials

View more info on the documentation website.

Authentication

To login with a personal account, you must have a Client ID and Secret.

  1. await loginPersonal({
  2. clientId: 'id',
  3. clientSecret: 'secret',
  4. password: 'password',
  5. username: 'username',
  6. });

Page Images

  1. // Get a manga with chapters
  2. const manga = await Manga.getByQuery({ order: { followedCount: 'desc' }, availableTranslatedLanguage: ['en'] });
  3. if (!manga) throw new Error('No manga found!');
  4. // This will get the first English chapter for this manga
  5. const chapters = await manga.getFeed({ translatedLanguage: ['en'], limit: 1 });
  6. const chapter = chapters[0];
  7. // Get the image URLs for this chapter
  8. const pages = await chapter.getReadablePages();
  9. console.log(pages);

Relationships

MangaDex will return Relationship objects for associated data objects instead of the entirety of each object.

For example, authors and artists will be returned as Relationship<Author> when requesting a manga. To request the author data, use the resolve method.

Additionally, you can supply 'author' to the includes parameter to include the author data alongside the manga request. You will still need to call the resolve method, but the promise will return instantly.

  1. const manga = await Manga.getRandom();
  2. const firstAuthor = await manga.authors[0].resolve();
  3. console.log('The first author is', firstAuthor.name);
  4. // Use resolveArray to resolve an array of Relationships more efficiently
  5. const allAuthors = await resolveArray(manga.authors);
  6. console.log('All authors are', allAuthors.map((a) => a.name).join(', '));
  7. // Because authors are included, the author relationships are cached
  8. const otherManga = await Manga.getByQuery({ includes: ['author'] });
  9. if (otherManga) {
  10. console.log('The authors for this manga are included and cached:', otherManga.authors[0].cached);
  11. const author = await otherManga.authors[0].resolve();
  12. console.log('The author is', author.name);
  13. }

Finding Manga

The most common way to find manga is to use the search method. However, there are a few other ways as well:

  1. // Basic Search
  2. Manga.search({
  3. title: 'One Piece',
  4. limit: Infinity, // API Max is 100 per request, but this function accepts more
  5. hasAvailableChapters: true,
  6. }).then((mangas) => {
  7. console.log('There are', mangas.length, 'mangas with One Piece in the title!');
  8. mangas.forEach((manga) => {
  9. console.log(manga.localTitle);
  10. });
  11. });
  12. // This will return the first result from a search
  13. Manga.getByQuery({ title: 'One Piece' }).then((manga) => {
  14. if (manga) console.log('Found a One Piece manga with id', manga.id);
  15. else console.log('No One Piece manga found');
  16. });
  17. // You can get a random manga
  18. Manga.getRandom().then((manga) => console.log('Random:', manga.localTitle));
  19. // You can get manga directly by UUID
  20. Manga.get('manga-uuid-here').then((manga) => console.log(manga));

Uploading Chapters

  1. // Login with your credentials
  2. await loginPersonal({
  3. clientId: 'id',
  4. clientSecret: 'secret',
  5. password: 'password',
  6. username: 'username',
  7. });
  8. // Create a new chapter upload session for a manga
  9. const session = await UploadSession.begin('manga-id', ['group-id']);
  10. // Upload pages as Blobs
  11. await session.uploadPages([
  12. new Blob([fs.readFileSync('path/to/page1.jpg')], new Blob([fs.readFileSync('path/to/page2.jpg')])),
  13. ]);
  14. // Commit the chapter
  15. await session.commit({
  16. chapter: '1',
  17. title: 'A new chapter!',
  18. translatedLanguage: 'en',
  19. volume: '1',
  20. });