Skip to content

Commit

Permalink
fix(en/fmovies): Fix vidsrc extractor + vrf helper (#2363)
Browse files Browse the repository at this point in the history
  • Loading branch information
Secozzi authored Oct 14, 2023
1 parent 05353c8 commit bcf55be
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/en/fmovies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext {
extName = 'FMovies'
pkgNameSuffix = 'en.fmovies'
extClass = '.FMovies'
extVersionCode = 10
extVersionCode = 11
libVersion = '13'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FMoviesHelper(private val client: OkHttpClient, private val headers: Heade

fun getVidSrc(query: String, host: String): String {
val url = API_URL.newBuilder().apply {
addPathSegment(if (host == "vidstream.pro") "rawVizcloud" else "rawMcloud")
addPathSegment(if (host.contains("mcloud", true)) "rawMcloud" else "rawVizcloud")
addQueryParameter("apikey", API_KEY)
}.build().toString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,64 @@ class VidsrcExtractor(private val client: OkHttpClient, private val headers: Hea
private val playlistUtils by lazy { PlaylistUtils(client, headers) }

fun videosFromUrl(url: String, name: String): List<Video> {
val host = when (name) {
"Vidplay" -> "vidstream.pro"
else -> "mcloud.to"
}
val httpUrl = url.toHttpUrl()
val host = httpUrl.host
val referer = "https://$host/"

val httpUrl = url.toHttpUrl()
val query = buildString {
append(httpUrl.pathSegments.last())
append("?")
append(
httpUrl.queryParameterNames.joinToString("&") {
"$it=${httpUrl.queryParameter(it)}"
},
)
}

val query = "${httpUrl.pathSegments.last()}?t=${httpUrl.queryParameter("t")!!}"
val rawUrl = vrfHelper.getVidSrc(query, host)
val rawUrl = vrfHelper.getVidSrc(query, host).addAutoStart()

val refererHeaders = headers.newBuilder().apply {
add("Referer", referer)
add("Accept", "application/json, text/javascript, */*; q=0.01")
add("Host", host)
add("Referer", url.addAutoStart())
add("X-Requested-With", "XMLHttpRequest")
}.build()

val infoJson = client.newCall(
GET(rawUrl, headers = refererHeaders),
).execute().parseAs<VidsrcResponse>()

val subtitleList = httpUrl.queryParameter("sub.info")?.let {
val subtitlesHeaders = headers.newBuilder().apply {
add("Accept", "application/json, text/javascript, */*; q=0.01")
add("Host", it.toHttpUrl().host)
add("Origin", "https://$host")
add("Referer", referer)
}.build()

client.newCall(
GET(it, headers = refererHeaders),
GET(it, headers = subtitlesHeaders),
).execute().parseAs<List<FMoviesSubs>>().map {
Track(it.file, it.label)
}
} ?: emptyList()

return infoJson.result.sources.distinctBy { it.file }.flatMap {
playlistUtils.extractFromHls(it.file, subtitleList = subtitleList, referer = referer, videoNameGen = { q -> "$name - $q" })
val url = it.file
.toHttpUrl()
.newBuilder()
.fragment(null)
.build()
.toString()

playlistUtils.extractFromHls(url, subtitleList = subtitleList, referer = referer, videoNameGen = { q -> "$name - $q" })
}
}

private fun String.addAutoStart(): String {
return this.toHttpUrl().newBuilder().setQueryParameter("autostart", "true").build().toString()
}

private inline fun <reified T> Response.parseAs(transform: (String) -> String = { it }): T {
val responseBody = use { transform(it.body.string()) }
return json.decodeFromString(responseBody)
Expand Down
2 changes: 1 addition & 1 deletion src/en/seez/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext {
extName = 'Seez'
pkgNameSuffix = 'en.seez'
extClass = '.Seez'
extVersionCode = 3
extVersionCode = 4
libVersion = '13'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class VrfHelper(private val client: OkHttpClient, private val headers: Headers)

fun getVidSrc(query: String, host: String): String {
val url = API_URL.newBuilder().apply {
addPathSegment("rawVizcloud")
addPathSegment(if (host.contains("mcloud", true)) "rawMcloud" else "rawVizcloud")
addQueryParameter("apikey", API_KEY)
}.build().toString()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,64 @@ class VidsrcExtractor(private val client: OkHttpClient, private val headers: Hea
private val playlistUtils by lazy { PlaylistUtils(client, headers) }

fun videosFromUrl(url: String, name: String): List<Video> {
val host = "vidstream.pro"

val httpUrl = url.toHttpUrl()
val host = httpUrl.host
val referer = "https://$host/"

val httpUrl = url.toHttpUrl()
val query = buildString {
append(httpUrl.pathSegments.last())
append("?")
append(
httpUrl.queryParameterNames.joinToString("&") {
"$it=${httpUrl.queryParameter(it)}"
},
)
}

val query = "${httpUrl.pathSegments.last()}?t=${httpUrl.queryParameter("t")!!}"
val rawUrl = vrfHelper.getVidSrc(query, host)
val rawUrl = vrfHelper.getVidSrc(query, host).addAutoStart()

val refererHeaders = headers.newBuilder().apply {
add("Referer", referer)
add("Accept", "application/json, text/javascript, */*; q=0.01")
add("Host", host)
add("Referer", url.addAutoStart())
add("X-Requested-With", "XMLHttpRequest")
}.build()

val infoJson = client.newCall(
GET(rawUrl, headers = refererHeaders),
).execute().parseAs<VidsrcResponse>()

val subtitleList = httpUrl.queryParameter("sub.info")?.let {
val subtitlesHeaders = headers.newBuilder().apply {
add("Accept", "application/json, text/javascript, */*; q=0.01")
add("Host", it.toHttpUrl().host)
add("Origin", "https://$host")
add("Referer", referer)
}.build()

client.newCall(
GET(it, headers = refererHeaders),
GET(it, headers = subtitlesHeaders),
).execute().parseAs<List<FMoviesSubs>>().map {
Track(it.file, it.label)
}
} ?: emptyList()

return infoJson.result.sources.distinctBy { it.file }.flatMap {
playlistUtils.extractFromHls(it.file, subtitleList = subtitleList, referer = referer, videoNameGen = { q -> "$name - $q" })
val url = it.file
.toHttpUrl()
.newBuilder()
.fragment(null)
.build()
.toString()

playlistUtils.extractFromHls(url, subtitleList = subtitleList, referer = referer, videoNameGen = { q -> "$name - $q" })
}
}

private fun String.addAutoStart(): String {
return this.toHttpUrl().newBuilder().setQueryParameter("autostart", "true").build().toString()
}

private inline fun <reified T> Response.parseAs(transform: (String) -> String = { it }): T {
val responseBody = use { transform(it.body.string()) }
return json.decodeFromString(responseBody)
Expand Down

0 comments on commit bcf55be

Please sign in to comment.