code refactor & optimisation

This commit is contained in:
kodjomoustapha
2023-07-30 15:28:20 +01:00
parent 00878e8ea3
commit 818b40c952
3 changed files with 84 additions and 86 deletions

View File

@@ -4,7 +4,7 @@ import 'package:bridge_lib/bridge_lib.dart';
Future<String> dataBase(int sourceId) async { Future<String> dataBase(int sourceId) async {
final data = { final data = {
"url": "https://api.franime.fr/api/animes/", "url": "https://api.franime.fr/api/animes/",
"headers": {"Referer": "https://franime.fr"}, "headers": {"Referer": "https://franime.fr/"},
"sourceId": sourceId "sourceId": sourceId
}; };
final res = await MBridge.http(json.encode(data), 0); final res = await MBridge.http(json.encode(data), 0);
@@ -14,52 +14,52 @@ Future<String> dataBase(int sourceId) async {
getPopularAnime(MangaModel anime) async { getPopularAnime(MangaModel anime) async {
final data = { final data = {
"url": "https://api.franime.fr/api/animes/", "url": "https://api.franime.fr/api/animes/",
"headers": {"Referer": "https://franime.fr"}, "headers": {"Referer": "https://franime.fr/"},
"sourceId": anime.sourceId "sourceId": anime.sourceId
}; };
final res = await MBridge.http(json.encode(data), 0); final res = await MBridge.http(json.encode(data), 0);
List<MangaModel> animeList = animePage(res);
if (res.isEmpty) { if (res.isEmpty) {
return anime; return [];
} }
List<MangaModel> animeList = animeResList(res);
return animeList; return animeList;
} }
List<MangaModel> animePage(String res) { List<MangaModel> animeResList(String res) {
final statusList = [ final statusList = [
{"EN COURS": 0, "TERMINÉ": 1} {"EN COURS": 0, "TERMINÉ": 1}
]; ];
List<MangaModel> animeList = []; List<MangaModel> animeList = [];
final genres = MBridge.jsonPathToList(res, r'$..themes', 1);
final images = MBridge.jsonPathToList(res, r'$..affiche', 0);
final descriptions = MBridge.jsonPathToList(res, r'$..description', 0);
final seasonss = MBridge.jsonPathToList(res, r'$..saisons', 1);
final statuss = MBridge.jsonPathToList(res, r'$..status', 0);
final titles = MBridge.jsonPathToList(res, r'$..title', 0);
final titleOs = MBridge.jsonPathToList(res, r'$..titleO', 0);
final langs = final langs =
MBridge.jsonPathToList(res, r'$..saisons[*].episodes[*].lang', 1); MBridge.jsonPathToList(res, r'$..saisons[*].episodes[*].lang', 1);
int index = 0; int index = 0;
for (var saisons in seasonss) { List<String> jsonResList = MBridge.jsonDecodeToList(res, 1);
for (var animeJson in jsonResList) {
MangaModel anime = MangaModel(); MangaModel anime = MangaModel();
List<String> seasons = MBridge.jsonDecodeToList(saisons, 0); List<String> seasons = MBridge.jsonDecodeToList(
final titleO = MBridge.listParse(titleOs, 0)[index]; MBridge.getMapValue(animeJson, "saisons", 1), 1);
final titleO = MBridge.getMapValue(animeJson, "titleO", 0);
final vo = MBridge.getMapValue(MBridge.listParse(langs, 0)[index], "vo", 1); final vo = MBridge.getMapValue(MBridge.listParse(langs, 0)[index], "vo", 1);
final vf = MBridge.getMapValue(MBridge.listParse(langs, 0)[index], "vf", 1); final vf = MBridge.getMapValue(MBridge.listParse(langs, 0)[index], "vf", 1);
final hasVostfr = MBridge.isEmptyOrIsNotEmpty( final hasVostfr = MBridge.isEmptyOrIsNotEmpty(
MBridge.jsonDecodeToList(MBridge.getMapValue(vo, "lecteurs", 1), 0), 1); MBridge.jsonDecodeToList(MBridge.getMapValue(vo, "lecteurs", 1), 0), 1);
final hasVf = MBridge.isEmptyOrIsNotEmpty( final hasVf = MBridge.isEmptyOrIsNotEmpty(
MBridge.jsonDecodeToList(MBridge.getMapValue(vf, "lecteurs", 1), 0), 1); MBridge.jsonDecodeToList(MBridge.getMapValue(vf, "lecteurs", 1), 0), 1);
String title = MBridge.getMapValue(animeJson, "title", 0);
final genre = MBridge.jsonDecodeToList(
MBridge.getMapValue(animeJson, "themes", 1), 0);
final description = MBridge.getMapValue(animeJson, "description", 0);
final status = MBridge.parseStatus(
MBridge.getMapValue(animeJson, "status", 0), statusList);
final imageUrl = MBridge.getMapValue(animeJson, "affiche", 0);
if (hasVostfr) { if (hasVostfr) {
for (int i = 0; i < seasons.length; i++) { for (int i = 0; i < seasons.length; i++) {
int ind = i + 1; int ind = i + 1;
String title = MBridge.listParse(titles, 0)[index].toString();
anime.genre = anime.genre = genre;
MBridge.jsonDecodeToList(MBridge.listParse(genres, 0)[index], 0);
anime.description = anime.description = description;
MBridge.listParse(descriptions, 0)[index].toString();
String seasonTitle = title; String seasonTitle = title;
if (seasons.length > 1) { if (seasons.length > 1) {
seasonTitle += " S$ind"; seasonTitle += " S$ind";
@@ -67,10 +67,9 @@ List<MangaModel> animePage(String res) {
if (hasVostfr) { if (hasVostfr) {
seasonTitle += " VOSTFR"; seasonTitle += " VOSTFR";
} }
anime.status = MBridge.parseStatus( anime.status = status;
MBridge.listParse(statuss, 0)[index], statusList);
anime.name = seasonTitle; anime.name = seasonTitle;
anime.imageUrl = MBridge.listParse(images, 0)[index]; anime.imageUrl = imageUrl;
anime.link = anime.link =
"/anime/${MBridge.regExp(titleO, "[^A-Za-z0-9 ]", "", 0, 0).replaceAll(" ", "-").toLowerCase()}?lang=vo&s=$ind"; "/anime/${MBridge.regExp(titleO, "[^A-Za-z0-9 ]", "", 0, 0).replaceAll(" ", "-").toLowerCase()}?lang=vo&s=$ind";
ind++; ind++;
@@ -78,11 +77,8 @@ List<MangaModel> animePage(String res) {
} else if (hasVf) { } else if (hasVf) {
for (int i = 0; i < seasons.length; i++) { for (int i = 0; i < seasons.length; i++) {
int ind = i + 1; int ind = i + 1;
String title = MBridge.listParse(titles, 0)[index].toString(); anime.genre = genre;
anime.genre = anime.description = description;
MBridge.jsonDecodeToList(MBridge.listParse(genres, 0)[index], 0);
anime.description =
MBridge.listParse(descriptions, 0)[index].toString();
String seasonTitle = title; String seasonTitle = title;
if (seasons.length > 1) { if (seasons.length > 1) {
seasonTitle += " S$ind"; seasonTitle += " S$ind";
@@ -90,10 +86,9 @@ List<MangaModel> animePage(String res) {
if (hasVf) { if (hasVf) {
seasonTitle += " VF"; seasonTitle += " VF";
} }
anime.status = MBridge.parseStatus( anime.status = status;
MBridge.listParse(statuss, 0)[index], statusList);
anime.name = seasonTitle; anime.name = seasonTitle;
anime.imageUrl = MBridge.listParse(images, 0)[index]; anime.imageUrl = imageUrl;
anime.link = anime.link =
"/anime/${MBridge.regExp(titleO, "[^A-Za-z0-9 ]", "", 0, 0).replaceAll(" ", "-").toLowerCase()}?lang=vo&s=$ind"; "/anime/${MBridge.regExp(titleO, "[^A-Za-z0-9 ]", "", 0, 0).replaceAll(" ", "-").toLowerCase()}?lang=vo&s=$ind";
ind++; ind++;
@@ -106,6 +101,7 @@ List<MangaModel> animePage(String res) {
} }
String databaseAnimeByTitleO(String res, String titleO) { String databaseAnimeByTitleO(String res, String titleO) {
print(titleO);
List<String> datas = MBridge.jsonDecodeToList(res, 1); List<String> datas = MBridge.jsonDecodeToList(res, 1);
for (var data in datas) { for (var data in datas) {
if (MBridge.regExp(MBridge.getMapValue(data, "titleO", 0), "[^A-Za-z0-9 ]", if (MBridge.regExp(MBridge.getMapValue(data, "titleO", 0), "[^A-Za-z0-9 ]",
@@ -116,12 +112,11 @@ String databaseAnimeByTitleO(String res, String titleO) {
return data; return data;
} }
} }
return "dffd"; return "";
} }
getAnimeDetail(MangaModel anime) async { getAnimeDetail(MangaModel anime) async {
String language = "vo".toString(); String language = "vo".toString();
if (anime.link.contains("lang=")) { if (anime.link.contains("lang=")) {
language = MBridge.listParse( language = MBridge.listParse(
MBridge.listParse(anime.link.split("lang="), 2)[0].split("&"), 1)[0]; MBridge.listParse(anime.link.split("lang="), 2)[0].split("&"), 1)[0];
@@ -130,7 +125,13 @@ getAnimeDetail(MangaModel anime) async {
String stem = MBridge.listParse( String stem = MBridge.listParse(
MBridge.listParse(anime.link.split("/"), 2)[0].split("?"), 1)[0]; MBridge.listParse(anime.link.split("/"), 2)[0].split("?"), 1)[0];
final res = await dataBase(anime.sourceId); final res = await dataBase(anime.sourceId);
if (res.isEmpty) {
return anime;
}
final animeByTitleOJson = databaseAnimeByTitleO(res, stem); final animeByTitleOJson = databaseAnimeByTitleO(res, stem);
if (animeByTitleOJson.isEmpty) {
return anime;
}
String seasonsJson = String seasonsJson =
MBridge.jsonPathToList(animeByTitleOJson, r'$..saisons', 1)[0]; MBridge.jsonPathToList(animeByTitleOJson, r'$..saisons', 1)[0];
List<String> seasons = MBridge.jsonDecodeToList(seasonsJson, 1); List<String> seasons = MBridge.jsonDecodeToList(seasonsJson, 1);
@@ -148,7 +149,6 @@ getAnimeDetail(MangaModel anime) async {
List<String> episodesNames = []; List<String> episodesNames = [];
List<String> episodesUrls = []; List<String> episodesUrls = [];
for (int i = 0; i < episodes.length; i++) { for (int i = 0; i < episodes.length; i++) {
print(i);
String episode = MBridge.listParse(episodes, 0)[i]; String episode = MBridge.listParse(episodes, 0)[i];
final lang = MBridge.getMapValue(episode, "lang", 1); final lang = MBridge.getMapValue(episode, "lang", 1);
final vo = MBridge.getMapValue(lang, "vo", 1); final vo = MBridge.getMapValue(lang, "vo", 1);
@@ -169,9 +169,7 @@ getAnimeDetail(MangaModel anime) async {
episodesNames.add(title.replaceAll('"', "")); episodesNames.add(title.replaceAll('"', ""));
} }
} }
if (res.isEmpty) {
return anime;
}
anime.urls = episodesUrls; anime.urls = episodesUrls;
anime.names = episodesNames; anime.names = episodesNames;
anime.chaptersDateUploads = []; anime.chaptersDateUploads = [];
@@ -195,7 +193,7 @@ getLatestUpdatesAnime(MangaModel anime) async {
} }
reversedJson += "$vg$va"; reversedJson += "$vg$va";
} }
List<MangaModel> animeList = animePage("[${reversedJson}]"); List<MangaModel> animeList = animeResList("[${reversedJson}]");
return animeList; return animeList;
} }
@@ -215,22 +213,16 @@ List<MangaModel> animeSeachFetch(String res, query) {
{"EN COURS": 0, "TERMINÉ": 1} {"EN COURS": 0, "TERMINÉ": 1}
]; ];
List<MangaModel> animeList = []; List<MangaModel> animeList = [];
final genres = MBridge.jsonPathToList(res, r'$..themes', 1);
final images = MBridge.jsonPathToList(res, r'$..affiche', 0);
final descriptions = MBridge.jsonPathToList(res, r'$..description', 0);
final seasonss = MBridge.jsonPathToList(res, r'$..saisons', 1);
final statuss = MBridge.jsonPathToList(res, r'$..status', 0);
final titles = MBridge.jsonPathToList(res, r'$..title', 0);
final titleOs = MBridge.jsonPathToList(res, r'$..titleO', 0);
final titlesAlt = MBridge.jsonPathToList(res, r'$..titles', 1);
final langs = final langs =
MBridge.jsonPathToList(res, r'$..saisons[*].episodes[*].lang', 1); MBridge.jsonPathToList(res, r'$..saisons[*].episodes[*].lang', 1);
int index = 0; int index = 0;
for (var saisons in seasonss) { List<String> jsonResList = MBridge.jsonDecodeToList(res, 1);
for (var animeJson in jsonResList) {
MangaModel anime = MangaModel(); MangaModel anime = MangaModel();
List<String> seasons = MBridge.jsonDecodeToList(saisons, 0);
final titleO = MBridge.listParse(titleOs, 0)[index]; final titleO = MBridge.getMapValue(animeJson, "titleO", 0);
final titleAlt = MBridge.listParse(titlesAlt, 0)[index];
final titleAlt = MBridge.getMapValue(animeJson, "titles", 1);
final enContains = MBridge.getMapValue(titleAlt, "en", 0) final enContains = MBridge.getMapValue(titleAlt, "en", 0)
.toString() .toString()
.toLowerCase() .toLowerCase()
@@ -258,6 +250,8 @@ List<MangaModel> animeSeachFetch(String res, query) {
contains = true; contains = true;
} }
if (contains) { if (contains) {
List<String> seasons = MBridge.jsonDecodeToList(
MBridge.getMapValue(animeJson, "saisons", 1), 1);
final vo = final vo =
MBridge.getMapValue(MBridge.listParse(langs, 0)[index], "vo", 1); MBridge.getMapValue(MBridge.listParse(langs, 0)[index], "vo", 1);
final vf = final vf =
@@ -268,14 +262,19 @@ List<MangaModel> animeSeachFetch(String res, query) {
final hasVf = MBridge.isEmptyOrIsNotEmpty( final hasVf = MBridge.isEmptyOrIsNotEmpty(
MBridge.jsonDecodeToList(MBridge.getMapValue(vf, "lecteurs", 1), 0), MBridge.jsonDecodeToList(MBridge.getMapValue(vf, "lecteurs", 1), 0),
1); 1);
String title = MBridge.getMapValue(animeJson, "title", 0);
final genre = MBridge.jsonDecodeToList(
MBridge.getMapValue(animeJson, "themes", 1), 0);
final description = MBridge.getMapValue(animeJson, "description", 0);
final status = MBridge.parseStatus(
MBridge.getMapValue(animeJson, "status", 0), statusList);
final imageUrl = MBridge.getMapValue(animeJson, "affiche", 0);
if (hasVostfr) { if (hasVostfr) {
for (int i = 0; i < seasons.length; i++) { for (int i = 0; i < seasons.length; i++) {
int ind = i + 1; int ind = i + 1;
String title = MBridge.listParse(titles, 0)[index].toString();
anime.genre = anime.genre = genre;
MBridge.jsonDecodeToList(MBridge.listParse(genres, 0)[index], 0); anime.description = description;
anime.description =
MBridge.listParse(descriptions, 0)[index].toString();
String seasonTitle = title; String seasonTitle = title;
if (seasons.length > 1) { if (seasons.length > 1) {
seasonTitle += " S$ind"; seasonTitle += " S$ind";
@@ -283,10 +282,9 @@ List<MangaModel> animeSeachFetch(String res, query) {
if (hasVostfr) { if (hasVostfr) {
seasonTitle += " VOSTFR"; seasonTitle += " VOSTFR";
} }
anime.status = MBridge.parseStatus( anime.status = status;
MBridge.listParse(statuss, 0)[index], statusList);
anime.name = seasonTitle; anime.name = seasonTitle;
anime.imageUrl = MBridge.listParse(images, 0)[index]; anime.imageUrl = imageUrl;
anime.link = anime.link =
"/anime/${MBridge.regExp(titleO, "[^A-Za-z0-9 ]", "", 0, 0).replaceAll(" ", "-").toLowerCase()}?lang=vo&s=$ind"; "/anime/${MBridge.regExp(titleO, "[^A-Za-z0-9 ]", "", 0, 0).replaceAll(" ", "-").toLowerCase()}?lang=vo&s=$ind";
ind++; ind++;
@@ -294,11 +292,8 @@ List<MangaModel> animeSeachFetch(String res, query) {
} else if (hasVf) { } else if (hasVf) {
for (int i = 0; i < seasons.length; i++) { for (int i = 0; i < seasons.length; i++) {
int ind = i + 1; int ind = i + 1;
String title = MBridge.listParse(titles, 0)[index].toString(); anime.genre = genre;
anime.genre = anime.description = description;
MBridge.jsonDecodeToList(MBridge.listParse(genres, 0)[index], 0);
anime.description =
MBridge.listParse(descriptions, 0)[index].toString();
String seasonTitle = title; String seasonTitle = title;
if (seasons.length > 1) { if (seasons.length > 1) {
seasonTitle += " S$ind"; seasonTitle += " S$ind";
@@ -306,10 +301,9 @@ List<MangaModel> animeSeachFetch(String res, query) {
if (hasVf) { if (hasVf) {
seasonTitle += " VF"; seasonTitle += " VF";
} }
anime.status = MBridge.parseStatus( anime.status = status;
MBridge.listParse(statuss, 0)[index], statusList);
anime.name = seasonTitle; anime.name = seasonTitle;
anime.imageUrl = MBridge.listParse(images, 0)[index]; anime.imageUrl = imageUrl;
anime.link = anime.link =
"/anime/${MBridge.regExp(titleO, "[^A-Za-z0-9 ]", "", 0, 0).replaceAll(" ", "-").toLowerCase()}?lang=vf&s=$ind"; "/anime/${MBridge.regExp(titleO, "[^A-Za-z0-9 ]", "", 0, 0).replaceAll(" ", "-").toLowerCase()}?lang=vf&s=$ind";
ind++; ind++;

View File

@@ -1,7 +1,7 @@
import '../../../../model/source.dart'; import '../../../../model/source.dart';
Source get franimeSource => _franimeSource; Source get franimeSource => _franimeSource;
const franimeVersion = "0.0.11"; const franimeVersion = "0.0.12";
const franimeSourceCodeUrl = const franimeSourceCodeUrl =
"https://raw.githubusercontent.com/kodjodevf/mangayomi-extensions/main/anime/src/fr/franime/franime-v$franimeVersion.dart"; "https://raw.githubusercontent.com/kodjodevf/mangayomi-extensions/main/anime/src/fr/franime/franime-v$franimeVersion.dart";
Source _franimeSource = Source( Source _franimeSource = Source(

View File

@@ -1,5 +1,6 @@
class Source { class Source {
String? id; String? id;
String? name; String? name;
String? baseUrl; String? baseUrl;
@@ -28,8 +29,10 @@ class Source {
bool? isFullData; bool? isFullData;
Source({ String? appMinVerReq;
this.id = null,
Source(
{this.id = null,
this.name = "", this.name = "",
this.baseUrl = "", this.baseUrl = "",
this.lang = "", this.lang = "",
@@ -44,7 +47,7 @@ class Source {
this.version = "", this.version = "",
this.isManga = true, this.isManga = true,
this.isFullData = false, this.isFullData = false,
}); this.appMinVerReq = "0.0.21"});
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {
@@ -62,7 +65,8 @@ class Source {
"apiUrl": apiUrl, "apiUrl": apiUrl,
"version": version, "version": version,
"isManga": isManga, "isManga": isManga,
"isFullData": isFullData "isFullData": isFullData,
"appMinVerReq": appMinVerReq
}; };
} }
} }