fix shahid4u (#940)

This commit is contained in:
adly98
2022-10-17 08:15:22 +02:00
committed by GitHub
parent c20783a72c
commit 35687654cd
3 changed files with 38 additions and 35 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'شاهد فور يو'
pkgNameSuffix = 'ar.shahid4u'
extClass = '.Shahid4U'
extVersionCode = 6
extVersionCode = 7
libVersion = '13'
}

View File

@ -206,19 +206,25 @@ class Shahid4U : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
private fun videosFromElement(document: Document): List<Video> {
val videoList = mutableListOf<Video>()
val scriptSelect = document.select("script:containsData(eval)").first().data()
val serverPrefix = scriptSelect.substringAfter("|net|cdn|amzn|").substringBefore("|rewind|icon|")
val sourceServer = "https://$serverPrefix.e-amzn-cdn.net"
val qualities = scriptSelect.substringAfter("|image|").substringBefore("|sources|").replace("||", "|").split("|")
qualities.forEachIndexed { i, q ->
if (i % 2 == 0) {
val id = qualities[i + 1]
val src = "$sourceServer/$id/v.mp4"
val video = Video(src, "Main: $q", src)
videoList.add(video)
return try {
val scriptSelect = document.select("script:containsData(eval)").first().data()
val serverPrefix =
scriptSelect.substringAfter("|net|cdn|amzn|").substringBefore("|rewind|icon|")
val sourceServer = "https://$serverPrefix.e-amzn-cdn.net"
val qualities = scriptSelect.substringAfter("|image|").substringBefore("|sources|")
.replace("||", "|").split("|")
qualities.forEachIndexed { i, q ->
if (i % 2 == 0) {
val id = qualities[i + 1]
val src = "$sourceServer/$id/v.mp4"
val video = Video(src, "Main: $q", src)
videoList.add(video)
}
}
videoList
} catch (e: Exception) {
videoList
}
return videoList
}
override fun List<Video>.sort(): List<Video> {
@ -276,6 +282,7 @@ class Shahid4U : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
return GET(catUrl, headers)
}
}
else -> {}
}
}
return GET(url, headers)

View File

@ -4,40 +4,36 @@ import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.OkHttpClient
import java.lang.Exception
class OkruExtractor(private val client: OkHttpClient) {
fun videosFromUrl(url: String): List<Video> {
val document = client.newCall(GET(url)).execute().asJsoup()
if (document == null) {
throw Exception("Not used")
} else {
val videoList = mutableListOf<Video>()
val qualityMap = mapOf(
"Okru: mobile" to "Okru: 140p",
"Okru: lowest" to "Okru: 240p",
"Okru: low" to "Okru: 360p",
"Okru: sd" to "Okru: 480p",
"Okru: hd" to "Okru: 720p",
"Okru: fhd" to "Okru: 1080p"
fun videosFromUrl(url: String, qualityPrefix: String = ""): List<Video> {
val videoList = mutableListOf<Video>()
return try {
val document = client.newCall(GET(url)).execute().asJsoup()
val qualities = listOf(
Pair("full", "1080p"),
Pair("hd", "720p"),
Pair("sd", "480p"),
Pair("low", "360p"),
Pair("lowest", "240p"),
Pair("mobile", "144p")
)
val videosString = document.select("div[data-options]").attr("data-options")
.substringAfter("\\\"videos\\\":[{\\\"name\\\":\\\"")
.substringBefore("]")
videosString.split("{\\\"name\\\":\\\"").reversed().forEach { it1 ->
val videoUrl = it1.substringAfter("url\\\":\\\"")
videosString.split("{\\\"name\\\":\\\"").reversed().forEach {
val videoUrl = it.substringAfter("url\\\":\\\"")
.substringBefore("\\\"")
.replace("\\\\u0026", "&")
val videoQuality = "Okru: " + it1.substringBefore("\\\"")
val quality = try { qualities.find { q -> q.first == it.substringBefore("\\\"") }?.second } catch (e: Exception) { it.substringBefore("\\\"") }
val videoQuality = qualityPrefix + "Okru:" + quality
if (videoUrl.startsWith("https://")) {
val video = qualityMap[videoQuality]?.let { Video(videoUrl, it, videoUrl) }
if (video != null)
videoList.add(video)
else
videoList.add(Video(videoUrl, videoQuality, videoUrl))
videoList.add(Video(videoUrl, videoQuality, videoUrl, headers = null))
}
}
return videoList
videoList
} catch (e: Exception) {
videoList
}
}
}