AnimePahe: Fix broken library URLs (#1397)

* Fix: add support to old animepahe URLs

* chore: bump version
This commit is contained in:
Claudemirovsky 2023-03-15 18:08:45 -03:00 committed by GitHub
parent 70a9b8c71d
commit 4da99feaa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'AnimePahe'
pkgNameSuffix = 'en.animepahe'
extClass = '.AnimePahe'
extVersionCode = 21
extVersionCode = 22
libVersion = '13'
}

View File

@ -52,6 +52,16 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
override val client: OkHttpClient = network.cloudflareClient
// =========================== Anime Details ============================
override fun animeDetailsRequest(anime: SAnime): Request {
return if (anime.getSession().isBlank()) {
val animeId = anime.getId()
val session = fetchSession(anime.title, animeId)
return GET("$baseUrl/anime/$session?anime_id=$animeId")
} else {
super.animeDetailsRequest(anime)
}
}
override fun animeDetailsParse(response: Response): SAnime {
val document = response.use { it.asJsoup() }
return SAnime.create().apply {
@ -117,7 +127,9 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
// ============================== Episodes ==============================
override fun episodeListRequest(anime: SAnime): Request {
val session = anime.url.substringBefore("?anime_id=").substringAfterLast("/")
val session = anime.getSession().ifEmpty {
fetchSession(anime.title, anime.getId())
}
return GET("$baseUrl/api?m=release&id=$session&sort=episode_desc&page=1")
}
@ -262,6 +274,15 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
}
// ============================= Utilities ==============================
private fun fetchSession(title: String, animeId: String): String {
return client.newCall(GET("$baseUrl/api?m=search&q=$title"))
.execute()
.use { it.body.string() }
.substringAfter("\"id\":$animeId")
.substringAfter("\"session\":\"")
.substringBefore("\"")
}
private fun parseStatus(statusString: String): Int {
return when (statusString) {
"Currently Airing" -> SAnime.ONGOING
@ -270,6 +291,9 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
}
}
private fun SAnime.getSession() = url.substringBefore("?anime_id=").substringAfterLast("/")
private fun SAnime.getId() = url.substringAfterLast("?anime_id=").substringBefore("\"")
private fun String.toDate(): Long {
return runCatching {
DATE_FORMATTER.parse(this)?.time ?: 0L