Add option to force hyphenation in KEPUB (#1656)

* Add option to force hyphenation in KEPUB

Fixes #1465

* Default force hyphenation to false

* Remove commented out code
This commit is contained in:
beedaddy
2025-11-27 06:45:47 -07:00
committed by GitHub
parent 190cb1fc7a
commit 47f75c2b9a
7 changed files with 36 additions and 7 deletions
@@ -8,4 +8,5 @@ import lombok.Data;
public class KoboSettings {
private boolean convertToKepub;
private int conversionLimitInMb;
private boolean forceEnableHyphenation;
}
@@ -253,6 +253,7 @@ public class SettingPersistenceHelper {
return KoboSettings.builder()
.convertToKepub(false)
.conversionLimitInMb(100)
.forceEnableHyphenation(false)
.build();
}
}
}
@@ -97,7 +97,8 @@ public class BookDownloadService {
if (asKepub) {
tempDir = Files.createTempDirectory("kepub-output");
fileToSend = kepubConversionService.convertEpubToKepub(inputFile, tempDir.toFile());
fileToSend = kepubConversionService.convertEpubToKepub(inputFile, tempDir.toFile(),
koboSettings.isForceEnableHyphenation());
}
setResponseHeaders(response, fileToSend);
@@ -28,11 +28,11 @@ public class KepubConversionService {
private static final String BIN_LINUX_ARM = "kepubify-linux-arm";
private static final String BIN_LINUX_ARM64 = "kepubify-linux-arm64";
public File convertEpubToKepub(File epubFile, File tempDir) throws IOException, InterruptedException {
public File convertEpubToKepub(File epubFile, File tempDir, boolean forceEnableHyphenation) throws IOException, InterruptedException {
validateInputs(epubFile);
Path kepubifyBinary = setupKepubifyBinary();
File outputFile = executeKepubifyConversion(epubFile, tempDir, kepubifyBinary);
File outputFile = executeKepubifyConversion(epubFile, tempDir, kepubifyBinary, forceEnableHyphenation);
log.info("Successfully converted {} to {} (size: {} bytes)", epubFile.getName(), outputFile.getName(), outputFile.length());
return outputFile;
@@ -98,9 +98,14 @@ public class KepubConversionService {
throw new IllegalStateException("Unsupported operating system or architecture: " + osName + " / " + osArch);
}
private File executeKepubifyConversion(File epubFile, File tempDir, Path kepubifyBinary) throws IOException, InterruptedException {
private File executeKepubifyConversion(File epubFile, File tempDir, Path kepubifyBinary, boolean forceEnableHyphenation) throws IOException, InterruptedException {
ProcessBuilder pb;
if (forceEnableHyphenation)
pb = new ProcessBuilder(kepubifyBinary.toAbsolutePath().toString(), "--hyphenate", "-o", tempDir.getAbsolutePath(), epubFile.getAbsolutePath());
else
pb = new ProcessBuilder(kepubifyBinary.toAbsolutePath().toString(), "-o", tempDir.getAbsolutePath(), epubFile.getAbsolutePath());
ProcessBuilder pb = new ProcessBuilder(kepubifyBinary.toAbsolutePath().toString(), "-o", tempDir.getAbsolutePath(), epubFile.getAbsolutePath());
pb.directory(tempDir);
log.info("Starting kepubify conversion for {} -> output dir: {}", epubFile.getAbsolutePath(), tempDir.getAbsolutePath());