DNS over HTTP

master
Swissky 2024-06-29 17:29:35 +02:00
parent 5563a4aa9d
commit 93a9ee910f
2 changed files with 55 additions and 0 deletions

View File

@ -2,6 +2,7 @@ dependencies {
implementation("androidx.legacy:legacy-support-v4:1.0.0")
implementation("com.google.android.material:material:1.4.0")
implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
}
// use an integer for version numbers
version = -1

View File

@ -6,6 +6,38 @@ import com.lagradost.cloudstream3.utils.ExtractorApi
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.M3u8Helper
import android.util.Log
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.decodeFromString
// Define data classes for the JSON structure
@Serializable
data class Question(
val name: String,
val type: Int
)
@Serializable
data class Answer(
val name: String,
val type: Int,
val TTL: Int,
val data: String
)
@Serializable
data class ApiResponse(
val Status: Int,
val TC: Boolean,
val RD: Boolean,
val RA: Boolean,
val AD: Boolean,
val CD: Boolean,
val Question: List<Question>,
val Answer: List<Answer>
)
class Upstream : ExtractorApi() {
override val name: String = "Upstream"
@ -19,6 +51,28 @@ class Upstream : ExtractorApi() {
callback: (ExtractorLink) -> Unit
) {
Log.d("mnemo", "Upstream extractor enabled")
// Bypass ISP blocking with DNS over HTTP to resolve the IP for upstream
// curl -H "accept: application/dns-json" "https://cloudflare-dns.com/dns-query?name=upstream.to&type=A" | jq -r '.Answer.[].data'
val dnsDoc = app.get(
"https://cloudflare-dns.com/dns-query?name=upstream.to&type=A",
headers = mapOf(
"x-accept" to "application/dns-json"
)
).text
// Parse JSON string to ApiResponse object
val apiResponse = Json.decodeFromString<ApiResponse>(dnsDoc)
// Extract the desired value
val ipAddress = apiResponse.Answer.firstOrNull()?.data
Log.d("mnemo", "IP ${ipAddress}") // 185.178.208.135
// curl https://185.178.208.135/embed-9qx7lhanoezn.html -k -H 'Host: upstream.to'
val doc = app.get(url, referer = referer).text
if (doc.isNotBlank()) {