small trailer fix

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

View file

@ -1977,8 +1977,9 @@ class ResultViewModel2 : ViewModel() {
limit: Int = 0
): List<ExtractedTrailerData> =
coroutineScope {
var currentCount = 0
return@coroutineScope loadResponse.trailers.amap { trailerData ->
val returnlist = ArrayList<ExtractedTrailerData>()
loadResponse.trailers.windowed(limit, limit, true).takeWhile { list ->
list.amap { trailerData ->
try {
val links = arrayListOf<ExtractorLink>()
val subs = arrayListOf<SubtitleFile>()
@ -2000,19 +2001,18 @@ class ResultViewModel2 : ViewModel() {
) to arrayListOf()
} else {
links to subs
}.also { (extractor, _) ->
if (extractor.isNotEmpty() && limit != 0) {
currentCount++
if (currentCount >= limit) {
cancel()
}
}
}
} catch (e: Throwable) {
logError(e)
null
}
}.filterNotNull().map { (links, subs) -> ExtractedTrailerData(links, subs) }
}.filterNotNull().map { (links, subs) -> ExtractedTrailerData(links, subs) }.let {
returnlist.addAll(it)
}
returnlist.size < limit
}
return@coroutineScope returnlist
}