mirror of
https://github.com/NohamR/papeer.git
synced 2026-05-25 04:17:19 +00:00
test tomobi, update progress style
This commit is contained in:
@@ -3,6 +3,8 @@ package book
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
md "github.com/JohannesKaufmann/html-to-markdown"
|
||||
@@ -10,6 +12,15 @@ import (
|
||||
epub "github.com/bmaupin/go-epub"
|
||||
)
|
||||
|
||||
func Filename(name string) string {
|
||||
filename := name
|
||||
|
||||
filename = strings.ReplaceAll(filename, " ", "_")
|
||||
filename = strings.ReplaceAll(filename, "/", "")
|
||||
|
||||
return filename
|
||||
}
|
||||
|
||||
func ToMarkdown(c chapter) string {
|
||||
|
||||
// make title
|
||||
@@ -33,7 +44,7 @@ func ToMarkdown(c chapter) string {
|
||||
return content
|
||||
}
|
||||
|
||||
func ToEpub(c chapter, filename string) {
|
||||
func ToEpub(c chapter, filename string) string {
|
||||
if len(filename) == 0 {
|
||||
filename = fmt.Sprintf("%s.epub", c.Name())
|
||||
}
|
||||
@@ -50,6 +61,8 @@ func ToEpub(c chapter, filename string) {
|
||||
}
|
||||
|
||||
fmt.Printf("Ebook saved to \"%s\"\n", filename)
|
||||
|
||||
return filename
|
||||
}
|
||||
|
||||
func AppendToEpub(e *epub.Epub, c chapter, imagesOnly bool) {
|
||||
@@ -88,3 +101,34 @@ func AppendToEpub(e *epub.Epub, c chapter, imagesOnly bool) {
|
||||
AppendToEpub(e, sc, false)
|
||||
}
|
||||
}
|
||||
|
||||
func ToMobi(c chapter, filename string) string {
|
||||
if len(filename) == 0 {
|
||||
filename = fmt.Sprintf("%s.mobi", c.Name())
|
||||
} else {
|
||||
|
||||
// add .mobi extension if not specified
|
||||
if strings.HasSuffix(filename, ".mobi") == false {
|
||||
filename = fmt.Sprintf("%s.mobi", filename)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
filenameEPUB := strings.ReplaceAll(filename, ".mobi", ".epub")
|
||||
ToEpub(c, filenameEPUB)
|
||||
|
||||
exec.Command("kindlegen", filenameEPUB).Run()
|
||||
// exec command always return status 1 even if it succeed
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
|
||||
fmt.Printf("Ebook saved to \"%s\"\n", filename)
|
||||
|
||||
err := os.Remove(filenameEPUB)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return filename
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user