From 0f10653698609f9fd67fd20a42499426dccaf94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Franti=C5=A1ek=20Straka?= <71689727+JosefFStraka@users.noreply.github.com> Date: Fri, 1 Nov 2024 05:23:51 +0100 Subject: [PATCH] fix(en/Aniplay): Video list empty fixed and other improvments (#343) * fix(en/AniPlay): Updated VersionCode * fix(en/AniPlay): Added idMal to request * fix(en/AniPlay): Added headers for backup domain * fix(en/AniPlay): Better episode list parsing --- src/en/aniplay/build.gradle | 2 +- .../animeextension/en/aniplay/AniPlay.kt | 76 ++++++++++++++++--- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/src/en/aniplay/build.gradle b/src/en/aniplay/build.gradle index 33076e1..3dd0fb2 100644 --- a/src/en/aniplay/build.gradle +++ b/src/en/aniplay/build.gradle @@ -2,7 +2,7 @@ ext { extName = 'AniPlay' extClass = '.AniPlay' themePkg = 'anilist' - overrideVersionCode = 3 + overrideVersionCode = 4 } apply from: "$rootDir/common.gradle" diff --git a/src/en/aniplay/src/eu/kanade/tachiyomi/animeextension/en/aniplay/AniPlay.kt b/src/en/aniplay/src/eu/kanade/tachiyomi/animeextension/en/aniplay/AniPlay.kt index d8ba151..63efd01 100644 --- a/src/en/aniplay/src/eu/kanade/tachiyomi/animeextension/en/aniplay/AniPlay.kt +++ b/src/en/aniplay/src/eu/kanade/tachiyomi/animeextension/en/aniplay/AniPlay.kt @@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.animesource.model.Track import eu.kanade.tachiyomi.animesource.model.Video import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils import eu.kanade.tachiyomi.multisrc.anilist.AniListAnimeHttpSource +import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.util.parallelFlatMapBlocking import eu.kanade.tachiyomi.util.parseAs @@ -67,6 +68,8 @@ class AniPlay : AniListAnimeHttpSource(), ConfigurableAnimeSource { } } + val baseHost: String get() = "${preferences.getString(PREF_DOMAIN_KEY, PREF_DOMAIN_DEFAULT)}" + /* ====================================== Episode List ====================================== */ override fun episodeListRequest(anime: SAnime): Request { @@ -79,7 +82,7 @@ class AniPlay : AniListAnimeHttpSource(), ConfigurableAnimeSource { val headersWithAction = headers.newBuilder() // next.js stuff I guess - .add("Next-Action", HEADER_NEXT_ACTION_EPISODE_LIST_VALUE) + .add("Next-Action", getHeaderValue(baseHost, NEXT_ACTION_EPISODE_LIST)) .build() return POST(url = "$baseUrl/anime/info/$animeId", headersWithAction, requestBody) @@ -90,8 +93,28 @@ class AniPlay : AniListAnimeHttpSource(), ConfigurableAnimeSource { val episodeListUrl = response.request.url val animeId = episodeListUrl.pathSegments[2] + val responsePage = client.newCall(GET("$baseUrl/anime/watch/$animeId")).execute() + val responsePageString = responsePage.body.string() + var idMal: Number? = null + val idMalIndex = responsePageString.indexOf("\\\"idMal\\\":") + if (idMalIndex != -1) { + val startIndex = idMalIndex + "\\\"idMal\\\":".length + val endIndex = responsePageString.indexOf(',', startIndex) + if (endIndex != -1) { + idMal = responsePageString.substring(startIndex, endIndex).toIntOrNull() + } + } + if (idMal == null) { + Log.e("AniPlay", "idMal not found - responsePageString: $responsePageString") + throw Exception("idMal not found") + } + val responseString = response.body.string() - val episodesArrayString = responseString.split("1:").last() + val episodesArrayString = extractEpisodeList(responseString) + if (episodesArrayString == null) { + Log.e("AniPlay", "Episode list not found - ${response.request}\nbody:${response.request.body}\n${responseString.substring(0,200)}") + throw Exception("Episode list not found") + } val providers = episodesArrayString.parseAs>() val episodes = mutableMapOf() @@ -127,6 +150,7 @@ class AniPlay : AniListAnimeHttpSource(), ConfigurableAnimeSource { .addQueryParameter("id", animeId) .addQueryParameter("ep", episodeNumber.toString()) .addQueryParameter("extras", episodeExtraString) + .addQueryParameter("idMal", idMal.toString()) .build() val name = parseEpisodeName(episodeNumber.toString(), episode.title) @@ -156,7 +180,7 @@ class AniPlay : AniListAnimeHttpSource(), ConfigurableAnimeSource { override suspend fun getVideoList(episode: SEpisode): List