Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit f045ecd

Browse files
authored
Merge pull request #19 from fabiopbx/feature/mangadexV5
Updated plugin to support the Mangadex V5 api
2 parents c507319 + 26ee069 commit f045ecd

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

plugins/mangadexV5/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# MangaDex Plugin
2+
3+
This is the Mango plugin for [MangaDex](https://mangadex.org/) using the latest V5 api version.
4+
5+
Maintained by [@fabiopbx](https://github.com/fabiopbx).

plugins/mangadexV5/index.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
var chapter;
2+
var currentPage;
3+
4+
function listChapters(query) {
5+
var mangaJson = {};
6+
var json = {};
7+
8+
var mangaURL = 'https://api.mangadex.org/manga/' + query;
9+
10+
try {
11+
mangaJson = JSON.parse(mango.get(mangaURL).body);
12+
} catch (e) {
13+
mango.raise('Failed to get JSON from ' + URL);
14+
}
15+
16+
if (mangaJson.result !== 'ok')
17+
mango.raise('JSON status: ' + mangaJson.result);
18+
19+
var URL = 'https://api.mangadex.org/manga/' + query + '/feed';
20+
21+
try {
22+
json = JSON.parse(mango.get(URL).body);
23+
} catch (e) {
24+
mango.raise('Failed to get JSON from ' + URL);
25+
}
26+
27+
if (json.result !== 'ok')
28+
mango.raise('JSON status: ' + json.result);
29+
30+
var chapters = [];
31+
Object.keys(json.data).forEach(function(id) {
32+
var obj = json.data[id];
33+
34+
var time = new Date(obj['attributes']['createdAt']);
35+
36+
var slimObj = {};
37+
slimObj['id'] = obj['id'].replace(/\-/g, "_");
38+
slimObj['volume'] = obj['attributes']['volume'];
39+
slimObj['chapter'] = obj['attributes']['chapter'];
40+
slimObj['title'] = 'v' + obj['attributes']['volume'] + ' c' + obj['attributes']['chapter'] + ' - ' + obj['attributes']['title'];
41+
slimObj['lang'] = obj['attributes']['translatedLanguage'];
42+
slimObj['groups'] = null;
43+
slimObj['time'] = time;
44+
45+
chapters.push(slimObj);
46+
});
47+
48+
return JSON.stringify({
49+
title: mangaJson['data']['attributes']['title']['en'],
50+
chapters: chapters
51+
});
52+
}
53+
54+
function selectChapter(id) {
55+
id = id.replace(/\_/g, "-");
56+
var json = {};
57+
var URL = 'https://api.mangadex.org/chapter/' + id;
58+
59+
try {
60+
json = JSON.parse(mango.get(URL).body);
61+
} catch (e) {
62+
mango.raise('Failed to get JSON from ' + URL);
63+
}
64+
65+
if (json.result !== 'ok')
66+
mango.raise('JSON status: ' + json.result);
67+
68+
chapter = json;
69+
currentPage = 0;
70+
71+
var info = {
72+
title: 'v' + json['data']['attributes']['volume'] + ' c' + json['data']['attributes']['chapter'] + ' - ' + json['data']['attributes']['title'].trim(),
73+
pages: json['data']['attributes']['pages']
74+
};
75+
return JSON.stringify(info);
76+
}
77+
78+
function nextPage() {
79+
var URL = 'https://api.mangadex.org/at-home/server/' + chapter.data.id;
80+
81+
if (currentPage >= chapter['data']['attributes']['pages'])
82+
return JSON.stringify({});
83+
84+
try {
85+
json = JSON.parse(mango.get(URL).body);
86+
} catch (e) {
87+
mango.raise('Failed to get JSON from ' + URL);
88+
}
89+
90+
if (json.result !== 'ok')
91+
mango.raise('JSON status: ' + json.result);
92+
93+
var fn = json['chapter']['data'][currentPage];
94+
var info = {
95+
filename: fn,
96+
url: json['baseUrl'] + '/data/' + json['chapter']['hash'] + '/' + fn
97+
};
98+
99+
currentPage += 1;
100+
return JSON.stringify(info);
101+
}

plugins/mangadexV5/info.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "mangadexV5",
3+
"title": "MangaDexV5",
4+
"author": "Fabio Rodrigues",
5+
"version": "v1.1",
6+
"placeholder": "MangaDex manga UUID (e.g., f7f430ab-2c24-49d3-b698-c9ff4787805b)",
7+
"wait_seconds": 5
8+
}

0 commit comments

Comments
 (0)