mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-29 13:00:17 +02:00
feat: custom path format
This commit is contained in:
parent
cc94ea93b2
commit
0d3bffb05b
@ -212,6 +212,10 @@
|
||||
"logging": {
|
||||
"name": "Logging",
|
||||
"description": "Shows toasts when media is downloading"
|
||||
},
|
||||
"custom_path_format": {
|
||||
"name": "Custom Path Format",
|
||||
"description": "Specify a custom path format for downloaded media\n\nAvailable variables:\n - %username%\n - %source%\n - %hash%\n - %date_time%"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -48,4 +48,5 @@ class DownloaderConfig : ConfigContainer() {
|
||||
val logging = multiple("logging", "started", "success", "progress", "failure").apply {
|
||||
set(mutableListOf("success", "progress", "failure"))
|
||||
}
|
||||
val customPathFormat = string("custom_path_format") { addNotices(FeatureNotice.UNSTABLE) }
|
||||
}
|
@ -44,8 +44,8 @@ fun createNewFilePath(
|
||||
creationTimestamp: Long?
|
||||
): String {
|
||||
val pathFormat by config.downloader.pathFormat
|
||||
val customPathFormat by config.downloader.customPathFormat
|
||||
val sanitizedMediaAuthor = mediaAuthor.sanitizeForPath().ifEmpty { hexHash }
|
||||
|
||||
val currentDateTime = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH).format(creationTimestamp ?: System.currentTimeMillis())
|
||||
|
||||
val finalPath = StringBuilder()
|
||||
@ -58,26 +58,35 @@ fun createNewFilePath(
|
||||
}
|
||||
}
|
||||
|
||||
if (pathFormat.contains("create_author_folder")) {
|
||||
finalPath.append(sanitizedMediaAuthor).append("/")
|
||||
}
|
||||
if (pathFormat.contains("create_source_folder")) {
|
||||
finalPath.append(downloadSource.pathName).append("/")
|
||||
}
|
||||
if (pathFormat.contains("append_hash")) {
|
||||
appendFileName(hexHash)
|
||||
}
|
||||
if (pathFormat.contains("append_source")) {
|
||||
appendFileName(downloadSource.pathName)
|
||||
}
|
||||
if (pathFormat.contains("append_username")) {
|
||||
appendFileName(sanitizedMediaAuthor)
|
||||
}
|
||||
if (pathFormat.contains("append_date_time")) {
|
||||
appendFileName(currentDateTime)
|
||||
if (customPathFormat.isNotEmpty()) {
|
||||
finalPath.append(customPathFormat
|
||||
.replace("%username%", sanitizedMediaAuthor)
|
||||
.replace("%source%", downloadSource.pathName)
|
||||
.replace("%hash%", hexHash)
|
||||
.replace("%date_time%", currentDateTime)
|
||||
)
|
||||
} else {
|
||||
if (pathFormat.contains("create_author_folder")) {
|
||||
finalPath.append(sanitizedMediaAuthor).append("/")
|
||||
}
|
||||
if (pathFormat.contains("create_source_folder")) {
|
||||
finalPath.append(downloadSource.pathName).append("/")
|
||||
}
|
||||
if (pathFormat.contains("append_hash")) {
|
||||
appendFileName(hexHash)
|
||||
}
|
||||
if (pathFormat.contains("append_source")) {
|
||||
appendFileName(downloadSource.pathName)
|
||||
}
|
||||
if (pathFormat.contains("append_username")) {
|
||||
appendFileName(sanitizedMediaAuthor)
|
||||
}
|
||||
if (pathFormat.contains("append_date_time")) {
|
||||
appendFileName(currentDateTime)
|
||||
}
|
||||
}
|
||||
|
||||
if (finalPath.isEmpty()) finalPath.append(hexHash)
|
||||
if (finalPath.isEmpty() || finalPath.isBlank()) finalPath.append(hexHash)
|
||||
|
||||
return finalPath.toString()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user