From 296ca42a196620f7ca7c201969b5bb2e53084a28 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 31 Jan 2023 16:35:00 +0100 Subject: [PATCH] Fix playlist importing issues --- .../com/github/libretube/api/PlaylistsHelper.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 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 f4e2cabc9..e5e5db44f 100644 --- a/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt +++ b/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt @@ -157,8 +157,9 @@ object PlaylistsHelper { suspend fun importPlaylists(playlists: List) = withContext(Dispatchers.IO) { playlists.map { playlist -> + val playlistId = createPlaylist(playlist.name!!, null) async { - val playlistId = createPlaylist(playlist.name!!, null) ?: return@async + playlistId ?: return@async // if logged in, add the playlists by their ID via an api call if (loggedIn) { addToPlaylist( @@ -171,8 +172,17 @@ object PlaylistsHelper { // if not logged in, all video information needs to become fetched manually runCatching { val streamItems = playlist.videos.map { - async { RetrofitInstance.api.getStreams(it).toStreamItem(it) } - }.awaitAll() + async { + try { + RetrofitInstance.api.getStreams(it).toStreamItem(it) + } catch (e: Exception) { + null + } + } + } + .awaitAll() + .filterNotNull() + addToPlaylist(playlistId, *streamItems.toTypedArray()) } }