Skip to content

Examples

Proxymiity edited this page May 26, 2021 · 2 revisions

For every example, this guide will be importing the MangaDexPy and put the client in a variable named cli.

import MangaDexPy
cli = MangaDexPy.MangaDex()

Get all covers for a Manga

def get_covers_for(manga_id: str):
    # Asking the API about that manga with uuid 'manga_id'
    manga = cli.get_manga(manga_id)
    # Printing a message with manga.title, the Manga's title
    print("Getting covers for " + manga.title)
    # Call manga.get_covers(), which returns an Array of Covers that we iterate over
    for cover in manga.get_covers():
        # Getting the "volume" and "url" properties of the Cover object
        # Note that some covers can have a None volume, hence the 'cover.volume or unknown'
        print("Volume " + (cover.volume or 'unknown') + "'s cover: " + cover.url)
>>> get_covers_for('b9797c5b-642e-44d9-ac40-8b31b9ae110a')
Getting covers for Tsuki ga Kirei Desu ne
Volume 0's cover: https://uploads.mangadex.org/covers/b9797c5b-642e-44d9-ac40-8b31b9ae110a/332283bb-33d2-4191-8867-f9c8b6c5f893.jpg
Volume 3's cover: https://uploads.mangadex.org/covers/b9797c5b-642e-44d9-ac40-8b31b9ae110a/a11f5e5a-38d2-4b33-a804-cb06a3e76417.jpg
Volume 5's cover: https://uploads.mangadex.org/covers/b9797c5b-642e-44d9-ac40-8b31b9ae110a/3c6d9a92-a2f2-4b86-bf6e-7e0a853c42a6.jpg
Volume 2's cover: https://uploads.mangadex.org/covers/b9797c5b-642e-44d9-ac40-8b31b9ae110a/97edd6a2-a45a-49fa-a5f8-3e0528ee815f.jpg
Volume 4's cover: https://uploads.mangadex.org/covers/b9797c5b-642e-44d9-ac40-8b31b9ae110a/8d8b52af-66eb-41cc-bb95-0b07e5fbc303.jpg
Volume 6's cover: https://uploads.mangadex.org/covers/b9797c5b-642e-44d9-ac40-8b31b9ae110a/025f4e2f-cac3-4a0a-813f-fa4c7f0a2399.jpg
Volume 1's cover: https://uploads.mangadex.org/covers/b9797c5b-642e-44d9-ac40-8b31b9ae110a/1aaa241a-7434-488e-983c-4d62ed6a05e9.jpg

Download a Manga's latest Chapter

# Importing the downloader tool
from MangaDexPy import downloader
def download_latest_chapter(manga_id: str):
    # Asking the API about that manga with uuid 'manga_id'
    manga = cli.get_manga(manga_id)
    # Getting chapters for that manga
    chapters = manga.get_chapters()
    # Getting the latest item in the list into a variable
    latest_chapter = chapters[-1]
    # Telling the downloader to download in a folder
    # Note that you need to escape backslashes in Python
    downloader.dl_chapter(chapter, "C:\\Users\\Proxy\\Downloads\\Manga")

Error management (404s, etc.)

def check_untrusted_user_input(chapter_id: str):
    # Getting a chapter via the API
    try
      chapter = cli.get_chapter(chapter_id)
      # The chapter exists: no error is raised
      print("This chapter exists!")
    except MangaDexPy.NoContentError:
      # API returned a 404 Not Found, therefore the wrapper will return a NoContentError
      print("This chapter doesn't exist.")
    except MangaDexPy.APIError as e:
      # API returned something that wasn't expected, the wrapper will return an APIError
      print("Something weird happened with the API.")
      print("Status code is: " + str(e.status))
Clone this wiki locally