mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #2913 from Isira-Seneviratne/awaitAll
Use awaitAll() extension.
This commit is contained in:
commit
8c6d20d64d
@ -24,8 +24,9 @@ import java.io.IOException
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.withContext
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
|
|
||||||
object PlaylistsHelper {
|
object PlaylistsHelper {
|
||||||
@ -228,30 +229,16 @@ object PlaylistsHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun exportPlaylists(): List<ImportPlaylist> {
|
suspend fun exportPlaylists(): List<ImportPlaylist> = withContext(Dispatchers.IO) {
|
||||||
val playlists = getPlaylists()
|
getPlaylists()
|
||||||
val importLists = mutableListOf<ImportPlaylist>()
|
.map { async { getPlaylist(it.id!!) } }
|
||||||
runBlocking {
|
.awaitAll()
|
||||||
val tasks = playlists.map {
|
.map {
|
||||||
async {
|
val videos = it.relatedStreams.map { item ->
|
||||||
val list = getPlaylist(it.id!!)
|
"$YOUTUBE_FRONTEND_URL/watch?v=${item.url!!.toID()}"
|
||||||
importLists.add(
|
|
||||||
ImportPlaylist(
|
|
||||||
name = list.name,
|
|
||||||
type = "playlist",
|
|
||||||
visibility = "private",
|
|
||||||
videos = list.relatedStreams.map {
|
|
||||||
"$YOUTUBE_FRONTEND_URL/watch?v=${it.url!!.toID()}"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
ImportPlaylist(it.name, "playlist", "private", videos)
|
||||||
}
|
}
|
||||||
tasks.forEach {
|
|
||||||
it.await()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return importLists
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clonePlaylist(context: Context, playlistId: String) {
|
fun clonePlaylist(context: Context, playlistId: String) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user