From a4d9ca8671292f9028db51748f4f028746d9bdef Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 23 Feb 2022 12:56:36 +0000 Subject: rescribe: Add embedded support for getgbook, for linux only so far --- cmd/rescribe/main.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'cmd/rescribe/main.go') diff --git a/cmd/rescribe/main.go b/cmd/rescribe/main.go index 7db5e3e..65ecd60 100644 --- a/cmd/rescribe/main.go +++ b/cmd/rescribe/main.go @@ -201,6 +201,20 @@ These training files are included in rescribe, and are always available: } } + err = unpackZip(gbookzip, tessdir) + if err != nil { + log.Fatalln("Error unpacking embedded getgbook zip:", err) + } + var gbookCommand string + switch runtime.GOOS { + case "darwin": + tessCommand = filepath.Join(tessdir, "getgbook") + case "linux": + gbookCommand = filepath.Join(tessdir, "getgbook") + case "windows": + tessCommand = filepath.Join(tessdir, "getgbook.exe") + } + tessdatadir := filepath.Join(tessdir, "tessdata") err = os.MkdirAll(tessdatadir, 0755) if err != nil { @@ -238,7 +252,7 @@ These training files are included in rescribe, and are always available: } if flag.NArg() < 1 || *usegui { - err := startGui(*verboselog, tessCommand, trainingName, tessdir) + err := startGui(*verboselog, tessCommand, gbookCommand, trainingName, tessdir) err = os.RemoveAll(tessdir) if err != nil { log.Printf("Error removing tesseract directory %s: %v", tessdir, err) @@ -266,12 +280,16 @@ These training files are included in rescribe, and are always available: var ctx context.Context + // TODO: support google book downloading, as done with the GUI + // try opening as a PDF, and extracting if !fi.IsDir() { if flag.NArg() < 2 { savedir = strings.TrimSuffix(bookdir, ".pdf") } + // BUG: this seems to fail from command line, yet works from GUI + // (used to work) bookdir, err = extractPdfImgs(ctx, bookdir) if err != nil { log.Fatalln("Error opening file as PDF:", err) -- cgit v1.2.1-24-ge1ad