From 4e71792e27106c0f2e750abf7a6546b31ac72a05 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 8 Mar 2025 12:21:24 +0100 Subject: [PATCH] fix: playlist download service crashes for video titles with invalid file name characters --- .../services/PlaylistDownloadEnqueueService.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/services/PlaylistDownloadEnqueueService.kt b/app/src/main/java/com/github/libretube/services/PlaylistDownloadEnqueueService.kt index d14177ff6..388fa2985 100644 --- a/app/src/main/java/com/github/libretube/services/PlaylistDownloadEnqueueService.kt +++ b/app/src/main/java/com/github/libretube/services/PlaylistDownloadEnqueueService.kt @@ -23,6 +23,7 @@ import com.github.libretube.extensions.toID import com.github.libretube.extensions.toastFromMainDispatcher import com.github.libretube.helpers.DownloadHelper import com.github.libretube.parcelable.DownloadData +import com.github.libretube.util.TextUtils import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -142,9 +143,16 @@ class PlaylistDownloadEnqueueService : LifecycleService() { val videoStream = getStream(videoInfo.videoStreams, maxVideoQuality) val audioStream = getStream(videoInfo.audioStreams, maxAudioQuality) + // remove all UNIX reserved characters from the title in order to generate + // a valid filename + var fileName = videoInfo.title + TextUtils.RESERVED_CHARS.forEach { + fileName = fileName.replace(it, '_') + } + val downloadData = DownloadData( videoId = stream.url!!.toID(), - fileName = videoInfo.title, + fileName = fileName, videoFormat = videoStream?.format, videoQuality = videoStream?.quality, audioFormat = audioStream?.format,