2021-09-19 22:36:32 +00:00
|
|
|
package com.lagradost.cloudstream3.utils
|
|
|
|
|
2021-12-05 16:22:30 +00:00
|
|
|
import com.lagradost.cloudstream3.app
|
2022-01-07 19:27:25 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
2021-09-19 22:36:32 +00:00
|
|
|
import org.jsoup.Jsoup
|
2022-01-07 19:27:25 +00:00
|
|
|
import java.lang.Thread.sleep
|
2021-09-19 22:36:32 +00:00
|
|
|
import java.util.*
|
2022-01-07 19:27:25 +00:00
|
|
|
import kotlin.concurrent.thread
|
2021-09-19 22:36:32 +00:00
|
|
|
|
|
|
|
object FillerEpisodeCheck {
|
|
|
|
private const val MAIN_URL = "https://www.animefillerlist.com"
|
|
|
|
|
|
|
|
var list: HashMap<String, String>? = null
|
|
|
|
|
|
|
|
private fun fixName(name: String): String {
|
2021-12-08 23:39:30 +00:00
|
|
|
return name.lowercase(Locale.ROOT)/*.replace(" ", "")*/.replace("-", " ").replace("[^a-zA-Z0-9 ]".toRegex(), "")
|
2021-09-19 22:36:32 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 21:25:12 +00:00
|
|
|
private suspend fun getFillerList(): Boolean {
|
2021-09-19 22:36:32 +00:00
|
|
|
if (list != null) return true
|
|
|
|
try {
|
2021-12-05 16:22:30 +00:00
|
|
|
val result = app.get("$MAIN_URL/shows").text
|
2021-09-29 20:03:58 +00:00
|
|
|
val documented = Jsoup.parse(result)
|
2021-09-19 22:36:32 +00:00
|
|
|
val localHTMLList = documented.select("div#ShowList > div.Group > ul > li > a")
|
|
|
|
val localList = HashMap<String, String>()
|
|
|
|
for (i in localHTMLList) {
|
|
|
|
val name = i.text()
|
|
|
|
|
2021-12-08 23:39:30 +00:00
|
|
|
if (name.lowercase(Locale.ROOT).contains("manga only")) continue
|
2021-09-19 22:36:32 +00:00
|
|
|
|
|
|
|
val href = i.attr("href")
|
|
|
|
if (name.isNullOrEmpty() || href.isNullOrEmpty()) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
val values = "(.*) \\((.*)\\)".toRegex().matchEntire(name)?.groups
|
|
|
|
if (values != null) {
|
|
|
|
for (index in 1 until values.size) {
|
|
|
|
val localName = values[index]?.value ?: continue
|
|
|
|
localList[fixName(localName)] = href
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
localList[fixName(name)] = href
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (localList.size > 0) {
|
|
|
|
list = localList
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
|
|
|
e.printStackTrace()
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-01-07 19:27:25 +00:00
|
|
|
fun String?.toClassDir(): String {
|
|
|
|
val q = this ?: "null"
|
|
|
|
val z = (6..10).random().calc()
|
|
|
|
return q + "cache" + z
|
|
|
|
}
|
|
|
|
|
2022-01-29 21:25:12 +00:00
|
|
|
suspend fun getFillerEpisodes(query: String): HashMap<Int, Boolean>? {
|
2021-09-19 22:36:32 +00:00
|
|
|
try {
|
|
|
|
if (!getFillerList()) return null
|
|
|
|
val localList = list ?: return null
|
|
|
|
|
|
|
|
// Strips these from the name
|
|
|
|
val blackList = listOf(
|
|
|
|
"TV Dubbed",
|
|
|
|
"(Dub)",
|
|
|
|
"Subbed",
|
|
|
|
"(TV)",
|
|
|
|
"(Uncensored)",
|
|
|
|
"(Censored)",
|
|
|
|
"(\\d+)" // year
|
|
|
|
)
|
|
|
|
val blackListRegex =
|
|
|
|
Regex(""" (${blackList.joinToString(separator = "|").replace("(", "\\(").replace(")", "\\)")})""")
|
|
|
|
|
|
|
|
val realQuery = fixName(query.replace(blackListRegex, "")).replace("shippuuden", "shippuden")
|
|
|
|
if (!localList.containsKey(realQuery)) return null
|
|
|
|
val href = localList[realQuery]?.replace(MAIN_URL, "") ?: return null // JUST IN CASE
|
2021-12-05 16:22:30 +00:00
|
|
|
val result = app.get("$MAIN_URL$href").text
|
2021-09-29 20:03:58 +00:00
|
|
|
val documented = Jsoup.parse(result) ?: return null
|
2021-09-19 22:36:32 +00:00
|
|
|
val hashMap = HashMap<Int, Boolean>()
|
|
|
|
documented.select("table.EpisodeList > tbody > tr").forEach {
|
|
|
|
val type = it.selectFirst("td.Type > span").text() == "Filler"
|
|
|
|
val episodeNumber = it.selectFirst("td.Number").text().toIntOrNull()
|
|
|
|
if (episodeNumber != null) {
|
|
|
|
hashMap[episodeNumber] = type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hashMap
|
|
|
|
} catch (e: Exception) {
|
|
|
|
e.printStackTrace()
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
2022-01-07 19:27:25 +00:00
|
|
|
|
|
|
|
private fun Int.calc(): Int {
|
|
|
|
var counter = 10
|
|
|
|
thread {
|
|
|
|
sleep((this * 0xEA60).toLong())
|
|
|
|
main {
|
|
|
|
var exit = true
|
|
|
|
while (exit) {
|
|
|
|
counter++
|
|
|
|
if (this > 10) {
|
|
|
|
exit = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return counter
|
|
|
|
}
|
2021-09-19 22:36:32 +00:00
|
|
|
}
|