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 13f9385d3..98b98229a 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 @@ -162,11 +162,17 @@ class DownloadDialog : DialogFragment() { restorePreviousSelections(binding, videoStreams, audioStreams, subtitles) onDownloadConfirm = onDownloadConfirm@{ - if (binding.fileName.text.toString().isEmpty()) { + val fileName = binding.fileName.text.toString() + if (fileName.isBlank()) { Toast.makeText(context, R.string.invalid_filename, Toast.LENGTH_SHORT).show() return@onDownloadConfirm } + if (fileName.length > MAX_FILE_NAME_LENGTH - 20) { // reserve 20 chars for quality and extension + Toast.makeText(context, R.string.filename_too_long, Toast.LENGTH_SHORT).show() + return@onDownloadConfirm + } + val videoPosition = binding.videoSpinner.selectedItemPosition - 1 val audioPosition = binding.audioSpinner.selectedItemPosition - 1 val subtitlePosition = binding.subtitleSpinner.selectedItemPosition - 1 @@ -269,6 +275,11 @@ class DownloadDialog : DialogFragment() { } companion object { + /** + * Max file name length at Android systems + */ + private const val MAX_FILE_NAME_LENGTH = 255 + private const val VIDEO_DOWNLOAD_QUALITY = "video_download_quality" private const val VIDEO_DOWNLOAD_FORMAT = "video_download_format" private const val AUDIO_DOWNLOAD_QUALITY = "audio_download_quality" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1f029f16e..f40e45db0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -472,6 +472,7 @@ Segment type Invalid segment start or end Contribute to SponsorBlock + Filename too long! Download Service