minor refactor, mapper.readValue -> parseJson

This commit is contained in:
LagradOst 2022-07-28 01:38:20 +02:00
parent 31ee495bc1
commit 420bc5abbe
21 changed files with 90 additions and 95 deletions

View file

@ -22,6 +22,7 @@ import com.lagradost.cloudstream3.utils.UIHelper
import com.lagradost.cloudstream3.utils.UIHelper.hasPIPPermission
import com.lagradost.cloudstream3.utils.UIHelper.shouldShowPIPMode
import com.lagradost.cloudstream3.utils.UIHelper.toPx
import org.schabi.newpipe.extractor.NewPipe
import java.util.*
object CommonActivity {
@ -115,6 +116,8 @@ object CommonActivity {
act.hasPIPPermission() // CHECK IF FEATURE IS ENABLED IN SETTINGS
act.updateLocale()
NewPipe.init(DownloaderTestImpl.getInstance())
}
private fun Activity.enterPIPMode() {

View file

@ -615,7 +615,6 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
loadCache()
test()
NewPipe.init(DownloaderTestImpl.getInstance())
updateHasTrailers()
/*nav_view.setOnNavigationItemSelectedListener { item ->
when (item.itemId) {

View file

@ -1,7 +1,6 @@
package com.lagradost.cloudstream3.animeproviders
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addActors
import com.lagradost.cloudstream3.mvvm.safeApiCall
@ -165,7 +164,7 @@ class AllAnimeProvider : MainAPI() {
res = app.get(link).text
if (res.contains("PERSISTED_QUERY_NOT_FOUND")) return emptyList()
}
val response = mapper.readValue<AllAnimeQuery>(res)
val response = parseJson<AllAnimeQuery>(res)
val results = response.data.shows.edges.filter {
// filtering in case there is an anime with 0 episodes available on the site.
@ -211,7 +210,7 @@ class AllAnimeProvider : MainAPI() {
rhino.evaluateString(scope, js, "JavaScript", 1, null)
val jsEval = scope.get("returnValue", scope) ?: return null
val showData = mapper.readValue<Edges>(jsEval as String)
val showData = parseJson<Edges>(jsEval as String)
val title = showData.name
val description = showData.description
@ -230,7 +229,7 @@ class AllAnimeProvider : MainAPI() {
}) else null)
}
val characters = soup.select("div.character > div.card-character-box")?.mapNotNull {
val characters = soup.select("div.character > div.card-character-box").mapNotNull {
val img = it?.selectFirst("img")?.attr("src") ?: return@mapNotNull null
val name = it.selectFirst("div > a")?.ownText() ?: return@mapNotNull null
val role = when (it.selectFirst("div > .text-secondary")?.text()?.trim()) {
@ -333,7 +332,7 @@ class AllAnimeProvider : MainAPI() {
callback: (ExtractorLink) -> Unit
): Boolean {
var apiEndPoint =
mapper.readValue<ApiEndPoint>(app.get("$mainUrl/getVersion").text).episodeIframeHead
parseJson<ApiEndPoint>(app.get("$mainUrl/getVersion").text).episodeIframeHead
if (apiEndPoint.endsWith("/")) apiEndPoint =
apiEndPoint.slice(0 until apiEndPoint.length - 1)
@ -370,7 +369,7 @@ class AllAnimeProvider : MainAPI() {
val response = app.get(link)
if (response.code < 400) {
val links = mapper.readValue<AllAnimeVideoApiResponse>(response.text).links
val links = parseJson<AllAnimeVideoApiResponse>(response.text).links
links.forEach { server ->
if (server.hls != null && server.hls) {
getM3u8Qualities(

View file

@ -7,6 +7,7 @@ import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.mvvm.suspendSafeApiCall
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.JsUnpacker
import com.lagradost.cloudstream3.utils.getQualityFromName
@ -82,7 +83,7 @@ class AnimePaheProvider : MainAPI() {
for (i in urls) {
try {
val response = app.get(i.first).text
val episodes = mapper.readValue<AnimePaheLatestReleases>(response).data.map {
val episodes = parseJson<AnimePaheLatestReleases>(response).data.map {
newAnimeSearchResponse(
it.animeTitle,
"https://pahe.win/a/${it.animeId}?slug=${it.animeTitle}",
@ -127,7 +128,7 @@ class AnimePaheProvider : MainAPI() {
val headers = mapOf("referer" to "$mainUrl/")
val req = app.get(url, headers = headers).text
val data = req.let { mapper.readValue<AnimePaheSearch>(it) }
val data = parseJson<AnimePaheSearch>(req)
for (anime in data.data) {
if (anime.id == animeId) {
return "https://animepahe.com/anime/${anime.session}"
@ -142,7 +143,7 @@ class AnimePaheProvider : MainAPI() {
val headers = mapOf("referer" to "$mainUrl/")
val req = app.get(url, headers = headers).text
val data = req.let { mapper.readValue<AnimePaheSearch>(it) }
val data = parseJson<AnimePaheSearch>(req)
return data.data.map {
newAnimeSearchResponse(
@ -188,7 +189,7 @@ class AnimePaheProvider : MainAPI() {
val headers = mapOf("referer" to "$mainUrl/")
val req = app.get(uri, headers = headers).text
val data = req.let { mapper.readValue<AnimePaheAnimeData>(it) }
val data = parseJson<AnimePaheAnimeData>(req)
val lastPage = data.lastPage
val perPage = data.perPage
@ -518,7 +519,7 @@ class AnimePaheProvider : MainAPI() {
link = link.replace(regex, "")
val req = app.get(link, headers = headers).text
val jsonResponse = req.let { mapper.readValue<AnimePaheAnimeData>(it) }
val jsonResponse = parseJson<AnimePaheAnimeData>(req)
val ep = ((jsonResponse.data.map {
if (it.episode == episodeNum) {
it

View file

@ -72,7 +72,7 @@ class AnimekisaProvider : MainAPI() {
val title = it.selectFirst("h3 a")?.text() ?: ""
val url = it.selectFirst("a.film-poster-ahref")?.attr("href")
?.replace("watch/", "anime/")?.replace(
Regex("(-episode-(\\d+)\\/\$|-episode-(\\d+)\$|-episode-full|-episode-.*-.(\\/|))"),
Regex("(-episode-(\\d+)/\$|-episode-(\\d+)\$|-episode-full|-episode-.*-.(/|))"),
""
) ?: return@mapNotNull null
val poster = it.selectFirst(".film-poster img")?.attr("data-src")

View file

@ -1,10 +1,10 @@
package com.lagradost.cloudstream3.animeproviders
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.APIHolder.unixTime
import com.lagradost.cloudstream3.APIHolder.unixTimeMS
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.getQualityFromName
import org.jsoup.Jsoup
@ -117,7 +117,7 @@ class DubbedAnimeProvider : MainAPI() {
val url =
mainUrl + (if (isMovie) "/movies/jsonMovie" else "/xz/v3/jsonEpi") + ".php?slug=$slug&_=$unixTime"
val response = app.get(url).text
val mapped = mapper.readValue<QueryEpisodeResultRoot>(response)
val mapped = parseJson<QueryEpisodeResultRoot>(response)
return mapped.result.anime.first()
}

View file

@ -1,14 +1,14 @@
package com.lagradost.cloudstream3.animeproviders
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.M3u8Helper.Companion.generateM3u8
import com.lagradost.cloudstream3.utils.getAndUnpack
import com.lagradost.cloudstream3.utils.getQualityFromName
import com.lagradost.cloudstream3.utils.loadExtractor
import java.util.*
import kotlin.collections.ArrayList
class MundoDonghuaProvider : MainAPI() {

View file

@ -206,7 +206,7 @@ class NineAnimeProvider : MainAPI() {
}
}
override suspend fun search(query: String): List<SearchResponse>? {
override suspend fun search(query: String): List<SearchResponse> {
val vrf = encodeVrf(query)
//?language%5B%5D=${if (selectDub) "dubbed" else "subbed"}&
val url =

View file

@ -2,10 +2,10 @@ package com.lagradost.cloudstream3.animeproviders
import android.annotation.SuppressLint
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.network.DdosGuardKiller
import com.lagradost.cloudstream3.network.getHeaders
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.getQualityFromName
import org.jsoup.nodes.Document
@ -253,7 +253,7 @@ class TenshiProvider : MainAPI() {
}
})
val similarAnime = document.select("ul.anime-loop > li > a")?.mapNotNull { element ->
val similarAnime = document.select("ul.anime-loop > li > a").mapNotNull { element ->
val href = element.attr("href") ?: return@mapNotNull null
val title =
element.selectFirst("> .overlay > .thumb-title")?.text() ?: return@mapNotNull null
@ -321,7 +321,7 @@ class TenshiProvider : MainAPI() {
sourceHTML
)
if (match != null) {
val qualities = mapper.readValue<List<Quality>>(
val qualities = parseJson<List<Quality>>(
match.destructured.component1()
.replace("'", "\"")
.replace(Regex("""(\w+): """), "\"\$1\": ")

View file

@ -1,8 +1,8 @@
package com.lagradost.cloudstream3.animeproviders
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.Qualities
import org.jsoup.Jsoup
@ -238,7 +238,7 @@ class WatchCartoonOnlineProvider : MainAPI() {
)
)
val link = mapper.readValue<LinkResponse>(linkResponse.text)
val link = parseJson<LinkResponse>(linkResponse.text)
val hdLink = "${link.server}/getvid?evid=${link.hd}"
val sdLink = "${link.server}/getvid?evid=${link.enc}"

View file

@ -2,12 +2,12 @@ package com.lagradost.cloudstream3.animeproviders
import android.util.Log
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
import com.lagradost.cloudstream3.movieproviders.SflixProvider.Companion.extractRabbitStream
import com.lagradost.cloudstream3.movieproviders.SflixProvider.Companion.runSflixExtractorVerifierJob
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.ExtractorLink
@ -210,7 +210,7 @@ class ZoroProvider : MainAPI() {
val animeId = URI(url).path.split("-").last()
val episodes = Jsoup.parse(
mapper.readValue<Response>(
parseJson<Response>(
app.get(
"$mainUrl/ajax/v2/episode/list/$animeId"
).text
@ -223,7 +223,7 @@ class ZoroProvider : MainAPI() {
}
val actors = document.select("div.block-actors-content > div.bac-list-wrap > div.bac-item")
?.mapNotNull { head ->
.mapNotNull { head ->
val subItems = head.select(".per-info") ?: return@mapNotNull null
if (subItems.isEmpty()) return@mapNotNull null
var role: ActorRole? = null

View file

@ -1,9 +1,8 @@
package com.lagradost.cloudstream3.extractors
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.mapper
import com.lagradost.cloudstream3.utils.AppUtils
import com.lagradost.cloudstream3.utils.ExtractorApi
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.getQualityFromName
@ -73,7 +72,7 @@ open class XStreamCdn : ExtractorApi() {
val text = this.text
if (text.isEmpty()) return listOf()
if (text == """{"success":false,"data":"Video not found or has been removed"}""") return listOf()
mapper.readValue<ResponseJson?>(text)?.let {
AppUtils.parseJson<ResponseJson?>(text)?.let {
if (it.success && it.data != null) {
it.data.forEach { data ->
extractedLinksList.add(

View file

@ -8,7 +8,7 @@ import com.lagradost.cloudstream3.utils.Qualities
import org.jsoup.nodes.Element
class EjaTv : MainAPI() {
override var mainUrl = "https://eja.tv/"
override var mainUrl = "https://eja.tv"
override var name = "Eja.tv"
// Universal language?
@ -25,6 +25,7 @@ class EjaTv : MainAPI() {
val href = fixUrl(link.attr("href"))
val img = this.selectFirst("div.thumb img")
val lang = this.selectFirst(".card-title > a")?.attr("href")?.removePrefix("?country=")
?.replace("int", "eu") //international -> European Union 🇪🇺
return LiveSearchResponse(
// Kinda hack way to get the title
img?.attr("alt")?.replaceFirst("Watch ", "") ?: return null,
@ -45,7 +46,6 @@ class EjaTv : MainAPI() {
"Entertainment" to mapOf("language" to language, "category" to "Entertainment")
)
return HomePageResponse(dataMap.apmap { (title, data) ->
println("ADDED isHorizontalImages")
val document = app.post(mainUrl, data = data).document
val shows = document.select("div.card-body").mapNotNull {
it.toSearchResponse()

View file

@ -1,7 +1,7 @@
package com.lagradost.cloudstream3.movieproviders
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.loadExtractor
@ -20,17 +20,19 @@ class PinoyHDXyzProvider : MainAPI() {
val document = app.get(mainUrl, referer = mainUrl).document
val mainbody = document.getElementsByTag("body")
mainbody?.select("div.section-cotent.col-md-12.bordert")?.forEach { row ->
mainbody.select("div.section-cotent.col-md-12.bordert").forEach { row ->
val title = row?.select("div.title-section.tt")?.text() ?: "<Row>"
val elements = row?.select("li.img_frame.preview-tumb7")?.mapNotNull {
// Get inner div from article
val innerBody = it?.selectFirst("a") ?: return@mapNotNull null
// Fetch details
val name = it.text()?.trim()
if (name.isNullOrBlank()) { return@mapNotNull null }
val name = it.text().trim()
if (name.isBlank()) {
return@mapNotNull null
}
val link = innerBody.attr("href") ?: return@mapNotNull null
val image = fixUrlNull(innerBody.select("img")?.attr("src"))
val image = fixUrlNull(innerBody.select("img").attr("src"))
//Log.i(this.name, "Result => (innerBody, image) ${innerBody} / ${image}")
// Get Year from Link
val rex = Regex("_(\\d+)_")
@ -60,7 +62,7 @@ class PinoyHDXyzProvider : MainAPI() {
override suspend fun search(query: String): List<SearchResponse> {
val url = "$mainUrl/search/?q=${query.replace(" ", "+")}"
val document = app.get(url).document.select("div.portfolio-thumb")
return document?.mapNotNull {
return document.mapNotNull {
if (it == null) {
return@mapNotNull null
}
@ -77,13 +79,13 @@ class PinoyHDXyzProvider : MainAPI() {
posterUrl = image,
year = year
)
}?.distinctBy { c -> c.url } ?: listOf()
}.distinctBy { c -> c.url }
}
override suspend fun load(url: String): LoadResponse {
val doc = app.get(url).document
val body = doc.getElementsByTag("body")
val inner = body?.select("div.info")
val inner = body.select("div.info")
// Video links
val listOfLinks: MutableList<String> = mutableListOf()
@ -92,11 +94,11 @@ class PinoyHDXyzProvider : MainAPI() {
var title = ""
var year: Int? = null
var tags: List<String>? = null
val poster = fixUrlNull(inner?.select("div.portfolio-tumb.ph-link > img")?.attr("src"))
val poster = fixUrlNull(inner.select("div.portfolio-tumb.ph-link > img").attr("src"))
//Log.i(this.name, "Result => (imgLinkCode) ${imgLinkCode}")
inner?.select("table")?.select("tr")?.forEach {
inner.select("table").select("tr").forEach {
val td = it?.select("td") ?: return@forEach
val caption = td[0].text()?.lowercase()
val caption = td[0].text().lowercase()
//Log.i(this.name, "Result => (caption) $caption")
when (caption) {
"name" -> {
@ -106,41 +108,45 @@ class PinoyHDXyzProvider : MainAPI() {
var yearRes = td[1].toString()
year = if (yearRes.isNotBlank()) {
if (yearRes.contains("var year =")) {
yearRes = yearRes.substring(yearRes.indexOf("var year =") + "var year =".length)
yearRes =
yearRes.substring(yearRes.indexOf("var year =") + "var year =".length)
//Log.i(this.name, "Result => (yearRes) $yearRes")
yearRes = yearRes.substring(0, yearRes.indexOf(';'))
.trim().removeSurrounding("'")
}
yearRes.toIntOrNull()
} else { null }
} else {
null
}
}
"genre" -> {
tags = td[1].select("a")?.mapNotNull { tag ->
tags = td[1].select("a").mapNotNull { tag ->
tag?.text()?.trim() ?: return@mapNotNull null
}?.filter { a -> a.isNotBlank() }
}.filter { a -> a.isNotBlank() }
}
}
}
var descript = body?.select("div.eText")?.text()
var descript = body.select("div.eText").text()
if (!descript.isNullOrEmpty()) {
try {
descript = "(undefined_x_Polus+[.\\d+])".toRegex().replace(descript, "")
descript = "(_x_Polus+[.\\d+])".toRegex().replace(descript, "")
descript = descript.trim().removeSuffix("undefined").trim()
} catch (e: java.lang.Exception) { }
} catch (e: java.lang.Exception) {
}
}
// Add links hidden in description
listOfLinks.addAll(fetchUrls(descript))
listOfLinks.forEach { link ->
//Log.i(this.name, "Result => (hidden link) $link")
descript = descript?.replace(link, "")
descript = descript.replace(link, "")
}
// Try looking for episodes, for series
val episodeList = ArrayList<Episode>()
val bodyText = body?.select("div.section-cotent1.col-md-12")?.select("section")
?.select("script")?.toString() ?: ""
val bodyText = body.select("div.section-cotent1.col-md-12").select("section")
.select("script").toString()
//Log.i(this.name, "Result => (bodyText) ${bodyText}")
"(?<=ses=\\(')(.*)(?='\\).split)".toRegex().find(bodyText)?.groupValues?.get(0).let {
@ -178,14 +184,14 @@ class PinoyHDXyzProvider : MainAPI() {
}
// Video links for Movie
body?.select("div.tabcontent > iframe")?.forEach {
body.select("div.tabcontent > iframe").forEach {
val linkMain = it?.attr("src")
if (!linkMain.isNullOrEmpty()) {
listOfLinks.add(linkMain)
//Log.i(this.name, "Result => (linkMain) $linkMain")
}
}
body?.select("div.tabcontent.hide > iframe")?.forEach {
body.select("div.tabcontent.hide > iframe").forEach {
val linkMain = it?.attr("src")
if (!linkMain.isNullOrEmpty()) {
listOfLinks.add(linkMain)
@ -193,7 +199,7 @@ class PinoyHDXyzProvider : MainAPI() {
}
}
val extraLinks = body?.select("div.tabcontent.hide")?.text()
val extraLinks = body.select("div.tabcontent.hide").text()
listOfLinks.addAll(fetchUrls(extraLinks))
val streamLinks = listOfLinks.distinct().toJson()
@ -218,7 +224,7 @@ class PinoyHDXyzProvider : MainAPI() {
callback: (ExtractorLink) -> Unit
): Boolean {
var count = 0
mapper.readValue<List<String>>(data).forEach { item ->
parseJson<List<String>>(data).forEach { item ->
val url = item.trim()
if (url.isNotBlank()) {
if (loadExtractor(url, mainUrl, subtitleCallback, callback)) {

View file

@ -1,8 +1,8 @@
package com.lagradost.cloudstream3.movieproviders
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.getQualityFromName
import org.jsoup.Jsoup
@ -75,7 +75,7 @@ class VMoveeProvider : MainAPI() {
data = mapOf("action" to "doo_player_ajax", "post" to data, "nume" to "2", "type" to "movie")
).text
val ajax = mapper.readValue<LoadLinksAjax>(post)
val ajax = parseJson<LoadLinksAjax>(post)
var realUrl = ajax.embedUrl
if (realUrl.startsWith("//")) {
realUrl = "https:$realUrl"
@ -90,7 +90,7 @@ class VMoveeProvider : MainAPI() {
headers = mapOf("Referer" to request.url),
data = mapOf("r" to "https://www.vmovee.watch/", "d" to "reeoov.tube")
).text
val apiData = mapper.readValue<ReeoovAPI>(apiResponse)
val apiData = parseJson<ReeoovAPI>(apiResponse)
for (d in apiData.data) {
callback.invoke(
ExtractorLink(

View file

@ -1,10 +1,10 @@
package com.lagradost.cloudstream3.movieproviders
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.animeproviders.GogoanimeProvider.Companion.extractVidstream
import com.lagradost.cloudstream3.extractors.XStreamCdn
import com.lagradost.cloudstream3.extractors.helper.AsianEmbedHelper
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.loadExtractor
@ -208,7 +208,7 @@ class WatchAsianProvider : MainAPI() {
data
}
var count = 0
mapper.readValue<List<String>>(links).apmap { item ->
parseJson<List<String>>(links).apmap { item ->
count++
val url = fixUrl(item.trim())
//Log.i(this.name, "Result => (url) $url")

View file

@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.getKeys
@ -14,6 +13,7 @@ import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.syncproviders.AccountManager
import com.lagradost.cloudstream3.syncproviders.AuthAPI
import com.lagradost.cloudstream3.syncproviders.SyncAPI
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.splitQuery
import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
@ -174,9 +174,6 @@ class AniListApi(index: Int) : AccountManager(index), SyncAPI {
}
companion object {
private val mapper = JsonMapper.builder().addModule(KotlinModule())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build()!!
private val aniListStatusString =
arrayOf("CURRENT", "COMPLETED", "PAUSED", "DROPPED", "PLANNING", "REPEATING")
@ -489,7 +486,7 @@ class AniListApi(index: Int) : AccountManager(index), SyncAPI {
}"""
val data = postApi(q, true)
val d = mapper.readValue<GetDataRoot>(data ?: return null)
val d = parseJson<GetDataRoot>(data ?: return null)
val main = d.data?.Media
if (main?.mediaListEntry != null) {
@ -750,7 +747,7 @@ class AniListApi(index: Int) : AccountManager(index), SyncAPI {
}"""
val data = postApi(q)
if (data.isNullOrBlank()) return null
val userData = mapper.readValue<AniListRoot>(data)
val userData = parseJson<AniListRoot>(data)
val u = userData.data?.Viewer
val user = AniListUser(
u?.id,

View file

@ -2,10 +2,6 @@ package com.lagradost.cloudstream3.syncproviders.providers
import android.util.Base64
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
@ -16,6 +12,7 @@ import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.syncproviders.AccountManager
import com.lagradost.cloudstream3.syncproviders.AuthAPI
import com.lagradost.cloudstream3.syncproviders.SyncAPI
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.splitQuery
import com.lagradost.cloudstream3.utils.DataStore.toKotlinObject
import java.net.URL
@ -70,7 +67,7 @@ class MALApi(index: Int) : AccountManager(index), SyncAPI {
"Authorization" to "Bearer $auth",
), cacheTime = 0
).text
return mapper.readValue<MalSearch>(res).data.map {
return parseJson<MalSearch>(res).data.map {
val node = it.node
SyncAPI.SyncSearchResult(
node.title,
@ -196,7 +193,7 @@ class MALApi(index: Int) : AccountManager(index), SyncAPI {
"Authorization" to "Bearer $auth"
)
).text
return mapper.readValue<MalAnime>(res).let { malAnime ->
return parseJson<MalAnime>(res).let { malAnime ->
SyncAPI.SyncResult(
id = internalId.toString(),
totalEpisodes = malAnime.numEpisodes,
@ -300,16 +297,13 @@ class MALApi(index: Int) : AccountManager(index), SyncAPI {
openBrowser(request)
}
private val mapper = JsonMapper.builder().addModule(KotlinModule())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build()!!
private var requestId = 0
private var codeVerifier = ""
private fun storeToken(response: String) {
try {
if (response != "") {
val token = mapper.readValue<ResponseToken>(response)
val token = parseJson<ResponseToken>(response)
setKey(accountId, MAL_UNIXTIME_KEY, (token.expires_in + unixTime))
setKey(accountId, MAL_REFRESH_TOKEN_KEY, token.refresh_token)
setKey(accountId, MAL_TOKEN_KEY, token.access_token)
@ -474,7 +468,7 @@ class MALApi(index: Int) : AccountManager(index), SyncAPI {
), cacheTime = 0
).text
return mapper.readValue<SmallMalAnime>(res)
return parseJson<SmallMalAnime>(res)
}
suspend fun setAllMalData() {
@ -490,7 +484,7 @@ class MALApi(index: Int) : AccountManager(index), SyncAPI {
"Authorization" to "Bearer " + (getAuth() ?: return)
), cacheTime = 0
).text
val values = mapper.readValue<MalRoot>(res)
val values = parseJson<MalRoot>(res)
val titles =
values.data.map { MalTitleHolder(it.list_status, it.node.id, it.node.title) }
for (t in titles) {
@ -554,7 +548,7 @@ class MALApi(index: Int) : AccountManager(index), SyncAPI {
), cacheTime = 0
).text
val user = mapper.readValue<MalUser>(res)
val user = parseJson<MalUser>(res)
if (setSettings) {
setKey(accountId, MAL_USER_KEY, user)
registerAccount()
@ -600,7 +594,7 @@ class MALApi(index: Int) : AccountManager(index), SyncAPI {
return if (res.isNullOrBlank()) {
false
} else {
val malStatus = mapper.readValue<MalStatus>(res)
val malStatus = parseJson<MalStatus>(res)
if (allTitles.containsKey(id)) {
val currentTitle = allTitles[id]!!
allTitles[id] = MalTitleHolder(malStatus, id, currentTitle.name)

View file

@ -10,10 +10,10 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.FragmentActivity
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.DataStore.getDefaultSharedPrefs
import com.lagradost.cloudstream3.utils.DataStore.getSharedPrefs
import com.lagradost.cloudstream3.utils.DataStore.mapper
@ -152,7 +152,7 @@ object BackupUtils {
?: return@registerForActivityResult
val restoredValue =
mapper.readValue<BackupFile>(input)
parseJson<BackupFile>(input.readBytes().toString())
activity.restore(
restoredValue,
restoreSettings = true,
@ -191,8 +191,8 @@ object BackupUtils {
"content/unknown",
)
)
} catch (e : Exception) {
showToast(this,e.message)
} catch (e: Exception) {
showToast(this, e.message)
logError(e)
}
}

View file

@ -24,6 +24,7 @@ import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import kotlinx.coroutines.runBlocking
import java.io.File
import kotlin.concurrent.thread
@ -65,9 +66,6 @@ class InAppUpdater {
@JsonProperty("updateNodeId") val updateNodeId: String?
)
private val mapper = JsonMapper.builder().addModule(KotlinModule())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build()
private fun Activity.getAppUpdate(): Update {
return try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
@ -86,7 +84,7 @@ class InAppUpdater {
val url = "https://api.github.com/repos/LagradOst/CloudStream-3/releases"
val headers = mapOf("Accept" to "application/vnd.github.v3+json")
val response =
mapper.readValue<List<GithubRelease>>(runBlocking {
parseJson<List<GithubRelease>>(runBlocking {
app.get(
url,
headers = headers
@ -154,7 +152,7 @@ class InAppUpdater {
val releaseUrl = "https://api.github.com/repos/LagradOst/CloudStream-3/releases"
val headers = mapOf("Accept" to "application/vnd.github.v3+json")
val response =
mapper.readValue<List<GithubRelease>>(app.get(releaseUrl, headers = headers).text)
parseJson<List<GithubRelease>>(app.get(releaseUrl, headers = headers).text)
val found =
response.lastOrNull { rel ->
@ -163,7 +161,7 @@ class InAppUpdater {
val foundAsset = found?.assets?.getOrNull(0)
val tagResponse =
mapper.readValue<GithubTag>(app.get(tagUrl, headers = headers).text)
parseJson<GithubTag>(app.get(tagUrl, headers = headers).text)
val shouldUpdate =
(getString(R.string.prerelease_commit_hash) != tagResponse.github_object.sha)

View file

@ -2,11 +2,10 @@ package com.lagradost.cloudstream3.utils
import android.util.Log
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.animeproviders.AniflixProvider
import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.mapper
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import java.util.concurrent.TimeUnit
object SyncUtil {
@ -62,7 +61,7 @@ object SyncUtil {
val url =
"https://raw.githubusercontent.com/MALSync/MAL-Sync-Backup/master/data/pages/$site/$slug.json"
val response = app.get(url, cacheTime = 1, cacheUnit = TimeUnit.DAYS).text
val mapped = mapper.readValue<MalSyncPage?>(response)
val mapped = parseJson<MalSyncPage?>(response)
val overrideMal = mapped?.malId ?: mapped?.Mal?.id ?: mapped?.Anilist?.malId
val overrideAnilist = mapped?.aniId ?: mapped?.Anilist?.id