Anichi: update homepage

This commit is contained in:
hexated 2023-07-02 23:05:21 +07:00
parent 541736305d
commit d051ccd9d1
2 changed files with 51 additions and 76 deletions

View file

@ -1,7 +1,7 @@
import org.jetbrains.kotlin.konan.properties.Properties import org.jetbrains.kotlin.konan.properties.Properties
// use an integer for version numbers // use an integer for version numbers
version = 2 version = 3
android { android {
defaultConfig { defaultConfig {

View file

@ -43,73 +43,51 @@ class Anichi : MainAPI() {
override val supportedTypes = setOf(TvType.Anime, TvType.AnimeMovie) override val supportedTypes = setOf(TvType.Anime, TvType.AnimeMovie)
private val popularTitle = "Popular" private val popularTitle = "Popular"
private val recentTitle = "Latest Updated" private val animeRecentTitle = "Latest Anime"
override val mainPage = listOf( private val donghuaRecentTitle = "Latest Donghua"
MainPageData( private val movieTitle = "Movie"
recentTitle,
"""$apiUrl?variables={"search":{"sortBy":"Latest_Update","allowAdult":${settingsForProvider.enableAdult},"allowUnknown":false},"limit":26,"page":%d,"translationType":"sub","countryOrigin":"ALL"}&extensions={"persistedQuery":{"version":1,"sha256Hash":"$mainHash"}}""" override val mainPage = mainPageOf(
), """$apiUrl?variables={"search":{"sortBy":"Latest_Update","allowAdult":${settingsForProvider.enableAdult},"allowUnknown":false},"limit":26,"page":%d,"translationType":"sub","countryOrigin":"JP"}&extensions={"persistedQuery":{"version":1,"sha256Hash":"$mainHash"}}""" to animeRecentTitle,
MainPageData( """$apiUrl?variables={"search":{"sortBy":"Latest_Update","allowAdult":${settingsForProvider.enableAdult},"allowUnknown":false},"limit":26,"page":%d,"translationType":"sub","countryOrigin":"CN"}&extensions={"persistedQuery":{"version":1,"sha256Hash":"$mainHash"}}""" to donghuaRecentTitle,
popularTitle, """$apiUrl?variables={"type":"anime","size":30,"dateRange":1,"page":%d,"allowAdult":${settingsForProvider.enableAdult},"allowUnknown":false}&extensions={"persistedQuery":{"version":1,"sha256Hash":"$popularHash"}}""" to popularTitle,
"""$apiUrl?variables={"type":"anime","size":30,"dateRange":1,"page":%d,"allowAdult":${settingsForProvider.enableAdult},"allowUnknown":false}&extensions={"persistedQuery":{"version":1,"sha256Hash":"$popularHash"}}""" """$apiUrl?variables={"search":{"slug":"movie-anime","format":"anime","tagType":"upcoming","name":"Trending Movies"}}&extensions={"persistedQuery":{"version":1,"sha256Hash":"$slugHash"}}""" to movieTitle
)
) )
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
val url = request.data.format(page) val url = request.data.format(page)
val test = app.get(url, headers = headers).text val res = app.get(url, headers = headers).parsedSafe<AnichiQuery>()?.data
val query = res?.shows ?: res?.queryPopular ?: res?.queryListForTag
val home = when (request.name) { val card = if(request.name == popularTitle) query?.recommendations?.map { it.anyCard } else query?.edges
recentTitle -> { val home = card?.mapNotNull { media ->
val json = parseJson<AnichiQuery>(test) media?.toSearchResponse()
val results = json.data.shows.edges.filter {
// filtering in case there is an anime with 0 episodes available on the site.
!(it.availableEpisodes?.raw == 0 && it.availableEpisodes.sub == 0 && it.availableEpisodes.dub == 0)
}
results.map {
newAnimeSearchResponse(it.name ?: "", "${it.Id}", fix = false) {
this.posterUrl = it.thumbnail
this.year = it.airedStart?.year
this.otherName = it.englishName
addDub(it.availableEpisodes?.dub)
addSub(it.availableEpisodes?.sub)
}
}
}
popularTitle -> {
val json = parseJson<PopularQuery>(test)
val results = json.data?.queryPopular?.recommendations?.filter {
// filtering in case there is an anime with 0 episodes available on the site.
!(it.anyCard?.availableEpisodes?.raw == 0 && it.anyCard.availableEpisodes.sub == 0 && it.anyCard.availableEpisodes.dub == 0)
}
results?.mapNotNull {
newAnimeSearchResponse(
it.anyCard?.name ?: return@mapNotNull null,
"${it.anyCard.Id ?: it.pageStatus?.Id}",
fix = false
) {
this.posterUrl = it.anyCard.thumbnail
this.otherName = it.anyCard.englishName
addDub(it.anyCard.availableEpisodes?.dub)
addSub(it.anyCard.availableEpisodes?.sub)
}
} ?: emptyList() } ?: emptyList()
} return newHomePageResponse(
else -> emptyList() list = HomePageList(
} name = request.name,
list = home,
),
hasNext = request.name != movieTitle
return HomePageResponse(
listOf(
HomePageList(request.name, home)
), hasNext = home.isNotEmpty()
) )
} }
override suspend fun search(query: String): List<SearchResponse> { private fun Edges.toSearchResponse(): AnimeSearchResponse? {
return newAnimeSearchResponse(
name ?: englishName ?: nativeName ?: "",
Id ?: return null,
fix = false
) {
this.posterUrl = thumbnail
this.year = airedStart?.year
this.otherName = englishName
addDub(availableEpisodes?.dub)
addSub(availableEpisodes?.sub)
}
}
override suspend fun search(query: String): List<SearchResponse>? {
val link = val link =
"""$apiUrl?variables={"search":{"allowAdult":false,"allowUnknown":false,"query":"$query"},"limit":26,"page":1,"translationType":"sub","countryOrigin":"ALL"}&extensions={"persistedQuery":{"version":1,"sha256Hash":"$mainHash"}}""" """$apiUrl?variables={"search":{"allowAdult":false,"allowUnknown":false,"query":"$query"},"limit":26,"page":1,"translationType":"sub","countryOrigin":"ALL"}&extensions={"persistedQuery":{"version":1,"sha256Hash":"$mainHash"}}"""
@ -126,12 +104,12 @@ class Anichi : MainAPI() {
val response = parseJson<AnichiQuery>(res) val response = parseJson<AnichiQuery>(res)
val results = response.data.shows.edges.filter { val results = response.data?.shows?.edges?.filter {
// filtering in case there is an anime with 0 episodes available on the site. // filtering in case there is an anime with 0 episodes available on the site.
!(it.availableEpisodes?.raw == 0 && it.availableEpisodes.sub == 0 && it.availableEpisodes.dub == 0) !(it.availableEpisodes?.raw == 0 && it.availableEpisodes.sub == 0 && it.availableEpisodes.dub == 0)
} }
return results.map { return results?.map {
newAnimeSearchResponse(it.name ?: "", "${it.Id}", fix = false) { newAnimeSearchResponse(it.name ?: "", "${it.Id}", fix = false) {
this.posterUrl = it.thumbnail this.posterUrl = it.thumbnail
this.year = it.airedStart?.year this.year = it.airedStart?.year
@ -401,6 +379,7 @@ class Anichi : MainAPI() {
private const val mainHash = "e42a4466d984b2c0a2cecae5dd13aa68867f634b16ee0f17b380047d14482406" private const val mainHash = "e42a4466d984b2c0a2cecae5dd13aa68867f634b16ee0f17b380047d14482406"
private const val popularHash = "31a117653812a2547fd981632e8c99fa8bf8a75c4ef1a77a1567ef1741a7ab9c" private const val popularHash = "31a117653812a2547fd981632e8c99fa8bf8a75c4ef1a77a1567ef1741a7ab9c"
private const val slugHash = "bf603205eb2533ca21d0324a11f623854d62ed838a27e1b3fcfb712ab98b03f4"
private const val detailHash = "bb263f91e5bdd048c1c978f324613aeccdfe2cbc694a419466a31edb58c0cc0b" private const val detailHash = "bb263f91e5bdd048c1c978f324613aeccdfe2cbc694a419466a31edb58c0cc0b"
private const val serverHash = "5e7e17cdd0166af5a2d8f43133d9ce3ce9253d1fdb5160a0cfd515564f98d061" private const val serverHash = "5e7e17cdd0166af5a2d8f43133d9ce3ce9253d1fdb5160a0cfd515564f98d061"
@ -452,13 +431,18 @@ class Anichi : MainAPI() {
) )
data class Data( data class Data(
@JsonProperty("shows") val shows: Shows @JsonProperty("shows") val shows: Shows? = null,
@JsonProperty("queryListForTag") val queryListForTag: Shows? = null,
@JsonProperty("queryPopular") val queryPopular: Shows? = null,
) )
data class Shows( data class Shows(
@JsonProperty("pageInfo") val pageInfo: PageInfo, @JsonProperty("edges") val edges: List<Edges>? = arrayListOf(),
@JsonProperty("edges") val edges: List<Edges>, @JsonProperty("recommendations") val recommendations: List<EdgesCard>? = arrayListOf(),
@JsonProperty("__typename") val _typename: String? )
data class EdgesCard(
@JsonProperty("anyCard") val anyCard: Edges? = null,
) )
data class CharacterImage( data class CharacterImage(
@ -518,13 +502,8 @@ class Anichi : MainAPI() {
@JsonProperty("year") val year: Int @JsonProperty("year") val year: Int
) )
data class PageInfo(
@JsonProperty("total") val total: Int?,
@JsonProperty("__typename") val _typename: String?
)
data class AnichiQuery( data class AnichiQuery(
@JsonProperty("data") val data: Data @JsonProperty("data") val data: Data? = null
) )
data class Detail( data class Detail(
@ -562,10 +541,6 @@ class Anichi : MainAPI() {
@JsonProperty("sourceUrls") val sourceUrls: ArrayList<SourceUrls> = arrayListOf(), @JsonProperty("sourceUrls") val sourceUrls: ArrayList<SourceUrls> = arrayListOf(),
) )
data class PopularQuery(
@JsonProperty("data") val data: DataPopular? = DataPopular()
)
data class Sub( data class Sub(
@JsonProperty("hour") val hour: Int? = null, @JsonProperty("hour") val hour: Int? = null,
@JsonProperty("minute") val minute: Int? = null, @JsonProperty("minute") val minute: Int? = null,