mangadex-api
TypeScript icon, indicating that this package has built-in type declarations

5.0.1 • Public • Published

Mangadex-api

NPM Version npm downloads License codecov

This is Mangadex website api wrapper.

WIP on V5 version

Installation

npm i mangadex-api

# or

yarn add mangadex-api

Example

// In V5 Mangadex switched id type from number to string.
// So if you need to convert it, call the convertLegacyId method.
// Soon will be added to usual methods, maybe.

Mangadex.convertLegacyId([12], 'group')
  .then((result) => {
    if (result.result === 'error') {
      console.log(
        `Got error on convertLegacyId request! ${result.errors
          .map((err) => err.title)
          .join(', ')}`
      )
      return
    }

    const { newId } = result.data.attributes

    console.log(`New group id: ${newId}`)
  })

Mangadex.manga
  .getManga(
    'c26269c7-0f5d-4966-8cd5-b79acb86fb7a',
    {
      // will fetch additionally scanlation_group, artist, author attributes
      withRelationShips: true
    }
  )
  .then(({ result, data, errors }) => {
    if (result === 'error') {
      // oh no! something went wrong!
      // here we can handle errors array.
    }

    const { title, originalLanguage } = data.attributes
    console.log(`Manga ${title.en} published in ${originalLanguage}`)

    Mangadex.manga
      .getMangaFeed('c26269c7-0f5d-4966-8cd5-b79acb86fb7a', {
        limit: 10
      })
      .then(({ results: chapters }) => {
        console.log(`Manga ${title.en} has ${chapters.length} chapters`)
        const { volume, chapter } = chapters[0].data.attributes
        console.log(`Latest chapter: Vol ${volume} Ch ${chapter}`)
      })
  })

Mangadex.chapter.getChapter(8857).then((chapter) => {
  if (chapter.result === 'error') {
    console.log(
      `Got errors on chapter request! ${chapter.errors
        .map((err) => err.title)
        .join(', ')}`
    )
    return
  }
  console.log(
    `Chapter title is "${chapter.data.attributes.title}" and it is ${chapter.data.attributes.chapter} chapter from ${chapter.volume} volume.`
  )
})

// currently requires authorization
Mangadex.manga.search({ title: 'senko' }).then(({ total }) => {
  console.log(`Found ${total} titles.`)
})
// Search with NSFW results
Mangadex.manga
  .search({
    title: 'gotoubun',
    contentRating: ['pornographic']
  })
  .then((result) => {
    console.log(`Found ${result.results.length} hentai manga (☞ ͡ ͡° ͜ ʖ ͡ ͡°)☞`)
  })

Mangadex.group.getGroup(12).then((group) => {
  if (group.result === 'error') {
    console.log(
      `Got errors from group request! ${group.errors
        .map((err) => err.title)
        .join(', ')}`
    )
    return
  }
  const { name, members } = group.data.attributes
  console.log(`Group ${name} has ${members} members`)
})

Authorization example

const { Mangadex } = require('mangadex-api')

const client = new Mangadex()

const loginResult = await client.auth.login('username', 'password')

if (loginResult.result === 'error') {
  // oh no! it's login error!
}

const result = await client.manga.search('To Be Winner')

console.log(result)

Cached session example

// first you must save your session somewhere

const loginResult = await client.auth.login('username', 'password')

if (loginResult.result === 'error') {
  // oh no! it's login error!
}

await client.agent.saveSession('/path/to/session'))

// now we can use it

await client.agent.loginWithSession('/path/to/session')

const me = await client.user.getMe()

console.log(me)

API

API section is available on the website.

Additional resources

  • mangadex-heroku is a GraphQL public endpoint. (not updated to V5 yet)
    Supports caching (in memory) and all public MD-API's that doesn't require authorization. (playground)
  • Example webapp that uses mangadex-heroku for API calls. (not updated to V5 yet)

Contact

My telegram and a group where you can ask your questions or suggest something.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
5.0.14latest
5.0.0-alpha.11alpha

Version History

VersionDownloads (Last 7 Days)Published
5.0.14
5.0.0-alpha.11
5.0.0-alpha.01
5.0.01
4.6.414
4.6.31
4.6.21
4.6.11
4.6.01
4.5.11
4.5.01
4.4.11
4.4.01
4.3.11
4.3.01
4.2.31
4.2.21
4.2.11
4.2.01
4.1.41
4.1.31
4.1.21
4.1.11
4.1.01
4.0.11
4.0.01
3.0.81
3.0.71
3.0.61
3.0.51
3.0.41
3.0.31
3.0.22
3.0.11
3.0.01
2.0.101
2.0.91
2.0.81
2.0.7-b1
2.0.71
2.0.61
2.0.51
2.0.41
2.0.35
2.0.21
2.0.1-b1
2.0.0-b1
1.0.102
1.0.92
1.0.81
1.0.71
1.0.61
1.0.51
1.0.41
1.0.3-b1
1.0.31
1.0.21
1.0.1-b1
1.0.11
1.0.01

Package Sidebar

Install

npm i mangadex-api

Weekly Downloads

83

Version

5.0.1

License

MIT

Unpacked Size

113 kB

Total Files

78

Last publish

Collaborators

  • ejnshtein