Hanime1: Fix anime details cover (#2)

* Hanime1: Fix anime details

- Use the series cover image for bangumi entries instead of the episode image.
- Version bump to 5

* Hanime1: Filter out ad
This commit is contained in:
AlphaBoom 2025-06-03 12:43:46 +08:00 committed by AlphaBoom
parent f84834770d
commit 9e4b2204bb
2 changed files with 27 additions and 6 deletions

View file

@ -1,7 +1,7 @@
ext {
extName = 'Hanime1'
extClass = '.Hanime1'
extVersionCode = 4
extVersionCode = 5
isNsfw = true
}

View file

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.animeextension.zh.hanime1
import android.app.Application
import android.content.SharedPreferences
import android.util.Log
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
@ -19,9 +20,11 @@ import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import okhttp3.Cookie
@ -65,14 +68,32 @@ class Hanime1 : AnimeHttpSource(), ConfigurableAnimeSource {
}
override fun animeDetailsParse(response: Response): SAnime {
val jsoup = response.asJsoup()
val doc = response.asJsoup()
return SAnime.create().apply {
genre = jsoup.select(".single-video-tag").not("[data-toggle]").eachText().joinToString()
author = jsoup.select("#video-artist-name").text()
jsoup.select("script[type=application/ld+json]").first()?.data()?.let {
genre = doc.select(".single-video-tag").not("[data-toggle]").eachText().joinToString()
author = doc.select("#video-artist-name").text()
doc.select("script[type=application/ld+json]").first()?.data()?.let {
val info = json.decodeFromString<JsonElement>(it).jsonObject
title = info["name"]!!.jsonPrimitive.content
description = info["description"]!!.jsonPrimitive.content
thumbnail_url = info["thumbnailUrl"]?.jsonArray?.get(0)?.jsonPrimitive?.content
}
val type = doc.select("a#video-artist-name + a").text().trim()
if (type == "裏番" || type == "泡麵番") {
// Use the series cover image for bangumi entries instead of the episode image.
runBlocking {
try {
val animesPage =
getSearchAnime(
1,
title,
AnimeFilterList(GenreFilter(arrayOf("", type)).apply { state = 1 }),
)
thumbnail_url = animesPage.animes.first().thumbnail_url
} catch (e: Exception) {
Log.e(name, "Failed to get bangumi cover image")
}
}
}
}
}
@ -137,7 +158,7 @@ class Hanime1 : AnimeHttpSource(), ConfigurableAnimeSource {
override fun searchAnimeParse(response: Response): AnimesPage {
val jsoup = response.asJsoup()
val nodes = jsoup.select("div.search-doujin-videos.hidden-xs")
val nodes = jsoup.select("div.search-doujin-videos.hidden-xs:not(:has(a[target=_blank]))")
val list = if (nodes.isNotEmpty()) {
nodes.map {
SAnime.create().apply {