From ade0732ee6b3b4ccf4682eaef2bcaf1e5b448172 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 7 Dec 2024 20:29:14 +0100 Subject: [PATCH] refactor: directly add loaded videos to playlist to improve UX --- .../java/com/github/libretube/api/PlaylistsHelper.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt b/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt index 5fe00f3f6..0672ac2b2 100644 --- a/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt +++ b/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt @@ -184,16 +184,15 @@ object PlaylistsHelper { } else { // if not logged in, all video information needs to become fetched manually // Only do so with `MAX_CONCURRENT_IMPORT_CALLS` videos at once to prevent performance issues - val streams = playlist.videos.chunked( - MAX_CONCURRENT_IMPORT_CALLS - ).map { videos -> - videos.parallelMap { + for (videoIdList in playlist.videos.chunked(MAX_CONCURRENT_IMPORT_CALLS)) { + val streams = videoIdList.parallelMap { runCatching { StreamsExtractor.extractStreams(it) } .getOrNull() ?.toStreamItem(it) }.filterNotNull() - }.flatten() - addToPlaylist(playlistId, *streams.toTypedArray()) + + addToPlaylist(playlistId, *streams.toTypedArray()) + } } } }