animepahe: add setting for alternative links

This commit is contained in:
jmir1
2021-11-19 01:28:08 +01:00
parent 8de9123438
commit 3d62148326
3 changed files with 43 additions and 5 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'AnimePahe'
pkgNameSuffix = 'en.animepahe'
extClass = '.AnimePahe'
extVersionCode = 8
extVersionCode = 9
libVersion = '12'
}

View File

@ -4,6 +4,7 @@ import android.app.Application
import android.content.SharedPreferences
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import com.google.gson.JsonElement
import com.google.gson.JsonNull
import com.google.gson.JsonObject
@ -217,16 +218,26 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
val quality = item.asJsonObject.keySet().first()
val adflyLink = item.asJsonObject.get(quality)
.asJsonObject.get("kwik_adfly").asString
val kwikLink = item.asJsonObject.get(quality)
.asJsonObject.get("kwik").asString
val audio = item.asJsonObject.get(quality).asJsonObject.get("audio")
val qualityString = if (audio is JsonNull) "${quality}p" else "${quality}p (" + audio.asString + " audio)"
videos.add(getVideo(adflyLink, qualityString))
videos.add(getVideo(adflyLink, kwikLink, qualityString))
}
return videos
}
private fun getVideo(adflyUrl: String, quality: String): Video {
val videoUrl = KwikExtractor(client).getStreamUrlFromKwik(adflyUrl)
return Video(videoUrl, quality, videoUrl, null)
private fun getVideo(adflyUrl: String, kwikUrl: String, quality: String): Video {
return if (preferences.getBoolean("preferred_link_type", false)) {
val videoUrl = KwikExtractor(client).getHlsStreamUrl(kwikUrl, referer = baseUrl)
Video(
videoUrl, quality, videoUrl, null,
Headers.headersOf("referer", "https://kwik.cx")
)
} else {
val videoUrl = KwikExtractor(client).getStreamUrlFromKwik(adflyUrl)
Video(videoUrl, quality, videoUrl, null)
}
}
override fun List<Video>.sort(): List<Video> {
@ -301,8 +312,21 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
preferences.edit().putString(key, entry).commit()
}
}
val linkPref = SwitchPreferenceCompat(screen.context).apply {
key = "preferred_link_type"
title = "Use HLS links"
summary = """Enable this if you are having Cloudflare issues.
|Note that this will break the ability to seek inside of the video unless the episode is downloaded in advance.""".trimMargin()
setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue ->
val new = newValue as Boolean
preferences.edit().putBoolean(key, new).commit()
}
}
screen.addPreference(videoQualityPref)
screen.addPreference(domainPref)
screen.addPreference(subPref)
screen.addPreference(linkPref)
}
}

View File

@ -27,6 +27,7 @@ SOFTWARE.
package eu.kanade.tachiyomi.animeextension.en.animepahe
import android.util.Log
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import okhttp3.FormBody
@ -113,6 +114,19 @@ class KwikExtractor(private val client: OkHttpClient) {
return newList
}
fun getHlsStreamUrl(kwikUrl: String, referer: String): String {
val eContent = client.newCall(GET(kwikUrl, Headers.headersOf("referer", referer)))
.execute().body!!.string()
val substring = eContent.substringAfterLast("m3u8|uwu|").substringBefore("'")
val urlParts = substring.split("|").reversed()
assert(urlParts.lastIndex == 8)
val url = urlParts[0] + "://" + urlParts[1] + "-" + urlParts[2] + "." + urlParts[3] + "." +
urlParts[4] + "." + urlParts[5] + "/" + urlParts[6] + "/" + urlParts[7] + "/" +
urlParts[8] + "/uwu.m3u8"
Log.i("bruh", url)
return url
}
fun getStreamUrlFromKwik(adflyUri: String): String {
val fContent =
client.newCall(GET(bypassAdfly(adflyUri), Headers.headersOf("referer", "https://kwik.cx/"))).execute()