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",
"typeSource": "single",
"itemType": 0,
"version": "0.1.21",
"version": "0.1.23",
"dateFormat": "",
"dateFormatLocale": "",
"pkgPath": "manga/src/all/mangafire.js"
}];
class DefaultExtension extends MProvider {
getPreference(key) {
return new SharedPreferences().get(key);
}
mangaListFromPage(res) {
const doc = new Document(res.body);
const elements = doc.select("div.unit");
const list = [];
for (const element of elements){
const name = element.selectFirst("div.info > a").text;
const imageUrl = element.selectFirst("img").getSrc;
const link = element.selectFirst("a").getHref;
list.push({name, imageUrl, link});
for (const element of elements) {
const name = element.selectFirst("div.info > a").text;
const imageUrl = element.selectFirst("img").getSrc;
const link = element.selectFirst("a").getHref;
list.push({ name, imageUrl, link });
}
const hasNextPage = doc.selectFirst("li.page-item.active + li").text != "";
return { "list": list, "hasNextPage": hasNextPage };
}
statusFromString(status){
statusFromString(status) {
return {
"Releasing": 0,
"Completed": 1,
@@ -41,14 +46,14 @@ class DefaultExtension extends MProvider {
parseDate(date) {
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(" ");
if (!(date[0] in months)) {
return String(new Date().valueOf())
}
date[0] = months[date[0]];
date = [date[2], date[0], date[1]];
date = date.join("-");
@@ -104,19 +109,14 @@ class DefaultExtension extends MProvider {
}
async getDetail(url) {
// get urls
const viewType = this.getPreference("mangafire_pref_content_view")
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 = {};
// request
const idRes = await new Client().get(chapterUrl);
const idDoc = new Document(JSON.parse(idRes.body).result.html);
// extract info
const infoUrl = this.source.baseUrl + url;
const infoRes = await new Client().get(infoUrl);
const infoDoc = new Document(infoRes.body);
// extract info
const info = infoDoc.selectFirst("div.info");
const sidebar = infoDoc.select("aside.sidebar div.meta div");
detail.name = info.selectFirst("h1").text;
@@ -130,23 +130,40 @@ class DefaultExtension extends MProvider {
});
// 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 chapRes = await new Client().get(this.source.baseUrl + `/ajax/manga/${id}/chapter/${this.source.lang}`);
const chapDoc = new Document(JSON.parse(chapRes.body).result);
const chapElements = chapDoc.selectFirst(".scroll-sm").children;
var chapElements = null
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 = [];
for (let i = 0; i < ids.length; i++) {
const name = ids[i].text;
const id = ids[i].attr("data-id");
const url = this.source.baseUrl + `/ajax/read/chapter/${id}`;
let dateUpload;
try {
dateUpload = this.parseDate(chapElements[i].selectFirst("span + span").text);
} catch (_) {
dateUpload = null
const id = ids[i]
const name = id.text;
const mangaId = id.attr("data-id");
var scanlator = null
var dateUpload = null;
if (viewType == "chapter") { // upload date is not present in volumes
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;
}
@@ -265,6 +282,15 @@ class DefaultExtension extends MProvider {
}
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"]
}
}]
}
}