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.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
@ -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<ExtractorLink>()
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))
}
}
fun LoadResponse.addTrailer(newTrailers: List<ExtractorLink>) {
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
val trailers = trailerUrls.apmap { trailerUrl ->
val trailers = trailerUrls.filter { it.isNotBlank() }.apmap { trailerUrl ->
val links = arrayListOf<ExtractorLink>()
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
}
}.map { (links, subs) -> TrailerData(links, subs) }
this.trailers.addAll(trailers)
}

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

View file

@ -172,7 +172,7 @@ class SuperStream : MainAPI() {
}
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 {
@ -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

View file

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