forked from Ivasoft/opds-proxy
feat: kepub conversions
Working *.epub to *.kepub.epub file conversions when using a Kobo reader. Updated docker file to include `kepubify` to convert to kepub. If not available the file is just sent without conversion.
This commit is contained in:
14
convert/convert.go
Normal file
14
convert/convert.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package convert
|
||||
|
||||
const (
|
||||
MOBI_MIME = "application/x-mobipocket-ebook"
|
||||
EPUB_MIME = "application/epub+zip"
|
||||
)
|
||||
|
||||
type Converter interface {
|
||||
// Whether or not the converter is available
|
||||
// Usually based on the availability of the underlying tool
|
||||
Available() bool
|
||||
// Convert the input file to the output file
|
||||
Convert(input string, output string) error
|
||||
}
|
||||
29
convert/kepub.go
Normal file
29
convert/kepub.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type KepubConverter struct {
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
func (kc *KepubConverter) Available() bool {
|
||||
path, err := exec.LookPath("kepubify")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return path != ""
|
||||
}
|
||||
|
||||
func (kc *KepubConverter) Convert(input string, output string) error {
|
||||
kc.mutex.Lock()
|
||||
defer kc.mutex.Unlock()
|
||||
cmd := exec.Command("kepubify", "-v", "-u", "-o", output, input)
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
25
convert/mobi.go
Normal file
25
convert/mobi.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type MobiConverter struct {
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
func (mc *MobiConverter) Available() bool {
|
||||
path, err := exec.LookPath("kindlegen")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return path != ""
|
||||
}
|
||||
|
||||
func (mc *MobiConverter) Convert(input string, output string) error {
|
||||
mc.mutex.Lock()
|
||||
defer mc.mutex.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user