code refactor

This commit is contained in:
kodjomoustapha
2023-10-08 15:58:46 +01:00
parent 9791b04b67
commit 12f07a4291
29 changed files with 2191 additions and 2430 deletions

View File

@@ -3,28 +3,24 @@ import 'package:bridge_lib/bridge_lib.dart';
getPopularManga(MangaModel manga) async {
final url = "${manga.baseUrl}/manga/page/${manga.page}/?m_orderby=views";
final data = {"url": url, "headers": null, "sourceId": manga.sourceId};
final res = await MBridge.http(json.encode(data), 0);
final data = {"url": url, "sourceId": manga.sourceId};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return manga;
}
manga.urls = MBridge.xpath(res, '//*[@class^="post-title"]/h3/a/@href', '-.')
.split("-.");
String images =
MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@data-src', '-.');
manga.urls = MBridge.xpath(res, '//*[@class^="post-title"]/h3/a/@href');
var images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@data-src');
if (images.isEmpty) {
images =
MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@data-lazy-src', '-.');
images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@data-lazy-src');
if (images.isEmpty) {
images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@srcset', '-.');
images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@srcset');
if (images.isEmpty) {
images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@src', '-.');
images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@src');
}
}
}
manga.images = images.split("-.");
manga.names =
MBridge.xpath(res, '//*[@id^="manga-item"]/a/@title', '-.').split("-.");
manga.images = images;
manga.names = MBridge.xpath(res, '//*[@id^="manga-item"]/a/@title');
return manga;
}
@@ -75,36 +71,50 @@ getMangaDetail(MangaModel manga) async {
}
];
final datas = {
"url": manga.link,
"headers": null,
"sourceId": manga.sourceId
};
final res = await MBridge.http(json.encode(datas), 0);
final datas = {"url": manga.link, "sourceId": manga.sourceId};
final res = await MBridge.http('GET', json.encode(datas));
if (res.isEmpty) {
return manga;
}
manga.author =
MBridge.querySelectorAll(res, "div.author-content > a", 0, "", 0, 0, "");
manga.description = MBridge.querySelectorAll(
res,
"div.description-summary div.summary__content, div.summary_content div.post-content_item > h5 + div, div.summary_content div.manga-excerpt, div.sinopsis div.contenedor, .description-summary > p",
0,
"",
0,
0,
"");
manga.imageUrl =
MBridge.querySelectorAll(res, "div.summary_image img", 2, "", 2, 1, "");
final mangaId = MBridge.querySelectorAll(
res, "div[id^=manga-chapters-holder]", 3, "data-id", 0, 1, "");
manga.author = MBridge.querySelectorAll(res,
selector: "div.author-content > a",
typeElement: 0,
attributes: "",
typeRegExp: 0)
.first;
manga.description = MBridge.querySelectorAll(res,
selector:
"div.description-summary div.summary__content, div.summary_content div.post-content_item > h5 + div, div.summary_content div.manga-excerpt, div.sinopsis div.contenedor, .description-summary > p",
typeElement: 0,
attributes: "",
typeRegExp: 0)
.first;
manga.imageUrl = MBridge.querySelectorAll(res,
selector: "div.summary_image img",
typeElement: 2,
attributes: "",
typeRegExp: 2)
.first;
final mangaId = MBridge.querySelectorAll(res,
selector: "div[id^=manga-chapters-holder]",
typeElement: 3,
attributes: "data-id",
typeRegExp: 0)
.first;
manga.status = MBridge.parseStatus(
MBridge.querySelectorAll(res, "div.summary-content", 0, "", 0, 2, ""),
MBridge.querySelectorAll(res,
selector: "div.summary-content",
typeElement: 0,
attributes: "",
typeRegExp: 0)
.last,
statusList);
manga.genre =
MBridge.querySelectorAll(res, "div.genres-content a", 0, "", 0, 0, "-.")
.split("-.");
manga.genre = MBridge.querySelectorAll(res,
selector: "div.genres-content a",
typeElement: 0,
attributes: "",
typeRegExp: 0);
final baseUrl = "${manga.baseUrl}/";
final headers = {
@@ -116,7 +126,7 @@ getMangaDetail(MangaModel manga) async {
"${baseUrl}wp-admin/admin-ajax.php?action=manga_get_chapters&manga=$mangaId";
final datasP = {"url": url, "headers": headers, "sourceId": manga.sourceId};
String resP = await MBridge.http(json.encode(datasP), 1);
String resP = await MBridge.http('POST', json.encode(datasP));
if (resP == "400") {
final urlP = "${manga.link}ajax/chapters";
final datasP = {
@@ -124,32 +134,24 @@ getMangaDetail(MangaModel manga) async {
"headers": headers,
"sourceId": manga.sourceId
};
resP = await MBridge.http(json.encode(datasP), 1);
resP = await MBridge.http('POST', json.encode(datasP));
}
manga.urls = MBridge.xpath(resP, "//li/a/@href", '-.').split("-.");
List<dynamic> chaptersNames =
MBridge.xpath(resP, "//li/a/text()", '-.').split("-.");
manga.urls = MBridge.xpath(resP, "//li/a/@href");
var chaptersNames = MBridge.xpath(resP, "//li/a/text()");
List<dynamic> dateF =
MBridge.xpath(resP, "//li/span/i/text()", '-.').split("-.");
var dateF = MBridge.xpath(resP, "//li/span/i/text()");
if (MBridge.xpath(resP, "//li/a/text()", "").isEmpty) {
final resWebview = await MBridge.getHtmlViaWebview(manga.link,
"//*[@id='manga-chapters-holder']/div[2]/div/ul/li/a/@href");
manga.urls = MBridge.xpath(resWebview,
"//*[@id='manga-chapters-holder']/div[2]/div/ul/li/a/@href", '-.')
.split("-.");
"//*[@id='manga-chapters-holder']/div[2]/div/ul/li/a/@href");
chaptersNames = MBridge.xpath(resWebview,
"//*[@id='manga-chapters-holder']/div[2]/div/ul/li/a/text()", '-.')
.split("-.");
dateF = MBridge.xpath(
resWebview,
"//*[@id='manga-chapters-holder']/div[2]/div/ul/li/span/i/text()",
'-.')
.split("-.");
"//*[@id='manga-chapters-holder']/div[2]/div/ul/li/a/text()");
dateF = MBridge.xpath(resWebview,
"//*[@id='manga-chapters-holder']/div[2]/div/ul/li/span/i/text()");
}
manga.names = chaptersNames;
List<String> chapterDate = [];
if (dateF.length == chaptersNames.length) {
manga.chaptersDateUploads = MBridge.listParseDateTime(
dateF, manga.dateFormat, manga.dateFormatLocale);
@@ -162,7 +164,7 @@ getMangaDetail(MangaModel manga) async {
final dateFF = MBridge.listParseDateTime(
dateF, manga.dateFormat, manga.dateFormatLocale);
List<String> chapterDate = MBridge.listParse(date.split('--..'), 0);
List<String> chapterDate = date.split('--..');
for (var date in dateFF) {
chapterDate.add(date);
@@ -173,42 +175,45 @@ getMangaDetail(MangaModel manga) async {
}
getChapterUrl(MangaModel manga) async {
final datas = {
"url": manga.link,
"headers": null,
"sourceId": manga.sourceId
};
final res = await MBridge.http(json.encode(datas), 0);
final datas = {"url": manga.link, "sourceId": manga.sourceId};
final res = await MBridge.http('GET', json.encode(datas));
if (res.isEmpty) {
return [];
}
final pagesSelectorRes = MBridge.querySelector(
res,
"div.page-break, li.blocks-gallery-item, .reading-content, .text-left img",
1,
"");
final imgs =
MBridge.querySelectorAll(pagesSelectorRes, "img", 2, "", 2, 0, '-.')
.split('-.');
List<dynamic> pageUrls = [];
final pagesSelectorRes = MBridge.querySelectorAll(res,
selector:
"div.page-break, li.blocks-gallery-item, .reading-content, .text-left img",
typeElement: 1,
attributes: "",
typeRegExp: 0)
.first;
final imgs = MBridge.querySelectorAll(pagesSelectorRes,
selector: "img", typeElement: 2, attributes: "", typeRegExp: 2);
var pageUrls = [];
if (imgs.length == 1) {
final pages = MBridge.querySelector(res, "#single-pager", 2, "");
final pages = MBridge.querySelectorAll(res,
selector: "#single-pager",
typeElement: 2,
attributes: "",
typeRegExp: 0)
.first;
final pagesNumber =
MBridge.querySelectorAll(pages, "option", 2, "", 0, 0, '-.')
.split('-.');
final pagesNumber = MBridge.querySelectorAll(pages,
selector: "option", typeElement: 2, attributes: "", typeRegExp: 0);
for (var i = 0; i < pagesNumber.length; i++) {
final val = i + 1;
if (i.toString().length == 1) {
pageUrls.add(
MBridge.querySelectorAll(pagesSelectorRes, "img", 2, "", 2, 0, "")
.replaceAll("01", '0$val'));
pageUrls.add(MBridge.querySelectorAll(pagesSelectorRes,
selector: "img", typeElement: 2, attributes: "", typeRegExp: 2)
.first
.replaceAll("01", '0$val'));
} else {
pageUrls.add(
MBridge.querySelectorAll(pagesSelectorRes, "img", 2, "", 2, 0, "")
.replaceAll("01", val.toString()));
pageUrls.add(MBridge.querySelectorAll(pagesSelectorRes,
selector: "img", typeElement: 2, attributes: "", typeRegExp: 2)
.first
.replaceAll("01", val.toString()));
}
}
} else {
@@ -219,59 +224,53 @@ getChapterUrl(MangaModel manga) async {
getLatestUpdatesManga(MangaModel manga) async {
final url = "${manga.baseUrl}/manga/page/${manga.page}/?m_orderby=latest";
final datas = {"url": url, "headers": null, "sourceId": manga.sourceId};
final res = await MBridge.http(json.encode(datas), 0);
final datas = {"url": url, "sourceId": manga.sourceId};
final res = await MBridge.http('GET', json.encode(datas));
if (res.isEmpty) {
return manga;
}
manga.urls = MBridge.xpath(res, '//*[@class^="post-title"]/h3/a/@href', '-.')
.split("-.");
String images =
MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@data-src', '-.');
manga.urls = MBridge.xpath(res, '//*[@class^="post-title"]/h3/a/@href');
var images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@data-src');
if (images.isEmpty) {
images =
MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@data-lazy-src', '-.');
images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@data-lazy-src');
if (images.isEmpty) {
images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@srcset', '-.');
images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@srcset');
if (images.isEmpty) {
images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@src', '-.');
images = MBridge.xpath(res, '//*[@id^="manga-item"]/a/img/@src');
}
}
}
manga.images = images.split("-.");
manga.names =
MBridge.xpath(res, '//*[@id^="manga-item"]/a/@title', '-.').split("-.");
manga.images = images;
manga.names = MBridge.xpath(res, '//*[@id^="manga-item"]/a/@title');
return manga;
}
searchManga(MangaModel manga) async {
final urll = "${manga.baseUrl}/?s=${manga.query}&post_type=wp-manga";
final datas = {"url": urll, "headers": null, "sourceId": manga.sourceId};
final res = await MBridge.http(json.encode(datas), 0);
final datas = {"url": urll, "sourceId": manga.sourceId};
final res = await MBridge.http('GET', json.encode(datas));
if (res.isEmpty) {
return manga;
}
manga.urls =
MBridge.xpath(res, '//*[@class^="tab-thumb c-image-hover"]/a/@href', '-.')
.split("-.");
String images = MBridge.xpath(
res, '//*[@class^="tab-thumb c-image-hover"]/a/img/@data-src', '-.');
MBridge.xpath(res, '//*[@class^="tab-thumb c-image-hover"]/a/@href');
var images = MBridge.xpath(
res, '//*[@class^="tab-thumb c-image-hover"]/a/img/@data-src');
if (images.isEmpty) {
images = MBridge.xpath(res,
'//*[@class^="tab-thumb c-image-hover"]/a/img/@data-lazy-src', '-.');
images = MBridge.xpath(
res, '//*[@class^="tab-thumb c-image-hover"]/a/img/@data-lazy-src');
if (images.isEmpty) {
images = MBridge.xpath(
res, '//*[@class^="tab-thumb c-image-hover"]/a/img/@srcset', '-.');
res, '//*[@class^="tab-thumb c-image-hover"]/a/img/@srcset');
if (images.isEmpty) {
images = MBridge.xpath(
res, '//*[@class^="tab-thumb c-image-hover"]/a/img/@src', '-.');
res, '//*[@class^="tab-thumb c-image-hover"]/a/img/@src');
}
}
}
manga.images = images.split("-.");
manga.names = MBridge.xpath(
res, '//*[@class^="tab-thumb c-image-hover"]/a/@title', '-.')
.split("-.");
manga.images = images;
manga.names =
MBridge.xpath(res, '//*[@class^="tab-thumb c-image-hover"]/a/@title');
return manga;
}