mirror of
https://github.com/kodjodevf/mangayomi-extensions.git
synced 2026-02-20 13:50:31 +00:00
Catch http error response
This commit is contained in:
@@ -2,9 +2,14 @@ import 'dart:convert';
|
||||
import 'package:bridge_lib/bridge_lib.dart';
|
||||
|
||||
getPopularManga(MManga manga) async {
|
||||
final url = "${manga.baseUrl}/browse?${lang(manga.lang)}&sort=views_a&page=${manga.page}";
|
||||
final url =
|
||||
"${manga.baseUrl}/browse?${lang(manga.lang)}&sort=views_a&page=${manga.page}";
|
||||
final data = {"url": url, "sourceId": manga.sourceId};
|
||||
final res = await MBridge.http('GET', json.encode(data));
|
||||
final response = await MBridge.http('GET', json.encode(data));
|
||||
if (response.hasError) {
|
||||
return response;
|
||||
}
|
||||
String res = response.body;
|
||||
return mangaElementM(res, manga);
|
||||
}
|
||||
|
||||
@@ -17,15 +22,27 @@ String lang(String lang) {
|
||||
}
|
||||
|
||||
getLatestUpdatesManga(MManga manga) async {
|
||||
final url = "${manga.baseUrl}/browse?${lang(manga.lang)}&sort=update&page=${manga.page}";
|
||||
final url =
|
||||
"${manga.baseUrl}/browse?${lang(manga.lang)}&sort=update&page=${manga.page}";
|
||||
final data = {"url": url, "sourceId": manga.sourceId};
|
||||
final res = await MBridge.http('GET', json.encode(data));
|
||||
final response = await MBridge.http('GET', json.encode(data));
|
||||
if (response.hasError) {
|
||||
return response;
|
||||
}
|
||||
String res = response.body;
|
||||
return mangaElementM(res, manga);
|
||||
}
|
||||
|
||||
searchManga(MManga manga) async {
|
||||
final data = {"url": "${manga.baseUrl}/search?word=${manga.query}&page=${manga.page}", "sourceId": manga.sourceId};
|
||||
final res = await MBridge.http('GET', json.encode(data));
|
||||
final data = {
|
||||
"url": "${manga.baseUrl}/search?word=${manga.query}&page=${manga.page}",
|
||||
"sourceId": manga.sourceId
|
||||
};
|
||||
final response = await MBridge.http('GET', json.encode(data));
|
||||
if (response.hasError) {
|
||||
return response;
|
||||
}
|
||||
String res = response.body;
|
||||
return mangaElementM(res, manga);
|
||||
}
|
||||
|
||||
@@ -41,39 +58,46 @@ getMangaDetail(MManga manga) async {
|
||||
|
||||
final url = "${manga.baseUrl}${manga.link}";
|
||||
final data = {"url": url, "sourceId": manga.sourceId};
|
||||
final res = await MBridge.http('GET', json.encode(data));
|
||||
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
final response = await MBridge.http('GET', json.encode(data));
|
||||
if (response.hasError) {
|
||||
return response;
|
||||
}
|
||||
String res = response.body;
|
||||
|
||||
final workStatus = MBridge.xpath(
|
||||
res, '//*[@class="attr-item"]/b[contains(text(),"Original work")]/following-sibling::span[1]/text()')
|
||||
final workStatus = MBridge.xpath(res,
|
||||
'//*[@class="attr-item"]/b[contains(text(),"Original work")]/following-sibling::span[1]/text()')
|
||||
.first;
|
||||
manga.status = MBridge.parseStatus(workStatus, statusList);
|
||||
|
||||
manga.author =
|
||||
MBridge.xpath(res, '//*[@class="attr-item"]/b[contains(text(),"Authors")]/following-sibling::span[1]/text()')
|
||||
.first;
|
||||
manga.genre =
|
||||
MBridge.xpath(res, '//*[@class="attr-item"]/b[contains(text(),"Genres")]/following-sibling::span[1]/text()')
|
||||
.first
|
||||
.split(",");
|
||||
manga.description = MBridge.xpath(res, '//*[@class="limit-html"]/text()').first;
|
||||
manga.author = MBridge.xpath(res,
|
||||
'//*[@class="attr-item"]/b[contains(text(),"Authors")]/following-sibling::span[1]/text()')
|
||||
.first;
|
||||
manga.genre = MBridge.xpath(res,
|
||||
'//*[@class="attr-item"]/b[contains(text(),"Genres")]/following-sibling::span[1]/text()')
|
||||
.first
|
||||
.split(",");
|
||||
manga.description =
|
||||
MBridge.xpath(res, '//*[@class="limit-html"]/text()').first;
|
||||
|
||||
List<String> chapsElement =
|
||||
MBridge.querySelectorAll(res, selector: "div.main div.p-2", typeElement: 2, attributes: "", typeRegExp: 0);
|
||||
List<String> chapsElement = MBridge.querySelectorAll(res,
|
||||
selector: "div.main div.p-2",
|
||||
typeElement: 2,
|
||||
attributes: "",
|
||||
typeRegExp: 0);
|
||||
List<String> times = [];
|
||||
List<String> chapsUrls = [];
|
||||
List<String> chapsNames = [];
|
||||
List<String> scanlators = [];
|
||||
for (var element in chapsElement) {
|
||||
final urlElement =
|
||||
MBridge.querySelectorAll(element, selector: "a.chapt", typeElement: 2, attributes: "", typeRegExp: 0).first;
|
||||
final urlElement = MBridge.querySelectorAll(element,
|
||||
selector: "a.chapt", typeElement: 2, attributes: "", typeRegExp: 0)
|
||||
.first;
|
||||
final group = MBridge.xpath(element, '//*[@class="extra"]/a/text()').first;
|
||||
final name = MBridge.xpath(urlElement, '//a/text()').first;
|
||||
final url = MBridge.xpath(urlElement, '//a/@href').first;
|
||||
final time = MBridge.xpath(element, '//*[@class="extra"]/i[@class="ps-3"]/text()').first;
|
||||
final time =
|
||||
MBridge.xpath(element, '//*[@class="extra"]/i[@class="ps-3"]/text()')
|
||||
.first;
|
||||
times.add(time);
|
||||
chapsUrls.add(url);
|
||||
scanlators.add(group);
|
||||
@@ -83,26 +107,35 @@ getMangaDetail(MManga manga) async {
|
||||
manga.urls = chapsUrls;
|
||||
manga.names = chapsNames;
|
||||
manga.chaptersScanlators = scanlators;
|
||||
manga.chaptersDateUploads = MBridge.listParseDateTime(times, "MMM dd,yyyy", "en");
|
||||
manga.chaptersDateUploads =
|
||||
MBridge.listParseDateTime(times, "MMM dd,yyyy", "en");
|
||||
|
||||
return manga;
|
||||
}
|
||||
|
||||
getChapterPages(MManga manga) async {
|
||||
final datas = {"url": "${manga.baseUrl}${manga.link}", "sourceId": manga.sourceId};
|
||||
final res = await MBridge.http('GET', json.encode(datas));
|
||||
if (res.isEmpty) {
|
||||
return [];
|
||||
final datas = {
|
||||
"url": "${manga.baseUrl}${manga.link}",
|
||||
"sourceId": manga.sourceId
|
||||
};
|
||||
final response = await MBridge.http('GET', json.encode(datas));
|
||||
if (response.hasError) {
|
||||
return response;
|
||||
}
|
||||
String res = response.body;
|
||||
final script = MBridge.xpath(res,
|
||||
'//script[contains(text(), "imgHttpLis") and contains(text(), "batoWord") and contains(text(), "batoPass")]/text()')
|
||||
.first;
|
||||
final imgHttpLisString = MBridge.substringBefore(MBridge.substringAfterLast(script, 'const imgHttpLis ='), ';');
|
||||
final imgHttpLisString = MBridge.substringBefore(
|
||||
MBridge.substringAfterLast(script, 'const imgHttpLis ='), ';');
|
||||
var imgHttpLis = json.decode(imgHttpLisString);
|
||||
final batoWord = MBridge.substringBefore(MBridge.substringAfterLast(script, 'const batoWord ='), ';');
|
||||
final batoPass = MBridge.substringBefore(MBridge.substringAfterLast(script, 'const batoPass ='), ';');
|
||||
final batoWord = MBridge.substringBefore(
|
||||
MBridge.substringAfterLast(script, 'const batoWord ='), ';');
|
||||
final batoPass = MBridge.substringBefore(
|
||||
MBridge.substringAfterLast(script, 'const batoPass ='), ';');
|
||||
final evaluatedPass = MBridge.deobfuscateJsPassword(batoPass);
|
||||
final imgAccListString = MBridge.decryptAESCryptoJS(batoWord.replaceAll('"', ""), evaluatedPass);
|
||||
final imgAccListString =
|
||||
MBridge.decryptAESCryptoJS(batoWord.replaceAll('"', ""), evaluatedPass);
|
||||
var imgAccList = json.decode(imgAccListString);
|
||||
List<String> pagesUrl = [];
|
||||
for (int i = 0; i < imgHttpLis.length; i++) {
|
||||
@@ -115,12 +148,14 @@ getChapterPages(MManga manga) async {
|
||||
}
|
||||
|
||||
MManga mangaElementM(String res, MManga manga) async {
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
}
|
||||
final lang = manga.lang.replaceAll("-", "_");
|
||||
var resB =
|
||||
MBridge.querySelectorAll(res, selector: "div#series-list div.col", typeElement: 2, attributes: "", typeRegExp: 0);
|
||||
|
||||
var resB = MBridge.querySelectorAll(res,
|
||||
selector: "div#series-list div.col",
|
||||
typeElement: 2,
|
||||
attributes: "",
|
||||
typeRegExp: 0);
|
||||
|
||||
List<String> images = [];
|
||||
List<String> urls = [];
|
||||
List<String> names = [];
|
||||
@@ -129,30 +164,36 @@ MManga mangaElementM(String res, MManga manga) async {
|
||||
if (manga.lang == "all" ||
|
||||
manga.lang == "en" && element.contains('no-flag') ||
|
||||
element.contains('data-lang="$lang"')) {
|
||||
final item =
|
||||
MBridge.querySelectorAll(element, selector: "a.item-cover", typeElement: 2, attributes: "", typeRegExp: 0)
|
||||
.first;
|
||||
final img =
|
||||
MBridge.querySelectorAll(item, selector: "img", typeElement: 3, attributes: "src", typeRegExp: 0).first;
|
||||
final url =
|
||||
MBridge.querySelectorAll(item, selector: "a", typeElement: 3, attributes: "href", typeRegExp: 0).first;
|
||||
final item = MBridge.querySelectorAll(element,
|
||||
selector: "a.item-cover",
|
||||
typeElement: 2,
|
||||
attributes: "",
|
||||
typeRegExp: 0)
|
||||
.first;
|
||||
final img = MBridge.querySelectorAll(item,
|
||||
selector: "img", typeElement: 3, attributes: "src", typeRegExp: 0)
|
||||
.first;
|
||||
final url = MBridge.querySelectorAll(item,
|
||||
selector: "a", typeElement: 3, attributes: "href", typeRegExp: 0)
|
||||
.first;
|
||||
images.add(img);
|
||||
urls.add(url);
|
||||
final title =
|
||||
MBridge.querySelectorAll(element, selector: "a.item-title", typeElement: 0, attributes: "", typeRegExp: 0)
|
||||
.first;
|
||||
final title = MBridge.querySelectorAll(element,
|
||||
selector: "a.item-title",
|
||||
typeElement: 0,
|
||||
attributes: "",
|
||||
typeRegExp: 0)
|
||||
.first;
|
||||
names.add(title);
|
||||
}
|
||||
}
|
||||
manga.urls = urls;
|
||||
manga.names = names;
|
||||
manga.images = images;
|
||||
final nextPage = MBridge.xpath(res, '//li[@class="page-item disabled"]/a/span[contains(text(),"»")]/text()').first;
|
||||
if (nextPage.isEmpty) {
|
||||
manga.hasNextPage = true;
|
||||
} else {
|
||||
manga.hasNextPage = false;
|
||||
}
|
||||
final nextPage = MBridge.xpath(res,
|
||||
'//li[@class="page-item disabled"]/a/span[contains(text(),"»")]/text()');
|
||||
manga.hasNextPage = true;
|
||||
|
||||
return manga;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user