From f1d93b6840883922f1c1d5bd57cd7f1b7d811a34 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 25 Sep 2024 14:33:13 +0200 Subject: [PATCH] fix: uncaught local streams extractor exceptions --- .../com/github/libretube/services/DownloadService.kt | 4 +++- .../com/github/libretube/ui/dialogs/DownloadDialog.kt | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index 50387151f..4827d5f6b 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -387,7 +387,9 @@ class DownloadService : LifecycleService() { * Regenerate stream url using available info format and quality. */ private suspend fun regenerateLink(item: DownloadItem) { - val streams = StreamsExtractor.extractStreams(item.videoId) + val streams = runCatching { + StreamsExtractor.extractStreams(item.videoId) + }.getOrNull() ?: return val stream = when (item.type) { FileType.AUDIO -> streams.audioStreams FileType.VIDEO -> streams.videoStreams diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt index 540a7604f..570f260c6 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt @@ -85,14 +85,17 @@ class DownloadDialog : DialogFragment() { StreamsExtractor.extractStreams(videoId) } } catch (e: IOException) { - println(e) - Log.e(TAG(), "IOException, you might not have internet connection") + Log.e(TAG(), e.stackTraceToString()) Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show() return@launch } catch (e: HttpException) { - Log.e(TAG(), "HttpException, unexpected response") + Log.e(TAG(), e.stackTraceToString()) Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show() return@launch + } catch (e: Exception) { + Log.e(TAG(), e.stackTraceToString()) + Toast.makeText(context, e.localizedMessage, Toast.LENGTH_SHORT).show() + return@launch } initDownloadOptions(binding, response) }