Catch http error response

This commit is contained in:
kodjomoustapha
2023-10-25 19:02:57 +01:00
parent 6eac32b58c
commit c07bcd6032
16 changed files with 511 additions and 361 deletions

View File

@@ -3,10 +3,11 @@ import 'package:bridge_lib/bridge_lib.dart';
getPopularAnime(MManga anime) async {
final data = {"url": "https://www.okanime.xyz"};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls = MBridge.xpath(res,
'//div[@class="section" and contains(text(),"افضل انميات")]/div[@class="section-content"]/div/div/div[contains(@class,"anime-card")]/div[@class="anime-title")]/h4/a/@href');
@@ -24,10 +25,11 @@ getAnimeDetail(MManga anime) async {
{"يعرض الان": 0, "مكتمل": 1}
];
final data = {"url": anime.link};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
final status = MBridge.xpath(res,
'//*[@class="full-list-info" and contains(text(),"حالة الأنمي")]/small/a/text()');
@@ -56,10 +58,11 @@ getLatestUpdatesAnime(MManga anime) async {
final data = {
"url": "https://www.okanime.xyz/espisode-list?page=${anime.page}"
};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls = MBridge.xpath(res,
'//*[contains(@class,"anime-card")]/div[@class="anime-title")]/h4/a/@href');
@@ -84,10 +87,11 @@ searchAnime(MManga anime) async {
url += "&page=${anime.page}";
}
final data = {"url": url};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls = MBridge.xpath(res,
'//*[contains(@class,"anime-card")]/div[@class="anime-title")]/h4/a/@href');
@@ -108,11 +112,12 @@ searchAnime(MManga anime) async {
getVideoList(MManga anime) async {
final datas = {"url": anime.link};
final res = await MBridge.http('GET', json.encode(datas));
final response = await MBridge.http('GET', json.encode(datas));
if (res.isEmpty) {
return [];
if (response.hasError) {
return response;
}
String res = response.body;
final urls = MBridge.xpath(res, '//*[@id="streamlinks"]/a/@data-src');
final qualities = MBridge.xpath(res, '//*[@id="streamlinks"]/a/span/text()');

View File

@@ -4,15 +4,19 @@ import 'package:bridge_lib/bridge_lib.dart';
getPopularAnime(MManga anime) async {
final data = {"url": "${anime.baseUrl}/most-popular?page=${anime.page}"};
final res = await MBridge.http('GET', json.encode(data));
return animeElementM(res, anime);
if (res.hasError) {
return res;
}
return animeElementM(res.body, anime);
}
getLatestUpdatesAnime(MManga anime) async {
final data = {"url": "${anime.baseUrl}/top-airing?page=${anime.page}"};
final res = await MBridge.http('GET', json.encode(data));
return animeElementM(res, anime);
if (res.hasError) {
return res;
}
return animeElementM(res.body, anime);
}
getAnimeDetail(MManga anime) async {
@@ -24,11 +28,11 @@ getAnimeDetail(MManga anime) async {
];
final url = "${anime.baseUrl}${anime.link}";
final data = {"url": url, "headers": null};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
final status = MBridge.xpath(res,
'//*[@class="anisc-info"]/div[contains(text(),"Status:")]/span[2]/text()')
.first;
@@ -70,7 +74,7 @@ getAnimeDetail(MManga anime) async {
};
final resEp = await MBridge.http('GET', json.encode(dataEp));
final html = json.decode(resEp)["html"];
final html = json.decode(resEp.body)["html"];
final epUrls = MBridge.querySelectorAll(html,
selector: "a.ep-item", typeElement: 3, attributes: "href", typeRegExp: 0);
@@ -107,8 +111,10 @@ searchAnime(MManga anime) async {
"url": "${anime.baseUrl}/search?keyword=${anime.query}&page=${anime.page}"
};
final res = await MBridge.http('GET', json.encode(data));
return animeElementM(res, anime);
if (res.hasError) {
return res;
}
return animeElementM(res.body, anime);
}
getVideoList(MManga anime) async {
@@ -122,10 +128,10 @@ getVideoList(MManga anime) async {
final res = await MBridge.http('GET', json.encode(datas));
if (res.isEmpty) {
return [];
if (res.hasError) {
return res;
}
final html = json.decode(res)["html"];
final html = json.decode(res.body)["html"];
final names = MBridge.querySelectorAll(html,
selector: "div.server-item",
@@ -159,7 +165,7 @@ getVideoList(MManga anime) async {
final resE = await MBridge.http('GET', json.encode(datasE));
String url = MBridge.substringBefore(
MBridge.substringAfter(resE, "\"link\":\""), "\"");
MBridge.substringAfter(resE.body, "\"link\":\""), "\"");
print(url);
List<MVideo> a = [];
if (name.contains("Vidstreaming")) {

View File

@@ -3,10 +3,11 @@ import 'package:bridge_lib/bridge_lib.dart';
getPopularAnime(MManga anime) async {
final data = {"url": "${anime.baseUrl}/popular.html?page=${anime.page}"};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls = MBridge.xpath(res, '//*[@class="img"]/a/@href');
anime.names = MBridge.xpath(res, '//*[@class="img"]/a/@title');
anime.images = MBridge.xpath(res, '//*[@class="img"]/a/img/@src');
@@ -17,10 +18,11 @@ getLatestUpdatesAnime(MManga anime) async {
final url =
"https://ajax.gogo-load.com/ajax/page-recent-release-ongoing.html?page=${anime.page}&type=1";
final data = {"url": url};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls = MBridge.xpath(
res, '//*[@class="added_series_body popular"]/ul/li/a[1]/@href');
anime.names = MBridge.xpath(
@@ -46,10 +48,11 @@ getAnimeDetail(MManga anime) async {
];
final data = {"url": "${anime.baseUrl}${anime.link}"};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
final status = MBridge.xpath(
res, '//*[@class="anime_info_body_bg"]/p[@class="type"][5]/text()')
@@ -70,7 +73,11 @@ getAnimeDetail(MManga anime) async {
final urlEp =
"https://ajax.gogo-load.com/ajax/load-list-episode?ep_start=0&ep_end=4000&id=$id";
final dataEp = {"url": urlEp};
final resEp = await MBridge.http('GET', json.encode(dataEp));
final responseresEp = await MBridge.http('GET', json.encode(dataEp));
if (responseresEp.hasError) {
return response;
}
String resEp = responseresEp.body;
anime.urls = MBridge.xpath(resEp, '//*[@id="episode_related"]/li/a/@href');
final names = MBridge.xpath(
resEp, '//*[@id="episode_related"]/li/a/div[@class="name"]/text()');
@@ -88,11 +95,12 @@ getAnimeDetail(MManga anime) async {
getVideoList(MManga anime) async {
final datas = {"url": "${anime.baseUrl}${anime.link}"};
final res = await MBridge.http('GET', json.encode(datas));
final response = await MBridge.http('GET', json.encode(datas));
if (res.isEmpty) {
return [];
if (response.hasError) {
return response;
}
String res = response.body;
final serverUrls =
MBridge.xpath(res, '//*[@class="anime_muti_link"]/ul/li/a/@data-video');
@@ -128,10 +136,11 @@ searchAnime(MManga anime) async {
final url =
"${anime.baseUrl}/search.html?keyword=${anime.query}&page=${anime.page}";
final data = {"url": url};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls = MBridge.xpath(res, '//*[@class="img"]/a/@href');
anime.names = MBridge.xpath(res, '//*[@class="img"]/a/@title');
anime.images = MBridge.xpath(res, '//*[@class="img"]/a/img/@src');

View File

@@ -6,10 +6,11 @@ getPopularAnime(MManga anime) async {
"url":
"${anime.baseUrl}/api/DramaList/List?page=${anime.page}&type=0&sub=0&country=0&status=0&order=1&pageSize=40"
};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
final jsonRes = json.decode(res);
final datas = jsonRes["data"] as List;
anime.names = datas.map((e) => e["title"]).toList();
@@ -29,10 +30,11 @@ getLatestUpdatesAnime(MManga anime) async {
"url":
"${anime.baseUrl}/api/DramaList/List?page=${anime.page}&type=0&sub=0&country=0&status=0&order=12&pageSize=40"
};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
final jsonRes = json.decode(res);
final datas = jsonRes["data"] as List;
anime.names = datas.map((e) => e["title"]).toList();
@@ -57,10 +59,11 @@ getAnimeDetail(MManga anime) async {
];
final data = {"url": anime.link};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
final jsonRes = json.decode(res);
final status = jsonRes["status"] ?? "";
print(status);
@@ -99,17 +102,18 @@ getAnimeDetail(MManga anime) async {
getVideoList(MManga anime) async {
final datas = {"url": anime.link};
final res = await MBridge.http('GET', json.encode(datas));
final response = await MBridge.http('GET', json.encode(datas));
if (res.isEmpty) {
return [];
if (response.hasError) {
return response;
}
String res = response.body;
final id = MBridge.substringAfter(
MBridge.substringBefore(anime.link, ".png"), "Episode/");
final jsonRes = json.decode(res);
final subRes = await MBridge.http(
'GET', json.encode({"url": "${anime.baseUrl}/api/Sub/$id"}));
var jsonSubRes = json.decode(subRes);
var jsonSubRes = json.decode(subRes.body);
List<MTrack> subtitles = [];
@@ -143,10 +147,11 @@ searchAnime(MManga anime) async {
final data = {
"url": "${anime.baseUrl}/api/DramaList/Search?q=${anime.query}&type=0"
};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
var jsonRes = json.decode(res) as List;
anime.names = jsonRes.map((e) => e["title"]).toList();
anime.images = jsonRes.map((e) => e["thumbnail"] ?? "").toList();

View File

@@ -3,10 +3,11 @@ import 'package:bridge_lib/bridge_lib.dart';
getPopularAnime(MManga anime) async {
final data = {"url": "${anime.baseUrl}/"};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls = MBridge.xpath(res,
'//*[contains(@class,"swiper-slide item-qtip")]/div[@class="item"]/a/@href');
anime.names = MBridge.xpath(res,
@@ -19,10 +20,11 @@ getPopularAnime(MManga anime) async {
getLatestUpdatesAnime(MManga anime) async {
final data = {"url": "${anime.baseUrl}/"};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls = MBridge.xpath(res,
'//*[@class="block_area block_area_home"]/div[@class="tab-content"]/div[contains(@class,"block_area-content block_area-list")]/div[@class="film_list-wrap"]/div[@class="flw-item"]/div[@class="film-poster"]/a/@href');
@@ -38,10 +40,11 @@ searchAnime(MManga anime) async {
final url =
"${anime.baseUrl}/?story=${anime.query}&do=search&subaction=search";
final data = {"url": url};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls = MBridge.xpath(res, '//*[@class="film-poster"]/a/@href');
anime.names = MBridge.xpath(res, '//*[@class="film-poster"]/a/@title');
anime.images = MBridge.xpath(res, '//*[@class="film-poster"]/img/@data-src');
@@ -58,10 +61,11 @@ getAnimeDetail(MManga anime) async {
];
final url = anime.link;
final data = {"url": url};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.description =
MBridge.xpath(res, '//*[@class="film-description m-hide"]/text()').first;

View File

@@ -1,13 +1,13 @@
import 'dart:convert';
import 'package:bridge_lib/bridge_lib.dart';
Future<String> dataBase(int sourceId) async {
Future<MHttpResponse> dataBase(int sourceId) async {
final data = {
"url": "https://api.franime.fr/api/animes/",
"headers": {"Referer": "https://franime.fr/"}
};
final res = await MBridge.http('GET', json.encode(data));
return res;
return await MBridge.http('GET', json.encode(data));
}
getPopularAnime(MManga anime) async {
@@ -16,10 +16,10 @@ getPopularAnime(MManga anime) async {
"headers": {"Referer": "https://franime.fr/"}
};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
if (res.hasError) {
return res;
}
List<MManga> animeList = animeResList(res);
List<MManga> animeList = animeResList(res.body);
return animeList;
}
@@ -115,10 +115,10 @@ getAnimeDetail(MManga anime) async {
String stem =
MBridge.substringBefore(MBridge.substringAfterLast(anime.link, "/"), "?");
final res = await dataBase(anime.sourceId);
if (res.isEmpty) {
return anime;
if (res.hasError) {
return res;
}
final animeByTitleOJson = databaseAnimeByTitleO(res, stem);
final animeByTitleOJson = databaseAnimeByTitleO(res.body, stem);
if (animeByTitleOJson.isEmpty) {
return anime;
}
@@ -168,10 +168,10 @@ getAnimeDetail(MManga anime) async {
getLatestUpdatesAnime(MManga anime) async {
final res = await dataBase(anime.sourceId);
if (res.isEmpty) {
return anime;
if (res.hasError) {
return res;
}
List list = json.decode(res);
List list = json.decode(res.body);
List reversedList = list.reversed.toList();
List<MManga> animeList = animeResList(json.encode(reversedList));
@@ -181,10 +181,10 @@ getLatestUpdatesAnime(MManga anime) async {
searchAnime(MManga anime) async {
final res = await dataBase(anime.sourceId);
if (res.isEmpty) {
return anime;
if (res.hasError) {
return res;
}
List<MManga> animeList = animeSeachFetch(res, anime.query);
List<MManga> animeList = animeSeachFetch(res.body, anime.query);
return animeList;
}
@@ -298,10 +298,10 @@ getVideoList(MManga anime) async {
String stem =
MBridge.substringBefore(MBridge.substringAfterLast(anime.link, "/"), "?");
final res = await dataBase(anime.sourceId);
if (res.isEmpty) {
return anime;
if (res.hasError) {
return res;
}
final animeByTitleOJson = databaseAnimeByTitleO(res, stem);
final animeByTitleOJson = databaseAnimeByTitleO(res.body, stem);
if (animeByTitleOJson.isEmpty) {
return anime;
}
@@ -358,7 +358,11 @@ getVideoList(MManga anime) async {
"headers": {"Referer": "https://franime.fr/"},
"sourceId": anime.sourceId
};
final playerUrl = await MBridge.http('GET', json.encode(data));
final requestPlayerUrl = await MBridge.http('GET', json.encode(data));
if (requestPlayerUrl.hasError) {
return requestPlayerUrl;
}
String playerUrl = requestPlayerUrl.body;
List<MVideo> a = [];
if (playerName.contains("franime_myvi")) {
videos.add(video

View File

@@ -5,10 +5,11 @@ getPopularAnime(MManga anime) async {
final data = {
"url": "${anime.baseUrl}/toute-la-liste-affiches/page/${anime.page}/?q=."
};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls =
MBridge.xpath(res, '//*[@class="list"]/article/div/div/figure/a/@href');
anime.names = MBridge.xpath(
@@ -26,10 +27,11 @@ getPopularAnime(MManga anime) async {
getLatestUpdatesAnime(MManga anime) async {
final data = {"url": "${anime.baseUrl}/page/${anime.page}/"};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls = MBridge.xpath(res, '//*[@class="episode"]/div/a/@href');
final namess = MBridge.xpath(res, '//*[@class="episode"]/div/a/text()');
List<String> names = [];
@@ -72,17 +74,22 @@ getAnimeDetail(MManga anime) async {
];
final url = anime.link;
final data = {"url": url};
String res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
final originalUrl = MBridge.xpath(res,
'//*[@class="breadcrumb"]/li[@class="breadcrumb-item"][2]/a/@href')
.first;
if (originalUrl.isNotEmpty) {
final newData = {"url": originalUrl};
res = await MBridge.http('GET', json.encode(newData));
final newResponse = await MBridge.http('GET', json.encode(newData));
if (newResponse.hasError) {
return newResponse;
}
res = newResponse.body;
if (res.isEmpty) {
return anime;
}
@@ -124,10 +131,11 @@ searchAnime(MManga anime) async {
"url":
"${anime.baseUrl}/toute-la-liste-affiches/page/${anime.page}/?q=${anime.query}"
};
final res = await MBridge.http('GET', json.encode(data));
if (res.isEmpty) {
return anime;
final response = await MBridge.http('GET', json.encode(data));
if (response.hasError) {
return response;
}
String res = response.body;
anime.urls =
MBridge.xpath(res, '//*[@class="list"]/article/div/div/figure/a/@href');
@@ -150,11 +158,11 @@ getVideoList(MManga anime) async {
final res = await MBridge.http('GET', json.encode(datas));
if (res.isEmpty) {
return [];
if (res.hasError) {
return res;
}
final servers =
MBridge.xpath(res, '//*[@id="nav-tabContent"]/div/iframe/@src');
MBridge.xpath(res.body, '//*[@id="nav-tabContent"]/div/iframe/@src');
List<MVideo> videos = [];
for (var url in servers) {
final datasServer = {
@@ -162,7 +170,9 @@ getVideoList(MManga anime) async {
"headers": {"X-Requested-With": "XMLHttpRequest"}
};
final resServer = await MBridge.http('GET', json.encode(datasServer));
final responseResServer =
await MBridge.http('GET', json.encode(datasServer));
String resServer = responseResServer.body;
final serverUrl =
fixUrl(MBridge.regExp(resServer, r"data-url='([^']+)'", '', 1, 1));
List<MVideo> a = [];