Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails If Title Name Has Characters that Can't Be Used in Filename #67

Open
YisroelTech opened this issue Sep 25, 2024 · 1 comment
Open

Comments

@YisroelTech
Copy link

When downloading a book with a title that has characters that aren't allowed in a filename (and not specifying a new title with -title) the process fails:

Preparing to download
https://anyflip.com/t---m/s--t
Downloading 100% |█████████████████████████████████████████████████████████████████████████████████████████| (100/100)
Converting to pdf
2024/09/25 12:07:55 open גליון 2 | טעסט.pdf: The filename, directory name, or volume label syntax is incorrect.

Can it be added to the script to sanitize the title to delete/replace all characters not allowed in a filename?

The characters (at least on Windows) include:

/ (forward slash)
< (less than)
> (greater than)
: (colon - sometimes works, but is actually NTFS Alternate Data Streams)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)
@YisroelTech
Copy link
Author

I actually notice now that the getBookTitle function seems to already be doing that for the \. Can the rest be added?

func getBookTitle(configjs string) (string, error) {
r := regexp.MustCompile(`("?(bookConfig.)?bookTitle"?[=]"(.*?)")|"title":"(.*?)"`)
match := r.FindString(configjs)
if strings.Contains(match, "=") {
match = strings.Split(match, "=")[1]
} else if strings.Contains(match, ":") {
match = strings.Split(match, ":")[1]
} else {
return "", errors.New("could not find book title")
}
match = strings.ReplaceAll(match, "\"", "")
return match, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant