Start removing Outcome class in favor of Result

This commit is contained in:
vfsfitvnm
2022-07-01 18:22:53 +02:00
parent 6ccbf7759c
commit c4fea8835a
5 changed files with 155 additions and 157 deletions

View File

@@ -0,0 +1,35 @@
package it.vfsfitvnm.vimusic.utils
import androidx.media3.common.MediaItem
import it.vfsfitvnm.youtubemusic.YouTube
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
data class YouTubeRadio(
private val videoId: String? = null,
private val playlistId: String? = null,
private val playlistSetVideoId: String? = null,
private val parameters: String? = null
) {
private var nextContinuation: String? = null
suspend fun process(): List<MediaItem> {
var mediaItems: List<MediaItem>? = null
nextContinuation = withContext(Dispatchers.IO) {
YouTube.next(
videoId = videoId,
playlistId = playlistId,
params = parameters,
playlistSetVideoId = playlistSetVideoId,
continuation = nextContinuation
)?.getOrNull()?.let { nextResult ->
mediaItems = nextResult.items?.map(YouTube.Item.Song::asMediaItem)
nextResult.continuation?.takeUnless { nextContinuation == nextResult.continuation }
}
}
return mediaItems ?: emptyList()
}
}