Skip to content

Commit

Permalink
Add support for cloudflare streams
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Dec 19, 2020
1 parent 08bb46a commit 8192c49
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package me.proxer.app.anime.resolver

import android.net.Uri
import io.reactivex.Single
import me.proxer.app.MainApplication
import me.proxer.app.exception.StreamResolutionException
import me.proxer.app.util.extension.buildSingle
import me.proxer.app.util.extension.toBodySingle
import me.proxer.app.util.extension.toPrefixedUrlOrNull
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.Request

/**
* @author Ruben Gees
*/
object ProxerStreamCFResolver : StreamResolver() {

private val regex = Regex("<stream.*?src=\"(.*?)\".*?>")

override val name = "Proxer-Stream (CF)"

override fun resolve(id: String): Single<StreamResolutionResult> {
return api.anime.vastLink(id)
.buildSingle()
.flatMap { (link, adTag) ->
client
.newCall(
Request.Builder()
.get()
.url(link.toPrefixedUrlOrNull() ?: throw StreamResolutionException())
.header("User-Agent", MainApplication.USER_AGENT)
.header("Connection", "close")
.build()
)
.toBodySingle()
.map {
val regexResult = regex.find(it) ?: throw StreamResolutionException()

val streamId = regexResult.groupValues[1]
val url = "https://videodelivery.net/$streamId/manifest/video.mpd".toHttpUrlOrNull()
?: throw StreamResolutionException()

val adTagUri = if (adTag.isNotBlank()) Uri.parse(adTag) else null

StreamResolutionResult.Video(url, "application/dash+xml", adTag = adTagUri)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ object StreamResolverFactory {
private val resolvers = arrayOf(
AmazonPrimeVideoStreamResolver, AnimeOnDemandStreamResolver, MessageStreamResolver, CrunchyrollStreamResolver,
DailymotionStreamResolver, Mp4UploadStreamResolver, NetflixStreamResolver, ProsiebenMAXXStreamResolver,
ProxerStreamResolver, SteamStreamResolver, StreamcloudStreamResolver, YourUploadStreamResolver,
YouTubeStreamResolver
ProxerStreamResolver, ProxerStreamCFResolver, SteamStreamResolver, StreamcloudStreamResolver,
YourUploadStreamResolver, YouTubeStreamResolver
)

fun resolverFor(name: String) = resolvers.find { it.supports(name) }
Expand Down
22 changes: 14 additions & 8 deletions src/main/kotlin/me/proxer/app/anime/stream/StreamActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ import timber.log.Timber
@Suppress("DEPRECATION") // TODO: Wait for androidx fullscreen support library.
class StreamActivity : BaseActivity() {

companion object {
private const val PREVIEW_MIME_TYPE = "video/mp4"
}

internal val id: String
get() = intent.getSafeStringExtra(ID_EXTRA)

Expand Down Expand Up @@ -286,14 +290,16 @@ class StreamActivity : BaseActivity() {
.autoDisposable(this.scope())
.subscribe { toggleOrientation() }

PreviewLoader
.loadFrames(
progress.loadRequests(),
{ Size(preview.width, preview.height) },
PreviewLoader.PreviewMetaData(uri, referer, isProxerStream)
)
.autoDisposable(this.scope())
.subscribeAndLogErrors { preview.setImageBitmap(it) }
if (mimeType == PREVIEW_MIME_TYPE) {
PreviewLoader
.loadFrames(
progress.loadRequests(),
{ Size(preview.width, preview.height) },
PreviewLoader.PreviewMetaData(uri, referer, isProxerStream)
)
.autoDisposable(this.scope())
.subscribeAndLogErrors { preview.setImageBitmap(it) }
}

if (savedInstanceState == null) {
toggleOrientation()
Expand Down

0 comments on commit 8192c49

Please sign in to comment.