quality stuff

This commit is contained in:
LagradOst 2022-04-18 20:49:17 +02:00
parent 96c074e87b
commit b942e066ee
3 changed files with 43 additions and 49 deletions

View file

@ -36,7 +36,7 @@ android {
targetSdkVersion 30
versionCode 45
versionName "2.9.19"
versionName "2.9.20"
resValue "string", "app_version",
"${defaultConfig.versionName}${versionNameSuffix ?: ""}"

View file

@ -799,7 +799,7 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogCustom)
builder.setTitle(title)
builder.setItems(links.map { it.name }.toTypedArray()) { dia, which ->
builder.setItems(links.map { "${it.name} ${Qualities.getStringByInt(it.quality)}" }.toTypedArray()) { dia, which ->
callback.invoke(links[which])
dia?.dismiss()
}

View file

@ -22,18 +22,18 @@ data class ExtractorLink(
) : VideoDownloadManager.IDownloadableMinimum
data class ExtractorUri(
val uri : Uri,
val name : String,
val uri: Uri,
val name: String,
val basePath: String? = null,
val relativePath: String? = null,
val displayName: String? = null,
val id : Int? = null,
val parentId : Int? = null,
val episode : Int? = null,
val season : Int? = null,
val headerName : String? = null,
val id: Int? = null,
val parentId: Int? = null,
val episode: Int? = null,
val season: Int? = null,
val headerName: String? = null,
val tvType: TvType? = null,
)
@ -45,44 +45,36 @@ data class ExtractorSubtitleLink(
) : VideoDownloadManager.IDownloadableMinimum
enum class Qualities(var value: Int) {
Unknown(0),
P360(-2), // 360p
P480(-1), // 480p
P720(1), // 720p
P1080(2), // 1080p
P1440(3), // 1440p
P2160(4); // 4k or 2160p
Unknown(400),
P144(144), // 144p
P240(240), // 240p
P360(360), // 360p
P480(480), // 480p
P720(720), // 720p
P1080(1080), // 1080p
P1440(1440), // 1440p
P2160(2160); // 4k or 2160p
companion object {
fun getStringByInt(qual: Int?) : String {
fun getStringByInt(qual: Int?): String {
return when (qual) {
P360.value -> "360p"
P480.value -> "480p"
P720.value -> "720p"
P1080.value -> "1080p"
P1440.value -> "1440p"
P2160.value -> "2160p/4k"
else -> ""
Unknown.value -> ""
P2160.value -> "4K"
else -> "${qual}p"
}
}
}
}
fun getQualityFromName(qualityName: String?): Int {
if (qualityName == null) {
if (qualityName == null)
return Qualities.Unknown.value
}
return when (qualityName.replace("p", "").replace("P", "").trim()) {
"360" -> Qualities.P360
"480" -> Qualities.P480
"720" -> Qualities.P720
"1080" -> Qualities.P1080
"1440" -> Qualities.P1440
"2160" -> Qualities.P2160
val match = qualityName.lowercase().replace("p", "").trim()
return when (match) {
"4k" -> Qualities.P2160
"4K" -> Qualities.P2160
else -> Qualities.Unknown
}.value
else -> null
}?.value ?: match.toIntOrNull() ?: Qualities.Unknown.value
}
private val packedRegex = Regex("""eval\(function\(p,a,c,k,e,.*\)\)""")
@ -98,7 +90,11 @@ fun getAndUnpack(string: String): String {
/**
* Tries to load the appropriate extractor based on link, returns true if any extractor is loaded.
* */
suspend fun loadExtractor(url: String, referer: String? = null, callback: (ExtractorLink) -> Unit) : Boolean {
suspend fun loadExtractor(
url: String,
referer: String? = null,
callback: (ExtractorLink) -> Unit
): Boolean {
for (extractor in extractorApis) {
if (url.startsWith(extractor.mainUrl)) {
extractor.getSafeUrl(url, referer)?.forEach(callback)
@ -192,7 +188,7 @@ fun httpsify(url: String): String {
return if (url.startsWith("//")) "https:$url" else url
}
suspend fun getPostForm(requestUrl : String, html : String) : String? {
suspend fun getPostForm(requestUrl: String, html: String): String? {
val document = Jsoup.parse(html)
val inputs = document.select("Form > input")
if (inputs.size < 4) return null
@ -216,7 +212,7 @@ suspend fun getPostForm(requestUrl : String, html : String) : String? {
}
delay(5000) // ye this is needed, wont work with 0 delay
val postResponse = app.post(
return app.post(
requestUrl,
headers = mapOf(
"content-type" to "application/x-www-form-urlencoded",
@ -226,8 +222,6 @@ suspend fun getPostForm(requestUrl : String, html : String) : String? {
),
data = mapOf("op" to op, "id" to id, "mode" to mode, "hash" to hash)
).text
return postResponse
}
abstract class ExtractorApi {