Fixes and improvement

This commit is contained in:
contusionglory 2022-12-24 10:14:14 +00:00 committed by GitHub
parent 008a7040d5
commit 041f8aa7a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,24 +9,22 @@ import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.Qualities import com.lagradost.cloudstream3.utils.Qualities
import okhttp3.MediaType.Companion.toMediaType import com.lagradost.nicehttp.RequestBodyTypes
import okhttp3.OkHttpClient import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.RequestBody.Companion.toRequestBody
class SkillShareProvider : MainAPI() { // all providers must be an instance of MainAPI class SkillShareProvider : MainAPI() { // all providers must be an instance of MainAPI
override var mainUrl = "https://www.skillshare.com" override var mainUrl = "https://www.skillshare.com"
override var name = "SkillShare" override var name = "SkillShare"
val apiUrl = "https://www.skillshare.com/api/graphql" private val apiUrl = "https://www.skillshare.com/api/graphql"
val bypassApiUrl = "https://skillshare-api.heckernohecking.repl.co" private val bypassApiUrl = "https://skillshare-api.heckernohecking.repl.co"
override val supportedTypes = setOf(TvType.TvSeries) override val supportedTypes = setOf(TvType.TvSeries)
override val hasChromecastSupport = true override val hasChromecastSupport = true
override var lang = "en" override var lang = "en"
override val hasMainPage = true override val hasMainPage = true
val client = OkHttpClient() private var cursor = mutableMapOf("SIX_MONTHS_ENGAGEMENT" to "", "ML_TRENDINESS" to "")
var cursor = ""
override val mainPage = override val mainPage =
mainPageOf( mainPageOf(
@ -34,24 +32,22 @@ class SkillShareProvider : MainAPI() { // all providers must be an instance of M
"ML_TRENDINESS" to "Trending Classes", "ML_TRENDINESS" to "Trending Classes",
) )
private suspend fun queryMovieApi(payload: String): String {
val req = payload.toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull())
return app.post(apiUrl, requestBody = req, referer = "$mainUrl/").text
}
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
val sortAttribute = request.data val sortAttribute = request.data
val payload = val payload =
"""{ "query": "query GetClassesByType(${'$'}filter: ClassFilters!, ${'$'}pageSize: Int, ${'$'}cursor: String, ${'$'}type: ClassListType!, ${'$'}sortAttribute: ClassListByTypeSortAttribute) { classListByType(type: ${'$'}type, where: ${'$'}filter, first: ${'$'}pageSize, after: ${'$'}cursor, sortAttribute: ${'$'}sortAttribute) { nodes { id title url sku smallCoverUrl largeCoverUrl studentCount durationInSeconds __typename } } }", "variables": { "type": "TRENDING_CLASSES", "filter": { "subCategory": "", "classLength": [] }, "pageSize": 30, "cursor": "$cursor", "sortAttribute": "$sortAttribute" }, "operationName": "GetClassesByType" }""" """{ "query": "query GetClassesByType(${'$'}filter: ClassFilters!, ${'$'}pageSize: Int, ${'$'}cursor: String, ${'$'}type: ClassListType!, ${'$'}sortAttribute: ClassListByTypeSortAttribute) { classListByType(type: ${'$'}type, where: ${'$'}filter, first: ${'$'}pageSize, after: ${'$'}cursor, sortAttribute: ${'$'}sortAttribute) { nodes { id title url sku smallCoverUrl largeCoverUrl } } }", "variables": { "type": "TRENDING_CLASSES", "filter": { "subCategory": "", "classLength": [] }, "pageSize": 30, "cursor": "${cursor[sortAttribute]}", "sortAttribute": "$sortAttribute" }, "operationName": "GetClassesByType" }"""
val body = payload.toRequestBody("application/json".toMediaType()) val responseBody = queryMovieApi(payload)
val r = Request.Builder()
.url(apiUrl)
.post(body)
.build()
val response = client.newCall(r).execute()
val responseBody = response.body.string()
val parsedJson = parseJson<ApiData>(responseBody).data!!.classListByType!!.nodes val parsedJson = parseJson<ApiData>(responseBody).data!!.classListByType!!.nodes
val home = parsedJson.map { val home = parsedJson.map {
it.toSearchResult() it.toSearchResult()
} }
home.let { home.let {
cursor = cursor[sortAttribute] =
parsedJson.last().id.toString() parsedJson.last().id.toString()
} }
return newHomePageResponse( return newHomePageResponse(
@ -63,13 +59,7 @@ class SkillShareProvider : MainAPI() { // all providers must be an instance of M
override suspend fun search(query: String): List<SearchResponse> { override suspend fun search(query: String): List<SearchResponse> {
val payload = val payload =
"""{"query":"fragment ClassFields on Class {\n id\n\tsmallCoverUrl\n largeCoverUrl\n sku\n title\n url\n}\n\nquery GetClassesQuery(${"$"}query: String!, ${"$"}where: SearchFilters!, ${"$"}after: String!, ${"$"}first: Int!) {\n search(query: ${"$"}query, where: ${"$"}where, analyticsTags: [\"src:browser\", \"src:browser:search\"], after: ${"$"}after, first: ${"$"}first) {\n edges {\n node {\n ...ClassFields\n }\n }\n }\n}\n","variables":{"query":"$query","where":{"level":["ALL_LEVELS","BEGINNER","INTERMEDIATE","ADVANCED"]},"after":"-1","first":30},"operationName":"GetClassesQuery"}""" """{"query":"fragment ClassFields on Class {\n id\n\tsmallCoverUrl\n largeCoverUrl\n sku\n title\n url\n}\n\nquery GetClassesQuery(${"$"}query: String!, ${"$"}where: SearchFilters!, ${"$"}after: String!, ${"$"}first: Int!) {\n search(query: ${"$"}query, where: ${"$"}where, analyticsTags: [\"src:browser\", \"src:browser:search\"], after: ${"$"}after, first: ${"$"}first) {\n edges {\n node {\n ...ClassFields\n }\n }\n }\n}\n","variables":{"query":"$query","where":{"level":["ALL_LEVELS","BEGINNER","INTERMEDIATE","ADVANCED"]},"after":"-1","first":30},"operationName":"GetClassesQuery"}"""
val body = payload.toRequestBody("application/json".toMediaType()) val responseBody = queryMovieApi(payload)
val r = Request.Builder()
.url(apiUrl)
.post(body)
.build()
val response = client.newCall(r).execute()
val responseBody = response.body.string()
val home = parseJson<SearchApiData>(responseBody).data!!.search!!.edges.map { val home = parseJson<SearchApiData>(responseBody).data!!.search!!.edges.map {
it.node!!.toSearchResult() it.node!!.toSearchResult()
} }
@ -99,7 +89,7 @@ class SkillShareProvider : MainAPI() { // all providers must be an instance of M
.parsedSafe<BypassApiData>() ?: throw ErrorLoadingException("Invalid Json Response") .parsedSafe<BypassApiData>() ?: throw ErrorLoadingException("Invalid Json Response")
val title = data.title ?: "" val title = data.title ?: ""
val poster = data.largeCoverUrl val poster = data.largeCoverUrl
val episodeList = document.lessons.mapIndexed() { index, episode -> val episodeList = document.lessons.mapIndexed { index, episode ->
Episode(episode.url ?: "", episode.title, 1, index) Episode(episode.url ?: "", episode.title, 1, index)
} }
@ -120,7 +110,7 @@ class SkillShareProvider : MainAPI() { // all providers must be an instance of M
name, name,
data, data,
isM3u8 = false, isM3u8 = false,
referer = mainUrl, referer = "$mainUrl/",
quality = Qualities.Unknown.value quality = Qualities.Unknown.value
) )
) )