Merge remote-tracking branch 'origin/master'

This commit is contained in:
LagradOst 2021-08-26 00:16:30 +02:00
commit 26e71019c8

View file

@ -63,6 +63,7 @@ class AnimePaheProvider : MainAPI() {
@JsonProperty("id") val id: Int, @JsonProperty("id") val id: Int,
@JsonProperty("anime_id") val animeId: Int, @JsonProperty("anime_id") val animeId: Int,
@JsonProperty("anime_title") val animeTitle: String, @JsonProperty("anime_title") val animeTitle: String,
@JsonProperty("anime_slug") val animeSlug: String,
@JsonProperty("episode") val episode: Int, @JsonProperty("episode") val episode: Int,
@JsonProperty("snapshot") val snapshot: String, @JsonProperty("snapshot") val snapshot: String,
@JsonProperty("created_at") val createdAt: String, @JsonProperty("created_at") val createdAt: String,
@ -86,7 +87,7 @@ class AnimePaheProvider : MainAPI() {
AnimeSearchResponse( AnimeSearchResponse(
it.animeTitle, it.animeTitle,
"https://animepahe.com/anime/${it.animeSession}", "https://pahe.win/a/${it.animeId}?slug=${it.animeTitle}",
this.name, this.name,
TvType.Anime, TvType.Anime,
it.snapshot, it.snapshot,
@ -107,28 +108,42 @@ class AnimePaheProvider : MainAPI() {
return HomePageResponse(items) return HomePageResponse(items)
} }
data class AnimePaheSearchData(
@JsonProperty("id") val id: Int,
@JsonProperty("slug") val slug: String,
@JsonProperty("title") val title: String,
@JsonProperty("type") val type: String,
@JsonProperty("episodes") val episodes: Int,
@JsonProperty("status") val status: String,
@JsonProperty("season") val season: String,
@JsonProperty("year") val year: Int,
@JsonProperty("score") val score: Double,
@JsonProperty("poster") val poster: String,
@JsonProperty("session") val session: String,
@JsonProperty("relevance") val relevance: String
)
data class AnimePaheSearch(
@JsonProperty("total") val total: Int,
@JsonProperty("data") val data: List<AnimePaheSearchData>
)
private fun getAnimeByIdAndTitle(title: String, animeId: Int): String? {
val url = "$mainUrl/api?m=search&l=8&q=$title"
val headers = mapOf("referer" to "$mainUrl/")
val req = khttp.get(url, headers = headers)
val data = req.let { mapper.readValue<AnimePaheSearch>(it.text) }
for (anime in data.data) {
if (anime.id == animeId) {
return "https://animepahe.com/anime/${anime.session}"
}
}
return null
}
override fun search(query: String): ArrayList<SearchResponse> { override fun search(query: String): ArrayList<SearchResponse> {
data class AnimePaheSearchData(
@JsonProperty("id") val id: Int,
@JsonProperty("slug") val slug: String,
@JsonProperty("title") val title: String,
@JsonProperty("type") val type: String,
@JsonProperty("episodes") val episodes: Int,
@JsonProperty("status") val status: String,
@JsonProperty("season") val season: String,
@JsonProperty("year") val year: Int,
@JsonProperty("score") val score: Double,
@JsonProperty("poster") val poster: String,
@JsonProperty("session") val session: String,
@JsonProperty("relevance") val relevance: String
)
data class AnimePaheSearch(
@JsonProperty("total") val total: Int,
@JsonProperty("data") val data: List<AnimePaheSearchData>
)
val url = "$mainUrl/api?m=search&l=8&q=$query" val url = "$mainUrl/api?m=search&l=8&q=$query"
val headers = mapOf("referer" to "$mainUrl/") val headers = mapOf("referer" to "$mainUrl/")
@ -138,7 +153,7 @@ class AnimePaheProvider : MainAPI() {
return ArrayList(data.data.map { return ArrayList(data.data.map {
AnimeSearchResponse( AnimeSearchResponse(
it.title, it.title,
"https://animepahe.com/anime/${it.session}", "https://pahe.win/a/${it.id}?slug=${it.title}",
this.name, this.name,
TvType.Anime, TvType.Anime,
it.poster, it.poster,
@ -178,7 +193,7 @@ class AnimePaheProvider : MainAPI() {
private fun generateListOfEpisodes(link: String): ArrayList<AnimeEpisode> { private fun generateListOfEpisodes(link: String): ArrayList<AnimeEpisode> {
try { try {
val attrs = link.split('/') val attrs = link.split('/')
val id = attrs[attrs.size - 1] val id = attrs[attrs.size - 1].split("?")[0]
val uri = "$mainUrl/api?m=release&id=$id&sort=episode_asc&page=1" val uri = "$mainUrl/api?m=release&id=$id&sort=episode_asc&page=1"
val headers = mapOf("referer" to "$mainUrl/") val headers = mapOf("referer" to "$mainUrl/")
@ -237,10 +252,14 @@ class AnimePaheProvider : MainAPI() {
override fun load(url: String): LoadResponse? { override fun load(url: String): LoadResponse? {
return normalSafeApiCall { return normalSafeApiCall {
val html = khttp.get(url).text
val regex = Regex("""a/(\d+)\?slug=(.+)""")
val (animeId, animeTitle) = regex.find(url)!!.destructured
val link = getAnimeByIdAndTitle(animeTitle, animeId.toInt())!!
val html = khttp.get(link).text
val doc = Jsoup.parse(html) val doc = Jsoup.parse(html)
val title = doc.selectFirst(".anime-poster img")?.attr("alt")?.replace("Poster of ", "")
val japTitle = doc.selectFirst("h2.japanese")?.text() val japTitle = doc.selectFirst("h2.japanese")?.text()
val poster = doc.selectFirst(".anime-poster a").attr("href") val poster = doc.selectFirst(".anime-poster a").attr("href")
@ -277,9 +296,9 @@ class AnimePaheProvider : MainAPI() {
} }
AnimeLoadResponse( AnimeLoadResponse(
title, animeTitle,
japTitle, japTitle,
title.toString(), animeTitle,
url, url,
this.name, this.name,
getType(tvType.toString()), getType(tvType.toString()),