[Android] SubDownload: sanitize opensubs' filenames for URIs
Duncan McNamara
git at videolan.org
Thu Feb 13 09:37:09 UTC 2025
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Thu Feb 6 16:41:36 2025 +0100| [3c777988348e8eae368c52997e8816f430b168fa] | committer: Nicolas Pomepuy
SubDownload: sanitize opensubs' filenames for URIs
Some filenames from opensubtitles.org had characters not authorized for an
Android Uri. This sanitizes the filename so it can be used as dest in copyFile
Cf https://www.rfc-editor.org/rfc/rfc2396 #2.4.3 mentionned in the Uri.parse
method doc
> https://code.videolan.org/videolan/vlc-android/commit/3c777988348e8eae368c52997e8816f430b168fa
---
.../vlc-android/src/org/videolan/vlc/util/VLCDownloadManager.kt | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/application/vlc-android/src/org/videolan/vlc/util/VLCDownloadManager.kt b/application/vlc-android/src/org/videolan/vlc/util/VLCDownloadManager.kt
index 04c7f55622..457ef7628d 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/VLCDownloadManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/VLCDownloadManager.kt
@@ -84,6 +84,15 @@ object VLCDownloadManager: BroadcastReceiver(), DefaultLifecycleObserver {
private suspend fun downloadSuccessful(id:Long, subtitleItem: SubtitleItem, localUri: String, context: FragmentActivity) {
val extractDirectory = getFinalDirectory(context, subtitleItem) ?: return
+ // Some filenames from opensubtitles.org had characters not authorized for an Android Uri
+ // This sanitizes the filename so it can be used as dest in copyFile
+ // cf https://www.rfc-editor.org/rfc/rfc2396 #2.4.3 mentionned in the Uri.parse method doc
+ subtitleItem.fileName = subtitleItem.fileName
+ .replace("\"", "")
+ .replace("<", "")
+ .replace(">", "")
+ .replace("#", "")
+ .replace("%", "")
FileUtils.copyFile(localUri, "$extractDirectory/${subtitleItem.fileName}")?.let {dest ->
subtitleItem.run {
ExternalSubRepository.getInstance(context).removeDownloadingItem(id)
More information about the Android
mailing list