kitsu description fix
This commit is contained in:
parent
3c992f89f4
commit
b018d0f090
4 changed files with 70 additions and 23 deletions
|
@ -46,18 +46,11 @@ class AnimeNameAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeEpisodeNumber(text: String): String {
|
fun removeEpisodeNumber(text: String): String {
|
||||||
val regexPattern = Regex(episodeRegex, RegexOption.IGNORE_CASE)
|
|
||||||
return text.replace(regexPattern, "").ifEmpty {
|
|
||||||
text
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeEpisodeNumberCompletely(text: String): String {
|
|
||||||
val regexPattern = Regex(episodeRegex, RegexOption.IGNORE_CASE)
|
val regexPattern = Regex(episodeRegex, RegexOption.IGNORE_CASE)
|
||||||
val removedNumber = text.replace(regexPattern, "").ifEmpty {
|
val removedNumber = text.replace(regexPattern, "").ifEmpty {
|
||||||
text
|
text
|
||||||
}
|
}
|
||||||
return if (removedNumber.equals(text, true)) {
|
return if (removedNumber.equals(text, true)) { // if nothing was removed
|
||||||
val failedEpisodeNumberPattern: Regex =
|
val failedEpisodeNumberPattern: Regex =
|
||||||
Regex(failedEpisodeNumberRegex, RegexOption.IGNORE_CASE)
|
Regex(failedEpisodeNumberRegex, RegexOption.IGNORE_CASE)
|
||||||
failedEpisodeNumberPattern.replace(removedNumber) { mr ->
|
failedEpisodeNumberPattern.replace(removedNumber) { mr ->
|
||||||
|
@ -67,5 +60,19 @@ class AnimeNameAdapter {
|
||||||
removedNumber
|
removedNumber
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun removeEpisodeNumberCompletely(text: String): String {
|
||||||
|
val regexPattern = Regex(episodeRegex, RegexOption.IGNORE_CASE)
|
||||||
|
val removedNumber = text.replace(regexPattern, "")
|
||||||
|
return if (removedNumber.equals(text, true)) { // if nothing was removed
|
||||||
|
val failedEpisodeNumberPattern: Regex =
|
||||||
|
Regex(failedEpisodeNumberRegex, RegexOption.IGNORE_CASE)
|
||||||
|
failedEpisodeNumberPattern.replace(removedNumber) { mr ->
|
||||||
|
mr.value.replaceFirst(mr.groupValues[1], "")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
removedNumber
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,10 +208,16 @@ class AnimeWatchFragment : Fragment() {
|
||||||
}
|
}
|
||||||
if (media.anime?.kitsuEpisodes != null) {
|
if (media.anime?.kitsuEpisodes != null) {
|
||||||
if (media.anime!!.kitsuEpisodes!!.containsKey(i)) {
|
if (media.anime!!.kitsuEpisodes!!.containsKey(i)) {
|
||||||
episode.desc = media.anime!!.kitsuEpisodes!![i]?.desc ?: episode.desc
|
episode.desc =
|
||||||
episode.title = media.anime!!.kitsuEpisodes!![i]?.title ?: episode.title
|
media.anime!!.kitsuEpisodes!![i]?.desc ?: episode.desc
|
||||||
episode.thumb = media.anime!!.kitsuEpisodes!![i]?.thumb
|
episode.title = if (AnimeNameAdapter.removeEpisodeNumberCompletely(
|
||||||
?: FileUrl[media.cover]
|
episode.title ?: ""
|
||||||
|
).isBlank()
|
||||||
|
) media.anime!!.kitsuEpisodes!![i]?.title
|
||||||
|
?: episode.title else episode.title
|
||||||
|
?: media.anime!!.kitsuEpisodes!![i]?.title ?: episode.title
|
||||||
|
episode.thumb = media.anime!!.kitsuEpisodes!![i]?.thumb
|
||||||
|
?: FileUrl[media.cover]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -542,7 +548,10 @@ class AnimeWatchFragment : Fragment() {
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
model.watchSources?.flushText()
|
model.watchSources?.flushText()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
requireContext().unregisterReceiver(downloadStatusReceiver)
|
try {
|
||||||
|
requireContext().unregisterReceiver(downloadStatusReceiver)
|
||||||
|
} catch (_: IllegalArgumentException) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var state: Parcelable? = null
|
var state: Parcelable? = null
|
||||||
|
|
|
@ -957,7 +957,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
|
||||||
episodes.forEach {
|
episodes.forEach {
|
||||||
val episode = it.value
|
val episode = it.value
|
||||||
val cleanedTitle = AnimeNameAdapter.removeEpisodeNumberCompletely(episode.title ?: "")
|
val cleanedTitle = AnimeNameAdapter.removeEpisodeNumberCompletely(episode.title ?: "")
|
||||||
episodeTitleArr.add("Episode ${episode.number}${if (episode.filler) " [Filler]" else ""}${if (cleanedTitle.isNotEmpty() && cleanedTitle != "null") ": $cleanedTitle" else ""}")
|
episodeTitleArr.add("Episode ${episode.number}${if (episode.filler) " [Filler]" else ""}${if (cleanedTitle.isNotBlank() && cleanedTitle != "null") ": $cleanedTitle" else ""}")
|
||||||
}
|
}
|
||||||
|
|
||||||
//Episode Change
|
//Episode Change
|
||||||
|
|
|
@ -6,26 +6,38 @@ import ani.dantotsu.logger
|
||||||
import ani.dantotsu.media.Media
|
import ani.dantotsu.media.Media
|
||||||
import ani.dantotsu.media.anime.Episode
|
import ani.dantotsu.media.anime.Episode
|
||||||
import ani.dantotsu.tryWithSuspend
|
import ani.dantotsu.tryWithSuspend
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.lagradost.nicehttp.NiceResponse
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import java.io.InputStreamReader
|
||||||
|
import java.util.zip.GZIPInputStream
|
||||||
|
|
||||||
object Kitsu {
|
object Kitsu {
|
||||||
private suspend fun getKitsuData(query: String): KitsuResponse? {
|
private suspend fun getKitsuData(query: String): KitsuResponse? {
|
||||||
val headers = mapOf(
|
val headers = mapOf(
|
||||||
"Content-Type" to "application/json",
|
"Content-Type" to "application/json",
|
||||||
"Accept" to "application/json",
|
"Accept" to "application/json",
|
||||||
|
"Accept-Encoding" to "gzip, deflate",
|
||||||
|
"Accept-Language" to "en-US,en;q=0.5",
|
||||||
|
"Host" to "kitsu.io",
|
||||||
"Connection" to "keep-alive",
|
"Connection" to "keep-alive",
|
||||||
"DNT" to "1",
|
"Origin" to "https://kitsu.io",
|
||||||
"Origin" to "https://kitsu.io"
|
"Sec-Fetch-Dest" to "empty",
|
||||||
|
"Sec-Fetch-Mode" to "cors",
|
||||||
|
"Sec-Fetch-Site" to "cross-site",
|
||||||
)
|
)
|
||||||
val json = tryWithSuspend {
|
val response = tryWithSuspend {
|
||||||
client.post(
|
val res = client.post(
|
||||||
"https://kitsu.io/api/graphql",
|
"https://kitsu.io/api/graphql",
|
||||||
headers,
|
headers,
|
||||||
data = mapOf("query" to query)
|
data = mapOf("query" to query)
|
||||||
)
|
)
|
||||||
|
res
|
||||||
}
|
}
|
||||||
return json?.parsed()
|
val json = decodeToString(response)
|
||||||
|
val gson = Gson()
|
||||||
|
return gson.fromJson(json, KitsuResponse::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getKitsuEpisodesDetails(media: Media): Map<String, Episode>? {
|
suspend fun getKitsuEpisodesDetails(media: Media): Map<String, Episode>? {
|
||||||
|
@ -54,14 +66,14 @@ query {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}"""
|
}""".trimIndent()
|
||||||
|
|
||||||
|
|
||||||
val result = getKitsuData(query) ?: return null
|
val result = getKitsuData(query) ?: return null
|
||||||
logger("Kitsu : result=$result", print)
|
logger("Kitsu : result=$result", print)
|
||||||
media.idKitsu = result.data?.lookupMapping?.id
|
media.idKitsu = result.data?.lookupMapping?.id
|
||||||
return (result.data?.lookupMapping?.episodes?.nodes ?: return null).mapNotNull { ep ->
|
val a = (result.data?.lookupMapping?.episodes?.nodes ?: return null).mapNotNull { ep ->
|
||||||
val num = ep?.num?.toString() ?: return@mapNotNull null
|
val num = ep?.number?.toString() ?: return@mapNotNull null
|
||||||
num to Episode(
|
num to Episode(
|
||||||
number = num,
|
number = num,
|
||||||
title = ep.titles?.canonical,
|
title = ep.titles?.canonical,
|
||||||
|
@ -69,6 +81,25 @@ query {
|
||||||
thumb = FileUrl[ep.thumbnail?.original?.url],
|
thumb = FileUrl[ep.thumbnail?.original?.url],
|
||||||
)
|
)
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
logger("Kitsu : a=$a", print)
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
fun decodeToString(res: NiceResponse?): String? {
|
||||||
|
return when (res?.headers?.get("Content-Encoding")) {
|
||||||
|
"gzip" -> {
|
||||||
|
res.body.byteStream()?.use { inputStream ->
|
||||||
|
GZIPInputStream(inputStream).use { gzipInputStream ->
|
||||||
|
InputStreamReader(gzipInputStream).use { reader ->
|
||||||
|
reader.readText()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
res?.body?.string()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -93,7 +124,7 @@ query {
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Node(
|
data class Node(
|
||||||
@SerialName("number") val num: Long? = null,
|
@SerialName("number") val number: Int? = null,
|
||||||
@SerialName("titles") val titles: Titles? = null,
|
@SerialName("titles") val titles: Titles? = null,
|
||||||
@SerialName("description") val description: Description? = null,
|
@SerialName("description") val description: Description? = null,
|
||||||
@SerialName("thumbnail") val thumbnail: Thumbnail? = null
|
@SerialName("thumbnail") val thumbnail: Thumbnail? = null
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue