Merge pull request #197 from Swakshan/manga/mangafire

Update: Mangafire
This commit is contained in:
Moustapha Kodjo Amadou
2025-03-19 17:39:04 +01:00
committed by GitHub

View File

@@ -6,30 +6,35 @@ const mangayomiSources = [{
"iconUrl": "https://mangafire.to/assets/sites/mangafire/favicon.png?v3", "iconUrl": "https://mangafire.to/assets/sites/mangafire/favicon.png?v3",
"typeSource": "single", "typeSource": "single",
"itemType": 0, "itemType": 0,
"version": "0.1.21", "version": "0.1.23",
"dateFormat": "", "dateFormat": "",
"dateFormatLocale": "", "dateFormatLocale": "",
"pkgPath": "manga/src/all/mangafire.js" "pkgPath": "manga/src/all/mangafire.js"
}]; }];
class DefaultExtension extends MProvider { class DefaultExtension extends MProvider {
getPreference(key) {
return new SharedPreferences().get(key);
}
mangaListFromPage(res) { mangaListFromPage(res) {
const doc = new Document(res.body); const doc = new Document(res.body);
const elements = doc.select("div.unit"); const elements = doc.select("div.unit");
const list = []; const list = [];
for (const element of elements){ for (const element of elements) {
const name = element.selectFirst("div.info > a").text; const name = element.selectFirst("div.info > a").text;
const imageUrl = element.selectFirst("img").getSrc; const imageUrl = element.selectFirst("img").getSrc;
const link = element.selectFirst("a").getHref; const link = element.selectFirst("a").getHref;
list.push({name, imageUrl, link}); list.push({ name, imageUrl, link });
} }
const hasNextPage = doc.selectFirst("li.page-item.active + li").text != ""; const hasNextPage = doc.selectFirst("li.page-item.active + li").text != "";
return { "list": list, "hasNextPage": hasNextPage }; return { "list": list, "hasNextPage": hasNextPage };
} }
statusFromString(status){ statusFromString(status) {
return { return {
"Releasing": 0, "Releasing": 0,
"Completed": 1, "Completed": 1,
@@ -41,7 +46,7 @@ class DefaultExtension extends MProvider {
parseDate(date) { parseDate(date) {
const months = { const months = {
"jan": "01", "feb": "02", "mar": "03", "apr": "04", "may": "05", "jun": "06", "jul": "07", "aug": "08", "sep": "09", "oct": "10", "nov": "11", "dec": "12" "jan": "01", "feb": "02", "mar": "03", "apr": "04", "may": "05", "jun": "06", "jul": "07", "aug": "08", "sep": "09", "oct": "10", "nov": "11", "dec": "12"
}; };
date = date.toLowerCase().replace(",", "").split(" "); date = date.toLowerCase().replace(",", "").split(" ");
@@ -104,19 +109,14 @@ class DefaultExtension extends MProvider {
} }
async getDetail(url) { async getDetail(url) {
// get urls const viewType = this.getPreference("mangafire_pref_content_view")
const id = url.split(".").pop(); const id = url.split(".").pop();
const infoUrl = this.source.baseUrl + url;
const chapterUrl = this.source.baseUrl + `/ajax/read/${id}/chapter/${this.source.lang}`;
const detail = {}; const detail = {};
// request // extract info
const idRes = await new Client().get(chapterUrl); const infoUrl = this.source.baseUrl + url;
const idDoc = new Document(JSON.parse(idRes.body).result.html);
const infoRes = await new Client().get(infoUrl); const infoRes = await new Client().get(infoUrl);
const infoDoc = new Document(infoRes.body); const infoDoc = new Document(infoRes.body);
// extract info
const info = infoDoc.selectFirst("div.info"); const info = infoDoc.selectFirst("div.info");
const sidebar = infoDoc.select("aside.sidebar div.meta div"); const sidebar = infoDoc.select("aside.sidebar div.meta div");
detail.name = info.selectFirst("h1").text; detail.name = info.selectFirst("h1").text;
@@ -130,23 +130,40 @@ class DefaultExtension extends MProvider {
}); });
// get chapter // get chapter
// /read/ is needed to get chapter details
const chapterUrl = this.source.baseUrl + `/ajax/read/${id}/${viewType}/${this.source.lang}`;
const idRes = await new Client().get(chapterUrl);
const idDoc = new Document(JSON.parse(idRes.body).result.html);
const ids = idDoc.select("a"); const ids = idDoc.select("a");
const chapRes = await new Client().get(this.source.baseUrl + `/ajax/manga/${id}/chapter/${this.source.lang}`);
const chapDoc = new Document(JSON.parse(chapRes.body).result); var chapElements = null
const chapElements = chapDoc.selectFirst(".scroll-sm").children; if (viewType == "chapter") { // upload date is not present in volumes
// /manga/ is needed to get chapter upload date
const chapRes = await new Client().get(this.source.baseUrl + `/ajax/manga/${id}/${viewType}/${this.source.lang}`);
const chapDoc = new Document(JSON.parse(chapRes.body).result);
chapElements = chapDoc.selectFirst(".scroll-sm").children;
}
detail.chapters = []; detail.chapters = [];
for (let i = 0; i < ids.length; i++) { for (let i = 0; i < ids.length; i++) {
const name = ids[i].text; const id = ids[i]
const id = ids[i].attr("data-id"); const name = id.text;
const url = this.source.baseUrl + `/ajax/read/chapter/${id}`; const mangaId = id.attr("data-id");
let dateUpload;
try { var scanlator = null
dateUpload = this.parseDate(chapElements[i].selectFirst("span + span").text); var dateUpload = null;
} catch (_) { if (viewType == "chapter") { // upload date is not present in volumes
dateUpload = null const chapElement = chapElements[i]
var title = chapElement.selectFirst("a").attr("title").split(" - ");
scanlator = title.length > 1 ? title[0] : "Vol 1"
try {
dateUpload = this.parseDate(chapElement.selectFirst("span + span").text);
} catch (_) {
dateUpload = null
}
} }
detail.chapters.push({ name, url, dateUpload }); const url = this.source.baseUrl + `/ajax/read/${viewType}/${mangaId}`;
detail.chapters.push({ name, url, dateUpload, scanlator });
} }
return detail; return detail;
} }
@@ -265,6 +282,15 @@ class DefaultExtension extends MProvider {
} }
getSourcePreferences() { getSourcePreferences() {
throw new Error("getSourcePreferences not implemented"); return [{
key: 'mangafire_pref_content_view',
listPreference: {
title: 'View manga as',
summary: '',
valueIndex: 0,
entries: ["Chapters", "Volumes"],
entryValues: ["chapter", "volume"]
}
}]
} }
} }