Remove characters not allowed in windows file names. #8

This commit is contained in:
Barold 2021-01-15 19:38:11 +02:00
parent 4ea1218cfb
commit dda23f4948
3 changed files with 18 additions and 4 deletions

View File

@ -71,12 +71,15 @@ func main() {
for _, issue := range issueList.Data { for _, issue := range issueList.Data {
issuePath := mydir + "/issue/" + strconv.Itoa(issue.Id) issuePath := mydir + "/issue/" + strconv.Itoa(issue.Id)
completeName := mydir + "/issue/" + issue.Publication.Name + " - " + issue.Name + ".pdf" publicationName := RemoveBadCharacters(issue.Publication.Name)
issueName := RemoveBadCharacters(issue.Name)
completeName := mydir + "/issue/" + publicationName + " - " + issueName + ".pdf"
if fileExists(completeName) { if fileExists(completeName) {
fmt.Println("Issue already found: " + issue.Publication.Name + " - " + issue.Name) fmt.Println("Issue already found: " + completeName)
continue continue
} }
fmt.Println("Downloading issue: " + issue.Publication.Name + " - " + issue.Name) fmt.Println("Downloading issue: " + publicationName + " - " + issueName)
pages := GetPages(loginToken, issue, initialToken, *zinioHostPtr) pages := GetPages(loginToken, issue, initialToken, *zinioHostPtr)
@ -156,7 +159,6 @@ func main() {
err = api.RemovePagesFile(filenames[i], "", []string{"2-"}, nil) err = api.RemovePagesFile(filenames[i], "", []string{"2-"}, nil)
if err != nil { if err != nil {
fmt.Printf("Removing extra pages failed with %s\n.", err) fmt.Printf("Removing extra pages failed with %s\n.", err)
} }
return return
@ -380,3 +382,15 @@ func GetDefaultTemplate() string {
</html>` </html>`
} }
var badCharacters = []string{"/", "\\", "<", ">", ":", "\"", "|", "?", "*"}
func RemoveBadCharacters(input string) string {
temp := input
for _, badChar := range badCharacters {
temp = strings.Replace(temp, badChar, "_", -1)
}
return temp
}

Binary file not shown.

Binary file not shown.