added latest states
This commit is contained in:
@@ -42,8 +42,31 @@ type MangaDesc struct {
|
||||
En string `json:"en"`
|
||||
}
|
||||
|
||||
func CreateEpub(mangaPath string, epubPath string, mangaTitle string, mangaId string) {
|
||||
func CreateEpub(mangaPath string, mangaTitle string, mangaId string) {
|
||||
var author MangaPlus
|
||||
var epubCss string
|
||||
|
||||
epubCss = `@page {
|
||||
background-color: #FFF;
|
||||
margin-bottom: 0pt;
|
||||
margin-left: 0pt;
|
||||
margin-right: 0pt;
|
||||
margin-top: 0pt;
|
||||
}
|
||||
.page {
|
||||
width: auto;
|
||||
height: auto;
|
||||
break-after: page;
|
||||
break-before: page;
|
||||
}
|
||||
.chapter {
|
||||
width: auto;
|
||||
height: auto;
|
||||
break-after: page;
|
||||
break-before: page;
|
||||
}`
|
||||
|
||||
_ = os.WriteFile("/tmp/epub/epub.css", []byte(epubCss), 0644)
|
||||
|
||||
url := "https://api.mangadex.org/manga/" + mangaId + "?includes[]=author&includes[]=cover_art"
|
||||
data := mangacrawler.GetJson(url)
|
||||
@@ -61,10 +84,13 @@ func CreateEpub(mangaPath string, epubPath string, mangaTitle string, mangaId st
|
||||
}
|
||||
}
|
||||
|
||||
book := epub.NewEpub(mangaTitle)
|
||||
book, err := epub.NewEpub(mangaTitle)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
book.SetAuthor(author.Data.Rels[0].Attributes.Name)
|
||||
book.SetDescription(author.Data.Attr.Desc.En)
|
||||
bookCss, _ := book.AddCSS(strings.Join([]string{epubPath, "epub.css"}, "/"), "")
|
||||
bookCss, _ := book.AddCSS("/tmp/epub/epub.css", "epubCss")
|
||||
bookCover, _ := book.AddImage(coverPath, coverFile)
|
||||
|
||||
book.SetCover(bookCover, "")
|
||||
@@ -73,15 +99,15 @@ func CreateEpub(mangaPath string, epubPath string, mangaTitle string, mangaId st
|
||||
fmt.Println("Adding pages to EPUB. Each chapter is a section\nIf chapter title is available that will be used for section title")
|
||||
addPages(book, mangaPath, bookCss)
|
||||
|
||||
fmt.Println("Writing EPUB to disk...")
|
||||
err := book.Write(strings.Join([]string{epubPath, mangaTitle + ".epub"}, "/"))
|
||||
fmt.Println("Writing EPUB to disk to add it to calibre DB")
|
||||
err = book.Write(strings.Join([]string{"/tmp/epub", mangaTitle + ".epub"}, "/"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// TODO add check to skip calibre call if calibre not found
|
||||
fmt.Println("Adding EPUB to calibre DB")
|
||||
cmd := exec.Command("calibredb", "add", "--automerge", "overwrite", strings.Join([]string{epubPath, mangaTitle + ".epub"}, "/"))
|
||||
cmd := exec.Command("calibredb", "add", "--automerge", "overwrite", strings.Join([]string{"/tmp/epub", mangaTitle + ".epub"}, "/"))
|
||||
var out strings.Builder
|
||||
cmd.Stdout = &out
|
||||
fmt.Println(cmd)
|
||||
@@ -91,6 +117,8 @@ func CreateEpub(mangaPath string, epubPath string, mangaTitle string, mangaId st
|
||||
}
|
||||
fmt.Printf(out.String())
|
||||
|
||||
_ = os.Remove(strings.Join([]string{"/tmp/epub", mangaTitle + ".epub"}, "/"))
|
||||
|
||||
}
|
||||
|
||||
func addPages(book *epub.Epub, mangaPath string, bookCss string) *epub.Epub {
|
||||
|
||||
Reference in New Issue
Block a user