Created
October 12, 2024 14:25
-
-
Save avelican/8602b417e810f8dd4e31e8e3fbbb41f0 to your computer and use it in GitHub Desktop.
qpa mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// edit: only convert if not already txt... | |
if (filepath.Ext(inputPath)) != ".txt" { | |
// Create a temporary file for the intermediate output | |
tmpFile, err := os.CreateTemp("", "ebook-convert-*.txt") | |
if err != nil { | |
return nil, fmt.Errorf("failed to create temporary file: %v", err) | |
} | |
defer tmpFile.Close() | |
c := color.New(color.Bold, color.FgMagenta) | |
c.Println("Converting " + filepath.Base(inputPath) + " to the proper intermediary text format...") | |
cmd := exec.Command("ebook-convert", inputPath, tmpFile.Name()) | |
output, err := cmd.CombinedOutput() | |
if err != nil { | |
return nil, fmt.Errorf("failed to convert ebook: %s\nOutput: %s", err, string(output)) | |
} | |
return tmpFile, nil | |
} else { | |
// return inputPath, nil | |
inputFile, err := os.Open(inputPath) | |
if err != nil { | |
return nil, fmt.Errorf("failed to open input file") | |
} | |
return inputFile, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment