mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Added ability to format directory names too
This commit is contained in:
parent
dafa2f4d70
commit
e9fdd8fd43
1 changed files with 15 additions and 18 deletions
|
|
@ -167,23 +167,7 @@ func terminalWidth() int {
|
||||||
return 60
|
return 60
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateFilename(name, directory string) string {
|
func generateFilename(name string) string {
|
||||||
if runtime.GOOS != "windows" {
|
|
||||||
for _, char := range invalidNotWindowsChars {
|
|
||||||
name = strings.ReplaceAll(name, char, "")
|
|
||||||
}
|
|
||||||
out.Debug("Replaced invalid characters (not windows)")
|
|
||||||
} else {
|
|
||||||
for _, char := range invalidWindowsChars {
|
|
||||||
name = strings.ReplaceAll(name, char, "")
|
|
||||||
}
|
|
||||||
out.Debug("Replaced invalid characters (windows)")
|
|
||||||
}
|
|
||||||
|
|
||||||
if directory != "" {
|
|
||||||
name = filepath.Join(directory, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
filename, changed := freeFileName(name)
|
filename, changed := freeFileName(name)
|
||||||
if changed {
|
if changed {
|
||||||
out.Info("File %s already exists, changing name to %s", name, filename)
|
out.Info("File %s already exists, changing name to %s", name, filename)
|
||||||
|
|
@ -292,7 +276,7 @@ type formatInformation struct {
|
||||||
Subtitle crunchyroll.LOCALE `json:"subtitle"`
|
Subtitle crunchyroll.LOCALE `json:"subtitle"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fi formatInformation) Format(source string) string {
|
func (fi formatInformation) Format(source string, removeInvalidChars bool) string {
|
||||||
fields := reflect.TypeOf(fi)
|
fields := reflect.TypeOf(fi)
|
||||||
values := reflect.ValueOf(fi)
|
values := reflect.ValueOf(fi)
|
||||||
|
|
||||||
|
|
@ -311,6 +295,19 @@ func (fi formatInformation) Format(source string) string {
|
||||||
valueAsString = "no " + valueAsString
|
valueAsString = "no " + valueAsString
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if removeInvalidChars {
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
for _, char := range invalidNotWindowsChars {
|
||||||
|
valueAsString = strings.ReplaceAll(valueAsString, char, "")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for _, char := range invalidWindowsChars {
|
||||||
|
valueAsString = strings.ReplaceAll(valueAsString, char, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
source = strings.ReplaceAll(source, "{"+fields.Field(i).Tag.Get("json")+"}", valueAsString)
|
source = strings.ReplaceAll(source, "{"+fields.Field(i).Tag.Get("json")+"}", valueAsString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue