Skip to content

ntbm/mangadex-sharp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MangaDexSharp

MangaDexSharp is an unofficial .NET library implementing some basic MangaDex(https://mangadex.org) API operations (Mostly read ones)
MangaDex API documentation can be found here: https://api.mangadex.org

About

MangaDex is an ad-free manga reader offering high-quality images!: https://mangadex.org

The library is not official and made for personal purposes.
It implements most of common api operations for common users and is oriented to provide simple access to most used and basic read operations

Nothing related to uploading/creating new resources via API is implemented


Be aware to do alot of requests because of rate limiters (https://api.mangadex.org/docs.html#section/Rate-limits), as these aren't implemented, and taking care of them is on the side of application, using the library.

Usage

  • MangaDexSharp.Parameters - This namespace provides access to query parameters that are used in API requests
  • MangaDexSharp.Resources - This namespace contains Entities/Objects retrieved by API

MangaDexSharp.MangaDexClient is the main entry point.
Api endpoints can be accessed via client, and currently presented Apis are:

  • MangaDexClient.AtHome
  • MangaDexClient.Auth
  • MangaDexClient.Author
  • MangaDexClient.Follows
  • MangaDexClient.Chapter
  • MangaDexClient.Cover
  • MangaDexClient.List
  • MangaDexClient.Manga
  • MangaDexClient.Group
  • MangaDexClient.User

Properties of MangaDexClient listed above are instances of the APIs.
It is very recommended to check official api documentation (https://api.mangadex.org) to ensure call is correct.


Simple example below:

using System;
using MangaDexSharp;
using MangaDexSharp.Resources;

class Program
{
    public static void Main(String[] args)
    {
            //Creating client
            var client = new MangaDexClient();
            
            //Defining ID of manga to get. (Pandora Hearts in the test)
            //https://mangadex.org/title/25aaabb1-9f74-4469-a8d6-1eac5924cc79/pandora-hearts
            Guid pandoraHearts = new Guid("25aaabb1-9f74-4469-a8d6-1eac5924cc79");
            //Getting manga resource
            Manga pandora = await client.Manga.ViewManga(pandoraHearts);

            //Displaying default title of Manga
            Console.WriteLine(pandora.Title.Default);
    }
}

Authentication

Authenticating is also supported, and some requests only availible for logged in user.
To authenticate user, it is needed to provide MangaDexSharp.UserCredentials to the client.
Currently logged in can be obtained by MangaDexClient.CurrentUser property and presents unique Resource type LocalUser that provides actions availible only for logged in User. (Such as get followed manga/authors, check User's follow)


Refreshing token happens automatically in background, but it is still possible to update session token manually via AuthApi.RefreshToken()


Example of authenticating below:

using System;
using MangaDexSharp;
using MangaDexSharp.Resources;

class Program
{
    public static void Main(String[] args)
    {
            var client = new MangaDexClient();

            //Creating and passing User's login data to client
            var credentials = new UserCredentials("username", "email", "password");
            client.SetUserCredentials(credentials);
            
            //Waiting for authenticating
            await client.Auth.Login();

            //Displaying current user's name
            Console.WriteLine(client.CurrentUser.Username);
    }
}

Calls on entities

While API provide raw implementation of enpoint, Resources have some methods (For example, Manga Resource has method called GetFeed)
Methods executed on entities/resource automatically apply MangaDexSharp.MangaDexClient.Settings where possible in requests. Such as ItemsPerPage, or content filters, or translated languages.
These filters will be added automatically where possible if method is called on Resource (Direct API calls aren't affected by Settings)

Example:

using System;
using MangaDexSharp;
using MangaDexSharp.Constants;
using MangaDexSharp.Resources;

class Program
{
    public static void Main(String[] args)
    {
            //Creating client
            var client = new MangaDexClient();
            //Adding English language code (en) to languages
            client.Settings.AddTranslatedLanguage(LanguageKeys.English);

            //Defining ID of manga to get. (Pandora Hearts in the test)
            //https://mangadex.org/title/25aaabb1-9f74-4469-a8d6-1eac5924cc79/pandora-hearts
            Guid pandoraHearts = new Guid("25aaabb1-9f74-4469-a8d6-1eac5924cc79");
            //Getting manga resource
            //This call is not affected by Settings, because it is direct API call.
            Manga pandora = await client.Manga.ViewManga(pandoraHearts);

            //This call IS affected by Settings, because executed on Resource.
            //The feed only includes chapters translated to English
            var feed = await pandora.GetFeed();
    }
}

Project structure

  • Api - Contains raw API implementations.
  • Constants - Contains some useful constant values (Such as language keys).
  • Collections - Contains some collections.
  • Enums - Contains enums for Resources.
  • Exceptions - Custom exceptions that can be thrown by API calls.
  • Internal - Some scary internal things, such as objects mapping, etc...
  • Objects - Entities that make aren't actual Resources, but have logical relation to them.
  • Parameters - Query parameters for API calls.
  • Resourcse - Contains Resources objects themselves.

Not everything is tested

About

Unofficial C# implementation of MangaDex (https://mangadex.org) API

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • C# 100.0%