Skip to content

Commit 4e71792

Browse files
committed
fix: playlist download service crashes for video titles with invalid file name characters
1 parent 2c0b43e commit 4e71792

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

app/src/main/java/com/github/libretube/services/PlaylistDownloadEnqueueService.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.github.libretube.extensions.toID
2323
import com.github.libretube.extensions.toastFromMainDispatcher
2424
import com.github.libretube.helpers.DownloadHelper
2525
import com.github.libretube.parcelable.DownloadData
26+
import com.github.libretube.util.TextUtils
2627
import kotlinx.coroutines.Dispatchers
2728
import kotlinx.coroutines.launch
2829

@@ -142,9 +143,16 @@ class PlaylistDownloadEnqueueService : LifecycleService() {
142143
val videoStream = getStream(videoInfo.videoStreams, maxVideoQuality)
143144
val audioStream = getStream(videoInfo.audioStreams, maxAudioQuality)
144145

146+
// remove all UNIX reserved characters from the title in order to generate
147+
// a valid filename
148+
var fileName = videoInfo.title
149+
TextUtils.RESERVED_CHARS.forEach {
150+
fileName = fileName.replace(it, '_')
151+
}
152+
145153
val downloadData = DownloadData(
146154
videoId = stream.url!!.toID(),
147-
fileName = videoInfo.title,
155+
fileName = fileName,
148156
videoFormat = videoStream?.format,
149157
videoQuality = videoStream?.quality,
150158
audioFormat = audioStream?.format,

0 commit comments

Comments
 (0)