fix(nyaa): ensure chapters is List<MChapter> to avoid type cast error

This commit is contained in:
xMohnad
2025-06-25 18:56:50 +00:00
parent af9a36a94e
commit 1b6e122a8c

View File

@@ -9,23 +9,21 @@ class Nyaa extends MProvider {
@override @override
Future<MPages> getPopular(int page) async { Future<MPages> getPopular(int page) async {
final res = final res = (await client.get(
(await client.get( Uri.parse(
Uri.parse( "${source.baseUrl}/?f=0&c=${getPreferenceValue(source.id, "preferred_categorie_page")}&q=&s=downloads&o=desc&p=$page",
"${source.baseUrl}/?f=0&c=${getPreferenceValue(source.id, "preferred_categorie_page")}&q=&s=downloads&o=desc&p=$page", ),
), )).body;
)).body;
return parseAnimeList(res); return parseAnimeList(res);
} }
@override @override
Future<MPages> getLatestUpdates(int page) async { Future<MPages> getLatestUpdates(int page) async {
final res = final res = (await client.get(
(await client.get( Uri.parse(
Uri.parse( "${source.baseUrl}/?f=0&c=${getPreferenceValue(source.id, "preferred_categorie_page")}&q=$page",
"${source.baseUrl}/?f=0&c=${getPreferenceValue(source.id, "preferred_categorie_page")}&q=$page", ),
), )).body;
)).body;
return parseAnimeList(res); return parseAnimeList(res);
} }
@@ -57,11 +55,17 @@ class Nyaa extends MProvider {
description += description +=
"\n\n${(document.xpathFirst('//div[@class="panel panel-default"]/text()') ?? "").trim().replaceAll("\n", "")}"; "\n\n${(document.xpathFirst('//div[@class="panel panel-default"]/text()') ?? "").trim().replaceAll("\n", "")}";
anime.description = description; anime.description = description;
MChapter ep = MChapter();
ep.name = "Torrent"; List<MChapter> chapters = [];
ep.url = chapters.add(
"${source.baseUrl}/download/${substringAfterLast(url, '/')}.torrent"; MChapter(
anime.chapters = [ep]; name: "Torrent",
url:
"${source.baseUrl}/download/${substringAfterLast(url, '/')}.torrent",
),
);
anime.chapters = chapters;
return anime; return anime;
} }
@@ -114,27 +118,25 @@ class Nyaa extends MProvider {
MManga anime = MManga(); MManga anime = MManga();
anime.imageUrl = anime.imageUrl =
"${source.baseUrl}${getUrlWithoutDomain(value.selectFirst("td:nth-child(1) > a > img").getSrc)}"; "${source.baseUrl}${getUrlWithoutDomain(value.selectFirst("td:nth-child(1) > a > img").getSrc)}";
MElement firstElement = MElement firstElement = value
value .select("td > a")
.select("td > a") .where(
.where( (MElement e) =>
(MElement e) => e.outerHtml.contains("/view/") &&
e.outerHtml.contains("/view/") && !e.outerHtml.contains("#comments"),
!e.outerHtml.contains("#comments"), )
) .toList()
.toList() .first;
.first;
anime.link = anime.link =
"${source.baseUrl}${getUrlWithoutDomain(firstElement.getHref)}"; "${source.baseUrl}${getUrlWithoutDomain(firstElement.getHref)}";
anime.name = firstElement.attr("title"); anime.name = firstElement.attr("title");
animeList.add(anime); animeList.add(anime);
} }
final hasNextPage = final hasNextPage = xpath(
xpath( res,
res, '//ul[@class="pagination"]/li[contains(text(),"»")]/a/@href',
'//ul[@class="pagination"]/li[contains(text(),"»")]/a/@href', ).isNotEmpty;
).isNotEmpty;
return MPages(animeList, hasNextPage); return MPages(animeList, hasNextPage);
} }