-
Notifications
You must be signed in to change notification settings - Fork 0
/
grfromepub.go
56 lines (51 loc) · 1.33 KB
/
grfromepub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
b "github.com/barsanuphe/endive/book"
u "github.com/barsanuphe/helpers/ui"
h "github.com/barsanuphe/helpers"
"github.com/skratchdot/open-golang/open"
)
func main() {
// test parameters
if len(os.Args) == 1 {
fmt.Println("Please provide an epub filename.")
return
}
epubs := os.Args[1:]
validEpubs := []string{}
for i := range epubs {
if !strings.HasSuffix(strings.ToLower(epubs[i]), ".epub") {
fmt.Println(epubs[i] + " is not an epub, ignoring.")
continue
}
absPath, err := h.FileExists(epubs[i])
if err != nil {
fmt.Println(epubs[i] + ": " + err.Error())
} else {
validEpubs = append(validEpubs, absPath)
}
}
var ui u.UserInterface
ui = &u.UI{}
// parse epubs and open the goodreads page
for _, epub := range validEpubs {
e := b.Epub{Filename: epub, UI: ui}
metadata, err := e.ReadMetadata()
if err != nil {
fmt.Println("Error reading metadata from " + epub + ": " + err.Error())
}
if metadata.ISBN != "" {
fmt.Println(filepath.Base(epub) + ": found ISBN " + metadata.ISBN)
err = open.Start("https://www.goodreads.com/search?q=" + metadata.ISBN)
if err != nil {
fmt.Println("Error: could not open goodreads page for " + filepath.Base(epub))
}
} else {
fmt.Println(filepath.Base(epub) + ": could not find ISBN!")
}
}
}