From 3a2041c52f3acdff645ea10bbee41f9d6239e113 Mon Sep 17 00:00:00 2001 From: reduplicated <110570621+reduplicated@users.noreply.github.com> Date: Sat, 6 Aug 2022 17:16:04 +0200 Subject: [PATCH] added trailer to superstream --- .../com/lagradost/cloudstream3/MainAPI.kt | 67 ++++++++++++++++--- .../extractors/YoutubeExtractor.kt | 7 ++ .../movieproviders/SuperStream.kt | 4 +- .../cloudstream3/utils/ExtractorApi.kt | 2 + 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index 0259ef46..7832aa3b 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -21,6 +21,7 @@ import com.lagradost.cloudstream3.ui.player.SubtitleData import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.Qualities import com.lagradost.cloudstream3.utils.loadExtractor import okhttp3.Interceptor import java.text.SimpleDateFormat @@ -980,7 +981,7 @@ interface LoadResponse { private val aniListIdPrefix = aniListApi.idPrefix var isTrailersEnabled = true - fun LoadResponse.isMovie() : Boolean { + fun LoadResponse.isMovie(): Boolean { return this.type.isMovieType() } @@ -1025,25 +1026,71 @@ interface LoadResponse { } /**better to call addTrailer with mutible trailers directly instead of calling this multiple times*/ - suspend fun LoadResponse.addTrailer(trailerUrl: String?, referer: String? = null) { - if (!isTrailersEnabled || trailerUrl == null) return + suspend fun LoadResponse.addTrailer( + trailerUrl: String?, + referer: String? = null, + addRaw: Boolean = false + ) { + if (!isTrailersEnabled || trailerUrl.isNullOrBlank()) return val links = arrayListOf() val subs = arrayListOf() - loadExtractor(trailerUrl, referer, { subs.add(it) }, { links.add(it) }) - this.trailers.add(TrailerData(links, subs)) + if (!loadExtractor( + trailerUrl, + referer, + { subs.add(it) }, + { links.add(it) }) && addRaw + ) { + this.trailers.add( + TrailerData( + listOf( + ExtractorLink( + "", + "Trailer", + trailerUrl, + referer ?: "", + Qualities.Unknown.value, + trailerUrl.contains(".m3u8") + ) + ), listOf() + ) + ) + } else { + this.trailers.add(TrailerData(links, subs)) + } } fun LoadResponse.addTrailer(newTrailers: List) { trailers.addAll(newTrailers.map { TrailerData(listOf(it)) }) } - suspend fun LoadResponse.addTrailer(trailerUrls: List?, referer: String? = null) { + suspend fun LoadResponse.addTrailer( + trailerUrls: List?, + referer: String? = null, + addRaw: Boolean = false + ) { if (!isTrailersEnabled || trailerUrls == null) return - val trailers = trailerUrls.apmap { trailerUrl -> + val trailers = trailerUrls.filter { it.isNotBlank() }.apmap { trailerUrl -> val links = arrayListOf() val subs = arrayListOf() - loadExtractor(trailerUrl, referer, { subs.add(it) }, { links.add(it) }) - links to subs + if (!loadExtractor( + trailerUrl, + referer, + { subs.add(it) }, + { links.add(it) }) && addRaw + ) { + arrayListOf( + ExtractorLink( + "", + "Trailer", + trailerUrl, + referer ?: "", + Qualities.Unknown.value, + trailerUrl.contains(".m3u8") + ) + ) to arrayListOf() + } else { + links to subs + } }.map { (links, subs) -> TrailerData(links, subs) } this.trailers.addAll(trailers) } @@ -1124,7 +1171,7 @@ data class NextAiring( data class SeasonData( val season: Int, val name: String? = null, - val displaySeason : Int? = null, // will use season if null + val displaySeason: Int? = null, // will use season if null ) interface EpisodeResponse { diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/YoutubeExtractor.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/YoutubeExtractor.kt index 8148ca3e..23704e90 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/YoutubeExtractor.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/YoutubeExtractor.kt @@ -19,6 +19,13 @@ class YoutubeShortLinkExtractor : YoutubeExtractor() { } } +class YoutubeMobileExtractor : YoutubeExtractor() { + override val mainUrl = "https://m.youtube.com" +} +class YoutubeNoCookieExtractor : YoutubeExtractor() { + override val mainUrl = "https://www.youtube-nocookie.com" +} + open class YoutubeExtractor : ExtractorApi() { override val mainUrl = "https://www.youtube.com" override val requiresReferer = false diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SuperStream.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SuperStream.kt index b224dca1..8585fc57 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SuperStream.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SuperStream.kt @@ -172,7 +172,7 @@ class SuperStream : MainAPI() { } private suspend inline fun queryApiParsed(query: String): T { - return queryApi(query).also { println("queryApiParsed== ${it.text}") }.parsed() + return queryApi(query).parsed() } private fun getExpiryDate(): Long { @@ -530,7 +530,7 @@ class SuperStream : MainAPI() { } ) { this.recommendations = data.recommend.mapNotNull { it.toSearchResponse() } - + addTrailer(data.trailerUrl) this.year = data.year this.plot = data.description this.posterUrl = data.posterOrg ?: data.poster diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt index a1f1ae25..30e62c9c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt @@ -312,6 +312,8 @@ val extractorApis: Array = arrayOf( YoutubeExtractor(), YoutubeShortLinkExtractor(), + YoutubeMobileExtractor(), + YoutubeNoCookieExtractor(), Streamlare(), VidSrcExtractor(), VidSrcExtractor2(),