92e6c4fe1e
Extends DownloadSettings with 4 additional options: - Name: File name pattern for downloaded files (existed) - Disabled: Disables downloads - Originals: Only download files stored in "originals" folder - MediaRaw: Include RAW image files - MediaSidecar: Include metadata sidecar files (JSON, XMP, YAML)
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package clean
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// spaced returns the string padded with a space left and right.
|
|
func spaced(s string) string {
|
|
return Space + s + Space
|
|
}
|
|
|
|
// replace performs a case-insensitive string replacement.
|
|
func replace(subject string, search string, replace string) string {
|
|
return regexp.MustCompile("(?i)"+search).ReplaceAllString(subject, replace)
|
|
}
|
|
|
|
// SearchString replaces search operator with default symbols.
|
|
func SearchString(s string) string {
|
|
if s == "" || reject(s, MaxLength) {
|
|
return Empty
|
|
}
|
|
|
|
// Normalize.
|
|
s = strings.ReplaceAll(s, "%%", "%")
|
|
s = strings.ReplaceAll(s, "%", "*")
|
|
s = strings.ReplaceAll(s, "**", "*")
|
|
|
|
// Trim.
|
|
return strings.Trim(s, "|\\<>\n\r\t")
|
|
}
|
|
|
|
// SearchQuery replaces search operator with default symbols.
|
|
func SearchQuery(s string) string {
|
|
if s == "" || reject(s, MaxLength) {
|
|
return Empty
|
|
}
|
|
|
|
// Normalize.
|
|
s = replace(s, spaced(EnOr), Or)
|
|
s = replace(s, spaced(EnOr), Or)
|
|
s = replace(s, spaced(EnAnd), And)
|
|
s = replace(s, spaced(EnWith), And)
|
|
s = replace(s, spaced(EnIn), And)
|
|
s = replace(s, spaced(EnAt), And)
|
|
s = strings.ReplaceAll(s, SpacedPlus, And)
|
|
s = strings.ReplaceAll(s, "%%", "%")
|
|
s = strings.ReplaceAll(s, "%", "*")
|
|
s = strings.ReplaceAll(s, "**", "*")
|
|
|
|
// Trim.
|
|
return strings.Trim(s, "|${}\\<>: \n\r\t")
|
|
}
|