added trailer to superstream

This commit is contained in:
reduplicated 2022-08-06 17:16:04 +02:00
parent 52a656a234
commit 3a2041c52f
4 changed files with 68 additions and 12 deletions

View file

@ -21,6 +21,7 @@ import com.lagradost.cloudstream3.ui.player.SubtitleData
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.Qualities
import com.lagradost.cloudstream3.utils.loadExtractor import com.lagradost.cloudstream3.utils.loadExtractor
import okhttp3.Interceptor import okhttp3.Interceptor
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@ -980,7 +981,7 @@ interface LoadResponse {
private val aniListIdPrefix = aniListApi.idPrefix private val aniListIdPrefix = aniListApi.idPrefix
var isTrailersEnabled = true var isTrailersEnabled = true
fun LoadResponse.isMovie() : Boolean { fun LoadResponse.isMovie(): Boolean {
return this.type.isMovieType() return this.type.isMovieType()
} }
@ -1025,25 +1026,71 @@ interface LoadResponse {
} }
/**better to call addTrailer with mutible trailers directly instead of calling this multiple times*/ /**better to call addTrailer with mutible trailers directly instead of calling this multiple times*/
suspend fun LoadResponse.addTrailer(trailerUrl: String?, referer: String? = null) { suspend fun LoadResponse.addTrailer(
if (!isTrailersEnabled || trailerUrl == null) return trailerUrl: String?,
referer: String? = null,
addRaw: Boolean = false
) {
if (!isTrailersEnabled || trailerUrl.isNullOrBlank()) return
val links = arrayListOf<ExtractorLink>() val links = arrayListOf<ExtractorLink>()
val subs = arrayListOf<SubtitleFile>() val subs = arrayListOf<SubtitleFile>()
loadExtractor(trailerUrl, referer, { subs.add(it) }, { links.add(it) }) 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)) this.trailers.add(TrailerData(links, subs))
} }
}
fun LoadResponse.addTrailer(newTrailers: List<ExtractorLink>) { fun LoadResponse.addTrailer(newTrailers: List<ExtractorLink>) {
trailers.addAll(newTrailers.map { TrailerData(listOf(it)) }) trailers.addAll(newTrailers.map { TrailerData(listOf(it)) })
} }
suspend fun LoadResponse.addTrailer(trailerUrls: List<String>?, referer: String? = null) { suspend fun LoadResponse.addTrailer(
trailerUrls: List<String>?,
referer: String? = null,
addRaw: Boolean = false
) {
if (!isTrailersEnabled || trailerUrls == null) return if (!isTrailersEnabled || trailerUrls == null) return
val trailers = trailerUrls.apmap { trailerUrl -> val trailers = trailerUrls.filter { it.isNotBlank() }.apmap { trailerUrl ->
val links = arrayListOf<ExtractorLink>() val links = arrayListOf<ExtractorLink>()
val subs = arrayListOf<SubtitleFile>() val subs = arrayListOf<SubtitleFile>()
loadExtractor(trailerUrl, referer, { subs.add(it) }, { links.add(it) }) 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 links to subs
}
}.map { (links, subs) -> TrailerData(links, subs) } }.map { (links, subs) -> TrailerData(links, subs) }
this.trailers.addAll(trailers) this.trailers.addAll(trailers)
} }
@ -1124,7 +1171,7 @@ data class NextAiring(
data class SeasonData( data class SeasonData(
val season: Int, val season: Int,
val name: String? = null, val name: String? = null,
val displaySeason : Int? = null, // will use season if null val displaySeason: Int? = null, // will use season if null
) )
interface EpisodeResponse { interface EpisodeResponse {

View file

@ -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() { open class YoutubeExtractor : ExtractorApi() {
override val mainUrl = "https://www.youtube.com" override val mainUrl = "https://www.youtube.com"
override val requiresReferer = false override val requiresReferer = false

View file

@ -172,7 +172,7 @@ class SuperStream : MainAPI() {
} }
private suspend inline fun <reified T : Any> queryApiParsed(query: String): T { private suspend inline fun <reified T : Any> queryApiParsed(query: String): T {
return queryApi(query).also { println("queryApiParsed== ${it.text}") }.parsed() return queryApi(query).parsed()
} }
private fun getExpiryDate(): Long { private fun getExpiryDate(): Long {
@ -530,7 +530,7 @@ class SuperStream : MainAPI() {
} }
) { ) {
this.recommendations = data.recommend.mapNotNull { it.toSearchResponse() } this.recommendations = data.recommend.mapNotNull { it.toSearchResponse() }
addTrailer(data.trailerUrl)
this.year = data.year this.year = data.year
this.plot = data.description this.plot = data.description
this.posterUrl = data.posterOrg ?: data.poster this.posterUrl = data.posterOrg ?: data.poster

View file

@ -312,6 +312,8 @@ val extractorApis: Array<ExtractorApi> = arrayOf(
YoutubeExtractor(), YoutubeExtractor(),
YoutubeShortLinkExtractor(), YoutubeShortLinkExtractor(),
YoutubeMobileExtractor(),
YoutubeNoCookieExtractor(),
Streamlare(), Streamlare(),
VidSrcExtractor(), VidSrcExtractor(),
VidSrcExtractor2(), VidSrcExtractor2(),