-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
98 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
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 | ||
Convert(input string) (string, error) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,40 @@ | ||
package convert | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
type KepubConverter struct { | ||
mutex sync.Mutex | ||
mutex sync.Mutex | ||
available bool | ||
availableOnce sync.Once | ||
} | ||
|
||
func (kc *KepubConverter) Available() bool { | ||
path, err := exec.LookPath("kepubify") | ||
if err != nil { | ||
return false | ||
} | ||
return path != "" | ||
kc.availableOnce.Do(func() { | ||
fmt.Println("TEST") | ||
path, err := exec.LookPath("kepubify") | ||
kc.available = err == nil && path != "" | ||
}) | ||
|
||
return kc.available | ||
} | ||
|
||
func (kc *KepubConverter) Convert(input string, output string) error { | ||
func (kc *KepubConverter) Convert(input string) (string, error) { | ||
kc.mutex.Lock() | ||
defer kc.mutex.Unlock() | ||
cmd := exec.Command("kepubify", "-v", "-u", "-o", output, input) | ||
|
||
dir := filepath.Dir(input) | ||
kepubFile := filepath.Join(dir, strings.Replace(filepath.Base(input), ".epub", ".kepub.epub", 1)) | ||
|
||
cmd := exec.Command("kepubify", "-v", "-u", "-o", kepubFile, input) | ||
if err := cmd.Run(); err != nil { | ||
return err | ||
return "", err | ||
} | ||
|
||
return nil | ||
return kepubFile, nil | ||
} |
This file contains 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
This file contains 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