Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated plugin to support the Mangadex V5 api #19

Merged
merged 3 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/mangadexV5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# MangaDex Plugin

This is the Mango plugin for [MangaDex](https://mangadex.org/) using the latest V5 api version.

Maintained by [@fabiopbx](https://github.com/fabiopbx).
101 changes: 101 additions & 0 deletions plugins/mangadexV5/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
var chapter;
var currentPage;

function listChapters(query) {
var mangaJson = {};
var json = {};

var mangaURL = 'https://api.mangadex.org/manga/' + query;

try {
mangaJson = JSON.parse(mango.get(mangaURL).body);
} catch (e) {
mango.raise('Failed to get JSON from ' + URL);
}

if (mangaJson.result !== 'ok')
mango.raise('JSON status: ' + mangaJson.result);

var URL = 'https://api.mangadex.org/manga/' + query + '/feed';

try {
json = JSON.parse(mango.get(URL).body);
} catch (e) {
mango.raise('Failed to get JSON from ' + URL);
}

if (json.result !== 'ok')
mango.raise('JSON status: ' + json.result);

var chapters = [];
Object.keys(json.data).forEach(function(id) {
var obj = json.data[id];

var time = new Date(obj['attributes']['createdAt']);

var slimObj = {};
slimObj['id'] = obj['id'].replace(/\-/g, "_");
slimObj['volume'] = obj['attributes']['volume'];
slimObj['chapter'] = obj['attributes']['chapter'];
slimObj['title'] = 'v' + obj['attributes']['volume'] + ' c' + obj['attributes']['chapter'] + ' - ' + obj['attributes']['title'];
slimObj['lang'] = obj['attributes']['translatedLanguage'];
slimObj['groups'] = null;
slimObj['time'] = time;

chapters.push(slimObj);
});

return JSON.stringify({
title: mangaJson['data']['attributes']['title']['en'],
chapters: chapters
});
}

function selectChapter(id) {
id = id.replace(/\_/g, "-");
var json = {};
var URL = 'https://api.mangadex.org/chapter/' + id;

try {
json = JSON.parse(mango.get(URL).body);
} catch (e) {
mango.raise('Failed to get JSON from ' + URL);
}

if (json.result !== 'ok')
mango.raise('JSON status: ' + json.result);

chapter = json;
currentPage = 0;

var info = {
title: 'v' + json['data']['attributes']['volume'] + ' c' + json['data']['attributes']['chapter'] + ' - ' + json['data']['attributes']['title'].trim(),
pages: json['data']['attributes']['pages']
};
return JSON.stringify(info);
}

function nextPage() {
var URL = 'https://api.mangadex.org/at-home/server/' + chapter.data.id;

if (currentPage >= chapter['data']['attributes']['pages'])
return JSON.stringify({});

try {
json = JSON.parse(mango.get(URL).body);
} catch (e) {
mango.raise('Failed to get JSON from ' + URL);
}

if (json.result !== 'ok')
mango.raise('JSON status: ' + json.result);

var fn = json['chapter']['data'][currentPage];
var info = {
filename: fn,
url: json['baseUrl'] + '/data/' + json['chapter']['hash'] + '/' + fn
};

currentPage += 1;
return JSON.stringify(info);
}
8 changes: 8 additions & 0 deletions plugins/mangadexV5/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "mangadexV5",
"title": "MangaDexV5",
"author": "Fabio Rodrigues",
"version": "v1.1",
"placeholder": "MangaDex manga UUID (e.g., f7f430ab-2c24-49d3-b698-c9ff4787805b)",
"wait_seconds": 5
}