Code Monkey home page Code Monkey logo

mangadex_library's Introduction

A dart library to facilitate easier access to the mangadex API

WARNING! In progress library

The library is currently in an under development and gradually changing state and therefore doesn't contain many of the features and new features and bugs are added often. At the current state of the library, it is able to:

  • Get login refresh and session tokens
  • Logout user
  • Search for Mangas
  • Get Manga thumbnails/covers
  • Get manga chapters
  • Retieve Manga pages
  • Get logged in user data
  • Get a user's details
  • Get an author's details
  • Manage Custom Lists
  • Check/Follow/Unfollow a Manga/Group/User
  • Set/Get the reading status of a manga for the logged in user
  • Get, Create and Delete Scanlation Groups

Breaking changes from 2.0.0

mangadex_library previously was only a set of static functions which were working fine but there were a few number of things that could be handled more gracefully, the issues mainly being:

  • The single library file became a pile of static functions which made it difficult to understand and work upon
  • Refreshing of tokens was left to the user to handle manually by only providing the functions to refresh.

Seeing these problems the following breaking changes has been introduced:

  • The library is now more client based than just static functions, you can now have a MangadexClient instance that upon using the login function will automatically refresh the token every 14 minutes which can be changed if needed. There is also an onrefresh callback function which is run on a successful token refresh to do any custom jobs.
  • All functions have been placed in their own repositories so that adding of more features in the future can be more easier.

For usage, please refer to the example provided.

ToJson() model methods are NOT STABLE

The toJson() methods of all json model classes are not stable, this is because mangadex returns a list type [] in case an object is empty, for example a description may become an empty list instead of an empty object if the description is empty.

Quickstart

A quick demonstration of the API:

import 'package:mangadex_library/mangadex_client.dart';
import 'package:mangadex_library/mangadex_server_exception.dart';
import 'package:mangadex_library/src/client_types/personal_client.dart';

void main() {
  printFilenames();
}

void printFilenames() async {
  const clientId = 'YOUR_CLIENT_ID';
  const clientSecret = 'YOUR_CLIENT_SECRET';
  // Please refer to https://api.mangadex.org/docs/02-authentication/personal-clients/
  // for retrieving Client ID and Client Secret
  final client =
      MangadexPersonalClient(clientId: clientId, clientSecret: clientSecret);
  // this function, needs a mangadex account username and password supplied
  // to retrive login token
  var username = 'USERNAME'; // Put your username here
  var password = 'PASSWORD'; // Put your password here

  //The line below uses the login function and takes in
  //two String parameters, username and password and returns
  //an instance of the Login class
  try {
    //This login functions logs the user in and sets the login tokens.
    await client.login(username, password);

    var searchData = await client.search(
        query:
            'oregairu'); //This is a search function that queries mangadex for the name of a manga
    // it returns a Search class instance
    // For now, it searches for the Oregairu manga. You may replace the String value with your desired query.

    var mangaID = searchData.data![0]
        .id; // this line gets the manga ID from the instance of the Search we just obtained
    //for demonstration we are talking the manga ID of only the first search result
    //Manga ID is unique to every manga and therefore is required to obtain any information regarding it
    //For example, chapter pages and thumbnails.
    var chapterData = await client.getChapters(
        mangaID!); //This function returns an instance of the ChapterData class,
    // it contains info on all the chapters of the manga ID it has been provided.

    var chapterID = chapterData.data![0]
        .id; // This line sets the chapterID variable to the chapter id of
    // the first chapter from the chapterData we just got.
    //Every chapter has a usique chapter ID and a chapter Hash
    //Chapter ID is required to access info of the desired chapter.
    //Chapter Hash is required for requesting manga pages.
    //All Chapter Hash and Chapter filenames can be requested by using the getBaseUrl() function
    var baseUrl = await client.getBaseUrl(chapterID!);
    //This look prints all urls to all the pages of the chapterID
    baseUrl.chapter!.dataSaver!.forEach((filename) {
      print(client.constructPageUrl(
          baseUrl.baseUrl!, true, baseUrl.chapter!.hash!, filename));
    });
  } on MangadexServerException catch (e) {
    e.info.errors!.forEach((error) {
      print(error
          .title); // print error details if a server exception occurs (like invalid username or password)
      print(error.detail);
    });
  }
  //disposing of client is needed as the refresh timer will still be running.
  client.dispose();
}

Documentation

The documentation is still under progress using the wiki, I have planned to put in a detailed one and so it will take time. for now the generated html docs using dartdoc can be found in the doc/api/ folder.

Contact

I'm not always active on github but you can always find me on discord, my ID: Rick~#9387 my ID: karna.satva

mangadex_library's People

Contributors

riktam-santra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lawrence2001-zz

mangadex_library's Issues

Query as anonymous

Im using your lib, but the version is before 2.0.0, i saw u updated version to 2.0.5, but seem like you are require user to login to query
Is there any way to query without auth

Refactor searchResponse Method

  1. IncludedTags = IncludedTags + '&includedTages[]=$element'; -> IncludedTags = IncludedTags + '&includedTags[]=$element';
  2. var Order = order != null
    ? '&order[${order.entries.first}]=${order[order.entries.first]}'
    : '&order[recentlyUpdated]=desc'; -> recentlyUpdated is a validation error for the order query

bug when fetching search results

When searching the data comes back empty. Taking a closer look at the problem I saw a typo in search.dart when getting the http response, it says dara instead of data. Hope this helps. Is my first time posting an issue.

///@nodoc
import 'package:mangadex_library/models/common/data.dart';

class Search {
  late final String result;
  late final String response;
  late final List<Data> data;
  late final int limit;
  late final int offset;
  late final int total;
  Search(this.data, this.limit, this.offset, this.total);
  Search.fromJson(Map<String, dynamic> json) {
    result = json['result'] ?? '';

    response = json['response'] ?? '';
    data = <Data>[];
    --> if (json['dara'] != null) { <--
      json['data'].forEach((v) {
        data.add(Data.fromJson(v));
      });
    }

    limit = json['limit'] ?? 0;
    offset = json['offset'] ?? 0;
    total = json['total'] ?? 0;
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.