diff --git a/src/main/kotlin/me/proxer/app/anime/resolver/ProxerStreamCFResolver.kt b/src/main/kotlin/me/proxer/app/anime/resolver/ProxerStreamCFResolver.kt new file mode 100644 index 00000000..85e54cd9 --- /dev/null +++ b/src/main/kotlin/me/proxer/app/anime/resolver/ProxerStreamCFResolver.kt @@ -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("") + + override val name = "Proxer-Stream (CF)" + + override fun resolve(id: String): Single { + 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) + } + } + } +} diff --git a/src/main/kotlin/me/proxer/app/anime/resolver/StreamResolverFactory.kt b/src/main/kotlin/me/proxer/app/anime/resolver/StreamResolverFactory.kt index a1374a2a..f3a0d905 100644 --- a/src/main/kotlin/me/proxer/app/anime/resolver/StreamResolverFactory.kt +++ b/src/main/kotlin/me/proxer/app/anime/resolver/StreamResolverFactory.kt @@ -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) } diff --git a/src/main/kotlin/me/proxer/app/anime/stream/StreamActivity.kt b/src/main/kotlin/me/proxer/app/anime/stream/StreamActivity.kt index 5591feba..e5c1fc9d 100644 --- a/src/main/kotlin/me/proxer/app/anime/stream/StreamActivity.kt +++ b/src/main/kotlin/me/proxer/app/anime/stream/StreamActivity.kt @@ -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) @@ -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()