Lofter1 / anyflip-downloader

Download anyflip books as PDF
GNU General Public License v3.0
241 stars 39 forks source link

"The system cannot find the path specified" and flag errors #26

Closed ottori-yo closed 1 year ago

ottori-yo commented 1 year ago

Description

OS: Windows 10 22H2

To Reproduce Install, using the PowerShell command provided in the code. Input the command line, such as: anyflip-downloader https://anyflip.com/ybvc/hgch -title MM5 or anyflip-downloader https://anyflip.com/ybvc/zlfd/ -temp-download-folder Eberron

Expected behavior Conversion of downloaded data into a pdf even if the title of the downloaded book in anyflip contains an apostrophe. Title is changed to the one specified by the flag. Temporary folder name is changed to the one specified by the flag.

wasivis commented 1 year ago

Hi! @Lofter1 I don't really know how to contribute, but you need to sanitize the name of the PDF when converting in main.go, since it has some issues with special characters like ' and . If you add a function that deletes those characters (and any others that might give you problems when converting to PDF), and then sanitize the name of the output file, it works like a charm:

func createPDF(outputFile string, imageDir string) error {
    pdf := itopdf.NewInstance()
    err := pdf.WalkDir(imageDir, nil)
    if err != nil {
        return err
    }

    // Sanitize the output file name
    outputFile = sanitizeFileName(outputFile)

    err = pdf.Save(outputFile)
    if err != nil {
        return err
    }
    return nil
}

func sanitizeFileName(fileName string) string {
    // Replace invalid characters in file names
    fileName = strings.ReplaceAll(fileName, "'", "")
    fileName = strings.ReplaceAll(fileName, "\\", "")

    return fileName
}
Lofter1 commented 1 year ago

I added sanitisation to the convertPDF method now.

Concerning the title not being set: I made a mistake when writing the README. Gos standard flag library cares for the position of flags. They should come before the first positional argument (so the book URL in this case). Move the URL to the end of the command and it should work. I'll probably should add a better usage message that describes the usage correctly, too.

ottori-yo commented 1 year ago

Thank you for the quick fix!