mirror of
https://github.com/kodjodevf/mangayomi-extensions.git
synced 2026-02-15 03:10:59 +00:00
code refactor
This commit is contained in:
@@ -1,203 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'package:bridge_lib/bridge_lib.dart';
|
||||
|
||||
searchManga(MangaModel manga) async {
|
||||
final headers = getHeader(manga.baseUrl);
|
||||
final url = "${manga.apiUrl}/series/search";
|
||||
final body = {"term": manga.query};
|
||||
final data = {"url": url, "headers": headers, "body": body};
|
||||
final res = await MBridge.http(json.encode(data), 1);
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
}
|
||||
List<String> jsonList = [];
|
||||
List<String> names = [];
|
||||
List<String> urls = [];
|
||||
List<String> images = [];
|
||||
if (res.startsWith("{")) {
|
||||
jsonList = MBridge.jsonPathToList(res, r'$.data[*]', 0);
|
||||
} else {
|
||||
jsonList = MBridge.jsonDecodeToList(res,0);
|
||||
}
|
||||
for (var a in jsonList) {
|
||||
final thumbnail = MBridge.getMapValue(a, "thumbnail", 0);
|
||||
if (thumbnail.startsWith("https://")) {
|
||||
images.add(thumbnail);
|
||||
} else {
|
||||
images.add("${manga.apiUrl}/cover/$thumbnail");
|
||||
}
|
||||
names.add(MBridge.getMapValue(a, "title", 0));
|
||||
final seriesSlug = MBridge.regExp(
|
||||
MBridge.getMapValue(a, "series_slug", 0), "-\\d+", "", 0, 0);
|
||||
urls.add("/series/$seriesSlug");
|
||||
}
|
||||
manga.urls = urls;
|
||||
manga.images = images;
|
||||
manga.names = names;
|
||||
return manga;
|
||||
}
|
||||
|
||||
getPopularManga(MangaModel manga) async {
|
||||
final headers = getHeader(manga.baseUrl);
|
||||
final url = "${manga.apiUrl}/series/querysearch";
|
||||
final body = {
|
||||
"page": manga.page,
|
||||
"order": "desc",
|
||||
"order_by": "total_views",
|
||||
"series_status": "Ongoing",
|
||||
"series_type": "Comic"
|
||||
};
|
||||
final data = {
|
||||
"url": url,
|
||||
"headers": headers,
|
||||
"sourceId": manga.sourceId,
|
||||
"body": body
|
||||
};
|
||||
final res = await MBridge.http(json.encode(data), 1);
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
}
|
||||
List<String> jsonList = [];
|
||||
List<String> names = [];
|
||||
List<String> urls = [];
|
||||
List<String> images = [];
|
||||
if (res.startsWith("{")) {
|
||||
jsonList = MBridge.jsonPathToList(res, r'$.data[*]', 0);
|
||||
} else {
|
||||
jsonList = MBridge.jsonDecodeToList(res,0);
|
||||
}
|
||||
for (var a in jsonList) {
|
||||
final thumbnail = MBridge.getMapValue(a, "thumbnail", 0);
|
||||
if (thumbnail.startsWith("https://")) {
|
||||
images.add(thumbnail);
|
||||
} else {
|
||||
images.add("${manga.apiUrl}/cover/$thumbnail");
|
||||
}
|
||||
names.add(MBridge.getMapValue(a, "title", 0));
|
||||
final seriesSlug = MBridge.regExp(
|
||||
MBridge.getMapValue(a, "series_slug", 0), "-\\d+", "", 0, 0);
|
||||
urls.add("/series/$seriesSlug");
|
||||
}
|
||||
manga.urls = urls;
|
||||
manga.images = images;
|
||||
manga.names = names;
|
||||
return manga;
|
||||
}
|
||||
|
||||
getLatestUpdatesManga(MangaModel manga) async {
|
||||
final headers = getHeader(manga.baseUrl);
|
||||
final url = "${manga.apiUrl}/series/querysearch";
|
||||
final body = {
|
||||
"page": manga.page,
|
||||
"order": "desc",
|
||||
"order_by": "latest",
|
||||
"series_status": "Ongoing",
|
||||
"series_type": "Comic"
|
||||
};
|
||||
final data = {
|
||||
"url": url,
|
||||
"headers": headers,
|
||||
"sourceId": manga.sourceId,
|
||||
"body": body
|
||||
};
|
||||
final res = await MBridge.http(json.encode(data), 1);
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
}
|
||||
List<String> jsonList = [];
|
||||
List<String> names = [];
|
||||
List<String> urls = [];
|
||||
List<String> images = [];
|
||||
if (res.startsWith("{")) {
|
||||
jsonList = MBridge.jsonPathToList(res, r'$.data[*]', 0);
|
||||
} else {
|
||||
jsonList = MBridge.jsonDecodeToList(res,0);
|
||||
}
|
||||
for (var a in jsonList) {
|
||||
final thumbnail = MBridge.getMapValue(a, "thumbnail", 0);
|
||||
if (thumbnail.startsWith("https://")) {
|
||||
images.add(thumbnail);
|
||||
} else {
|
||||
images.add("${manga.apiUrl}/cover/$thumbnail");
|
||||
}
|
||||
names.add(MBridge.getMapValue(a, "title", 0));
|
||||
final seriesSlug = MBridge.regExp(
|
||||
MBridge.getMapValue(a, "series_slug", 0), "-\\d+", "", 0, 0);
|
||||
urls.add("/series/$seriesSlug");
|
||||
}
|
||||
manga.urls = urls;
|
||||
manga.images = images;
|
||||
manga.names = names;
|
||||
return manga;
|
||||
}
|
||||
|
||||
getMangaDetail(MangaModel manga) async {
|
||||
String currentSlug = MBridge.listParse(manga.link.split('/'), 2)[0];
|
||||
|
||||
final headers = getHeader(manga.baseUrl);
|
||||
final url = "${manga.apiUrl}/series/$currentSlug";
|
||||
final data = {"url": url, "headers": headers};
|
||||
final res = await MBridge.http(json.encode(data), 0);
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
}
|
||||
manga.author = MBridge.getMapValue(res, "author", 0);
|
||||
|
||||
manga.description = MBridge.getMapValue(res, "description", 0);
|
||||
manga.genre =
|
||||
MBridge.jsonPathToString(res, r"$.tags[*].name", "._").split("._");
|
||||
|
||||
final chapters = MBridge.jsonPathToList(res, r"$.chapters[*]", 0);
|
||||
List<String> chapterTitles = [];
|
||||
List<String> chapterUrls = [];
|
||||
List<String> chapterDates = [];
|
||||
for (var chapter in chapters) {
|
||||
final chapterName = MBridge.getMapValue(chapter, "chapter_name", 0);
|
||||
final chapterSlug = MBridge.getMapValue(chapter, "chapter_slug", 0);
|
||||
final chapterId = MBridge.getMapValue(chapter, "id", 0);
|
||||
final createdAt = MBridge.getMapValue(chapter, "created_at", 0);
|
||||
chapterUrls.add("/series/$currentSlug/$chapterSlug#$chapterId");
|
||||
chapterTitles.add(chapterName);
|
||||
chapterDates.add(createdAt);
|
||||
}
|
||||
manga.urls = MBridge.listParse(chapterUrls,5);
|
||||
manga.names = MBridge.listParse(chapterTitles,5);
|
||||
manga.chaptersDateUploads = MBridge.listParse(
|
||||
MBridge.listParseDateTime(
|
||||
chapterDates, manga.dateFormat, manga.dateFormatLocale),
|
||||
5);
|
||||
return manga;
|
||||
}
|
||||
|
||||
getChapterUrl(MangaModel manga) async {
|
||||
String chapterId = MBridge.listParse(manga.link.split('#'), 2)[0];
|
||||
|
||||
final headers = getHeader(manga.baseUrl);
|
||||
final url = "${manga.apiUrl}/series/chapter/$chapterId";
|
||||
final data = {"url": url, "headers": headers};
|
||||
final res = await MBridge.http(json.encode(data), 0);
|
||||
if (res.isEmpty) {
|
||||
return [];
|
||||
}
|
||||
final pages = MBridge.jsonPathToList(res, r"$.content.images[*]", 0);
|
||||
List<String> pageUrls = [];
|
||||
for (var u in pages) {
|
||||
final url = u.replaceAll('"', "");
|
||||
if (url.startsWith("http")) {
|
||||
pageUrls.add(url);
|
||||
} else {
|
||||
pageUrls.add("${manga.apiUrl}/$url");
|
||||
}
|
||||
}
|
||||
return pageUrls;
|
||||
}
|
||||
|
||||
Map<String, String> getHeader(String url) {
|
||||
final headers = {
|
||||
'Origin': url,
|
||||
'Referer': '$url/',
|
||||
'Accept': 'application/json, text/plain, */*',
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
return headers;
|
||||
}
|
||||
276
manga/multisrc/heancms/heancms-v0.0.2.dart
Normal file
276
manga/multisrc/heancms/heancms-v0.0.2.dart
Normal file
@@ -0,0 +1,276 @@
|
||||
import 'dart:convert';
|
||||
import 'package:bridge_lib/bridge_lib.dart';
|
||||
|
||||
searchManga(MangaModel manga) async {
|
||||
final headers = getHeader(manga.baseUrl);
|
||||
|
||||
String res = "".toString();
|
||||
if (!useNewQueryEndpoint(manga.source)) {
|
||||
final url = "${manga.apiUrl}/series/search";
|
||||
final body = {"term": manga.query};
|
||||
final data = {"url": url, "headers": headers, "body": body};
|
||||
res = await MBridge.http('POST', json.encode(data));
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
}
|
||||
} else {
|
||||
final newEndpointUrl = "${manga.apiUrl}/query";
|
||||
final newEndpointBody = {
|
||||
"query_string": manga.query,
|
||||
"series_status": "All",
|
||||
"page": manga.page,
|
||||
"order": "desc",
|
||||
"order_by": "total_views",
|
||||
"perPage": "12",
|
||||
"tags_ids": "[]",
|
||||
"series_type": "Comic"
|
||||
};
|
||||
final newEndpointData = {
|
||||
"url": newEndpointUrl,
|
||||
"headers": headers,
|
||||
"newEndpointBody": newEndpointBody
|
||||
};
|
||||
res = await MBridge.http('GET', json.encode(newEndpointData));
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
}
|
||||
}
|
||||
|
||||
return mangaModelRes(res, manga);
|
||||
}
|
||||
|
||||
getPopularManga(MangaModel manga) async {
|
||||
final headers = getHeader(manga.baseUrl);
|
||||
String res = "".toString();
|
||||
if (!useNewQueryEndpoint(manga.source)) {
|
||||
final url = "${manga.apiUrl}/series/querysearch";
|
||||
print(url);
|
||||
|
||||
final body = {
|
||||
"page": manga.page,
|
||||
"order": "desc",
|
||||
"order_by": "total_views",
|
||||
"series_status": "Ongoing",
|
||||
"series_type": "Comic"
|
||||
};
|
||||
final data = {
|
||||
"url": url,
|
||||
"headers": headers,
|
||||
"sourceId": manga.sourceId,
|
||||
"body": body
|
||||
};
|
||||
res = await MBridge.http('POST', json.encode(data));
|
||||
} else {
|
||||
final newEndpointUrl = "${manga.apiUrl}/query";
|
||||
final newEndpointBody = {
|
||||
"query_string": "",
|
||||
"series_status": "All",
|
||||
"page": manga.page,
|
||||
"order": "desc",
|
||||
"order_by": "total_views",
|
||||
"perPage": "12",
|
||||
"tags_ids": "[]",
|
||||
"series_type": "Comic"
|
||||
};
|
||||
final newEndpointData = {
|
||||
"url": newEndpointUrl,
|
||||
"headers": headers,
|
||||
"sourceId": manga.sourceId,
|
||||
"body": newEndpointBody
|
||||
};
|
||||
print("sssssssssssssssssssss");
|
||||
res = await MBridge.http('GET', json.encode(newEndpointData));
|
||||
print(res);
|
||||
}
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
}
|
||||
return mangaModelRes(res, manga);
|
||||
}
|
||||
|
||||
getLatestUpdatesManga(MangaModel manga) async {
|
||||
final headers = getHeader(manga.baseUrl);
|
||||
String res = "".toString();
|
||||
if (!useNewQueryEndpoint(manga.source)) {
|
||||
final url = "${manga.apiUrl}/series/querysearch";
|
||||
final body = {
|
||||
"page": manga.page,
|
||||
"order": "desc",
|
||||
"order_by": "latest",
|
||||
"series_status": "Ongoing",
|
||||
"series_type": "Comic"
|
||||
};
|
||||
final data = {
|
||||
"url": url,
|
||||
"headers": headers,
|
||||
"sourceId": manga.sourceId,
|
||||
"body": body
|
||||
};
|
||||
res = await MBridge.http('POST', json.encode(data));
|
||||
} else {
|
||||
final newEndpointUrl = "${manga.apiUrl}/query";
|
||||
final newEndpointBody = {
|
||||
"query_string": "",
|
||||
"series_status": "All",
|
||||
"page": manga.page,
|
||||
"order": "desc",
|
||||
"order_by": "latest",
|
||||
"perPage": "12",
|
||||
"tags_ids": "[]",
|
||||
"series_type": "Comic"
|
||||
};
|
||||
final newEndpointData = {
|
||||
"url": newEndpointUrl,
|
||||
"headers": headers,
|
||||
"sourceId": manga.sourceId,
|
||||
"body": newEndpointBody
|
||||
};
|
||||
res = await MBridge.http('GET', json.encode(newEndpointData));
|
||||
print(res);
|
||||
}
|
||||
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
}
|
||||
return mangaModelRes(res, manga);
|
||||
}
|
||||
|
||||
getMangaDetail(MangaModel manga) async {
|
||||
String currentSlug = manga.link.split('/').last;
|
||||
|
||||
final headers = getHeader(manga.baseUrl);
|
||||
final url = "${manga.apiUrl}/series/$currentSlug";
|
||||
final data = {"url": url, "headers": headers};
|
||||
final res = await MBridge.http('GET', json.encode(data));
|
||||
if (res.isEmpty) {
|
||||
return manga;
|
||||
}
|
||||
manga.author = MBridge.getMapValue(res, "author");
|
||||
|
||||
manga.description = MBridge.getMapValue(res, "description");
|
||||
manga.genre =
|
||||
MBridge.jsonPathToString(res, r"$.tags[*].name", "._").split("._");
|
||||
|
||||
var chapters = [];
|
||||
if (!useNewQueryEndpoint(manga.source)) {
|
||||
chapters = json.decode(res)["chapters"];
|
||||
} else {
|
||||
final seasons = json.decode(res)["seasons"].first;
|
||||
chapters = seasons["chapters"];
|
||||
}
|
||||
List<String> chapterTitles = [];
|
||||
List<String> chapterUrls = [];
|
||||
List<String> chapterDates = [];
|
||||
for (var chapter in chapters) {
|
||||
final chapterName = chapter["chapter_name"];
|
||||
final chapterSlug = chapter["chapter_slug"];
|
||||
final chapterId = chapter["id"];
|
||||
final createdAt = chapter["created_at"];
|
||||
chapterUrls.add("/series/$currentSlug/$chapterSlug#$chapterId");
|
||||
chapterTitles.add(chapterName);
|
||||
chapterDates.add(createdAt);
|
||||
}
|
||||
if (!useNewQueryEndpoint(manga.source)) {
|
||||
manga.urls = chapterUrls.reversed.toList();
|
||||
manga.names = chapterTitles.reversed.toList();
|
||||
manga.chaptersDateUploads = MBridge.listParseDateTime(
|
||||
chapterDates, manga.dateFormat, manga.dateFormatLocale)
|
||||
.reversed
|
||||
.toList();
|
||||
} else {
|
||||
manga.urls = chapterUrls;
|
||||
manga.names = chapterTitles;
|
||||
manga.chaptersDateUploads = MBridge.listParseDateTime(
|
||||
chapterDates, manga.dateFormat, manga.dateFormatLocale);
|
||||
}
|
||||
return manga;
|
||||
}
|
||||
|
||||
getChapterUrl(MangaModel manga) async {
|
||||
String res = "".toString();
|
||||
final headers = getHeader(manga.baseUrl);
|
||||
if (!useslugStrategy(manga.source)) {
|
||||
String chapterId = MBridge.substringAfter(manga.link, '#');
|
||||
|
||||
final url = "${manga.apiUrl}/series/chapter/$chapterId";
|
||||
final data = {"url": url, "headers": headers};
|
||||
res = await MBridge.http('GET', json.encode(data));
|
||||
} else {
|
||||
final url = "${manga.baseUrl}${manga.link}";
|
||||
final data = {"url": url, "headers": headers};
|
||||
res = await MBridge.http('GET', json.encode(data));
|
||||
List<String> pageUrls = [];
|
||||
var imagesRes = MBridge.querySelectorAll(res,
|
||||
selector: "div.min-h-screen > div.container > p.items-center",
|
||||
typeElement: 1,
|
||||
attributes: "",
|
||||
typeRegExp: 0);
|
||||
pageUrls = MBridge.xpath(imagesRes.first, '//img/@src');
|
||||
|
||||
pageUrls.addAll(MBridge.xpath(imagesRes.first, '//img/@data-src'));
|
||||
|
||||
return pageUrls.where((e) => e.isNotEmpty).toList();
|
||||
}
|
||||
|
||||
if (res.isEmpty) {
|
||||
return [];
|
||||
}
|
||||
final pages = MBridge.jsonPathToList(res, r"$.content.images[*]", 0);
|
||||
List<String> pageUrls = [];
|
||||
for (var u in pages) {
|
||||
final url = u.replaceAll('"', "");
|
||||
if (url.startsWith("http")) {
|
||||
pageUrls.add(url);
|
||||
} else {
|
||||
pageUrls.add("${manga.apiUrl}/$url");
|
||||
}
|
||||
}
|
||||
return pageUrls;
|
||||
}
|
||||
|
||||
Map<String, String> getHeader(String url) {
|
||||
final headers = {
|
||||
'Origin': url,
|
||||
'Referer': '$url/',
|
||||
'Accept': 'application/json, text/plain, */*',
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
return headers;
|
||||
}
|
||||
|
||||
bool useNewQueryEndpoint(String sourceName) {
|
||||
List<String> sources = ["YugenMangas", "Perf Scan", "Reaper Scans"];
|
||||
return sources.contains(sourceName);
|
||||
}
|
||||
|
||||
bool useslugStrategy(String sourceName) {
|
||||
List<String> sources = ["YugenMangas", "Reaper Scans"];
|
||||
return sources.contains(sourceName);
|
||||
}
|
||||
|
||||
MangaModel mangaModelRes(String res, MangaModel manga) {
|
||||
var jsonList = [];
|
||||
List<String> names = [];
|
||||
List<String> urls = [];
|
||||
List<String> images = [];
|
||||
if (res.startsWith("{")) {
|
||||
jsonList = json.decode(res)["data"];
|
||||
} else {
|
||||
jsonList = json.decode(res);
|
||||
}
|
||||
for (var a in jsonList) {
|
||||
String thumbnail = a["thumbnail"];
|
||||
if (thumbnail.startsWith("https://")) {
|
||||
images.add(thumbnail);
|
||||
} else {
|
||||
images.add("${manga.apiUrl}/cover/$thumbnail");
|
||||
}
|
||||
names.add(a["title"]);
|
||||
final seriesSlug = MBridge.regExp(a["series_slug"], "-\\d+", "", 0, 0);
|
||||
urls.add("/series/$seriesSlug");
|
||||
}
|
||||
manga.urls = urls;
|
||||
manga.images = images;
|
||||
manga.names = names;
|
||||
return manga;
|
||||
}
|
||||
@@ -10,8 +10,8 @@ List<Source> get heanCmsSourcesList => _heanCmsSourcesList;
|
||||
List<Source> _heanCmsSourcesList = [
|
||||
Source(
|
||||
name: "YugenMangas",
|
||||
baseUrl: "https://yugenmangas.net",
|
||||
apiUrl: "https://api.yugenmangas.net",
|
||||
baseUrl: "https://yugenmangas.lat",
|
||||
apiUrl: "https://api.yugenmangas.lat",
|
||||
lang: "es",
|
||||
typeSource: "heancms",
|
||||
isNsfw: true,
|
||||
@@ -32,4 +32,40 @@ List<Source> _heanCmsSourcesList = [
|
||||
version: heancmsVersion,
|
||||
dateFormat: defaultDateFormat,
|
||||
dateFormatLocale: defaultDateFormatLocale),
|
||||
Source(
|
||||
name: "Reaper Scans",
|
||||
baseUrl: "https://reaperscans.net",
|
||||
apiUrl: "https://api.reaperscans.net",
|
||||
lang: "pt-BR",
|
||||
typeSource: "heancms",
|
||||
isNsfw: true,
|
||||
iconUrl: getIconUrl("reaperscans", "pt-BR"),
|
||||
sourceCodeUrl: heancmsSourceCodeUrl,
|
||||
version: heancmsVersion,
|
||||
dateFormat: defaultDateFormat,
|
||||
dateFormatLocale: defaultDateFormatLocale),
|
||||
Source(
|
||||
name: "Perf Scan",
|
||||
baseUrl: "https://perf-scan.fr",
|
||||
apiUrl: "https://api.perf-scan.fr",
|
||||
lang: "fr",
|
||||
typeSource: "heancms",
|
||||
isNsfw: true,
|
||||
iconUrl: getIconUrl("perfscan", "fr"),
|
||||
sourceCodeUrl: heancmsSourceCodeUrl,
|
||||
version: heancmsVersion,
|
||||
dateFormat: defaultDateFormat,
|
||||
dateFormatLocale: defaultDateFormatLocale),
|
||||
Source(
|
||||
name: "Glorious Scan",
|
||||
baseUrl: "https://gloriousscan.com",
|
||||
apiUrl: "https://api.gloriousscan.com",
|
||||
lang: "pt-BR",
|
||||
typeSource: "heancms",
|
||||
isNsfw: true,
|
||||
iconUrl: getIconUrl("gloriousscan", "pt-BR"),
|
||||
sourceCodeUrl: heancmsSourceCodeUrl,
|
||||
version: heancmsVersion,
|
||||
dateFormat: defaultDateFormat,
|
||||
dateFormatLocale: defaultDateFormatLocale),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user