From 213fc626c124fc1d122adbeca90bc00a1fa9b9c0 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 23 Aug 2024 16:23:38 +0200 Subject: [PATCH] fix: crashes and issues with local stream extractor --- .../main/java/com/github/libretube/api/StreamsExtractor.kt | 6 +++--- .../java/com/github/libretube/ui/models/PlayerViewModel.kt | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/StreamsExtractor.kt b/app/src/main/java/com/github/libretube/api/StreamsExtractor.kt index 047ede4ac..19090bbbe 100644 --- a/app/src/main/java/com/github/libretube/api/StreamsExtractor.kt +++ b/app/src/main/java/com/github/libretube/api/StreamsExtractor.kt @@ -30,7 +30,7 @@ object StreamsExtractor { val resp = StreamInfo.getInfo("https://www.youtube.com/watch?v=$videoId") return Streams( title = resp.name, - description = resp.description.toString(), + description = resp.description.content, uploader = resp.uploaderName, uploaderAvatar = resp.uploaderAvatars.maxBy { it.height }.url, uploaderUrl = resp.uploaderUrl.replace("https://www.youtube.com", ""), @@ -56,7 +56,7 @@ object StreamsExtractor { uploadTimestamp = resp.uploadDate.offsetDateTime().toInstant().toKotlinInstant(), uploaded = resp.uploadDate.offsetDateTime().toEpochSecond(), thumbnailUrl = resp.thumbnails.maxBy { it.height }.url, - relatedStreams = resp.relatedItems.map { it as StreamInfoItem }.map { + relatedStreams = resp.relatedItems.filterIsInstance().map { StreamItem( it.url.replace("https://www.youtube.com", ""), StreamItem.TYPE_STREAM, @@ -72,7 +72,7 @@ object StreamsExtractor { it.uploadDate?.offsetDateTime()?.toEpochSecond() ?: 0L, it.shortDescription, it.isShortFormContent, - ) + ) }, chapters = resp.streamSegments.map { ChapterSegment( diff --git a/app/src/main/java/com/github/libretube/ui/models/PlayerViewModel.kt b/app/src/main/java/com/github/libretube/ui/models/PlayerViewModel.kt index 42ea73ae8..899217bf3 100644 --- a/app/src/main/java/com/github/libretube/ui/models/PlayerViewModel.kt +++ b/app/src/main/java/com/github/libretube/ui/models/PlayerViewModel.kt @@ -62,6 +62,8 @@ class PlayerViewModel( JsonHelper.json.decodeFromString(this).message }?.getOrNull() ?: context.getString(R.string.server_error) return@withContext null to errorMessage + } catch (e: Exception) { + return@withContext null to e.message } return@withContext streamsInfo to null