small trailer fix

This commit is contained in:
reduplicated 2022-12-09 20:06:23 +01:00
parent 7c4f177e47
commit c11f0c101b

View file

@ -1977,42 +1977,42 @@ class ResultViewModel2 : ViewModel() {
limit: Int = 0 limit: Int = 0
): List<ExtractedTrailerData> = ): List<ExtractedTrailerData> =
coroutineScope { coroutineScope {
var currentCount = 0 val returnlist = ArrayList<ExtractedTrailerData>()
return@coroutineScope loadResponse.trailers.amap { trailerData -> loadResponse.trailers.windowed(limit, limit, true).takeWhile { list ->
try { list.amap { trailerData ->
val links = arrayListOf<ExtractorLink>() try {
val subs = arrayListOf<SubtitleFile>() val links = arrayListOf<ExtractorLink>()
if (!loadExtractor( val subs = arrayListOf<SubtitleFile>()
trailerData.extractorUrl, if (!loadExtractor(
trailerData.referer,
{ subs.add(it) },
{ links.add(it) }) && trailerData.raw
) {
arrayListOf(
ExtractorLink(
"",
"Trailer",
trailerData.extractorUrl, trailerData.extractorUrl,
trailerData.referer ?: "", trailerData.referer,
Qualities.Unknown.value, { subs.add(it) },
trailerData.extractorUrl.contains(".m3u8") { links.add(it) }) && trailerData.raw
) ) {
) to arrayListOf() arrayListOf(
} else { ExtractorLink(
links to subs "",
}.also { (extractor, _) -> "Trailer",
if (extractor.isNotEmpty() && limit != 0) { trailerData.extractorUrl,
currentCount++ trailerData.referer ?: "",
if (currentCount >= limit) { Qualities.Unknown.value,
cancel() trailerData.extractorUrl.contains(".m3u8")
} )
) to arrayListOf()
} else {
links to subs
} }
} catch (e: Throwable) {
logError(e)
null
} }
} catch (e: Throwable) { }.filterNotNull().map { (links, subs) -> ExtractedTrailerData(links, subs) }.let {
logError(e) returnlist.addAll(it)
null
} }
}.filterNotNull().map { (links, subs) -> ExtractedTrailerData(links, subs) }
returnlist.size < limit
}
return@coroutineScope returnlist
} }