summaryrefslogtreecommitdiff
path: root/internal/pipeline/get.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pipeline/get.go')
-rw-r--r--internal/pipeline/get.go34
1 files changed, 27 insertions, 7 deletions
diff --git a/internal/pipeline/get.go b/internal/pipeline/get.go
index 960c8f7..8fac060 100644
--- a/internal/pipeline/get.go
+++ b/internal/pipeline/get.go
@@ -12,7 +12,7 @@ import (
"strings"
)
-func DownloadBestPages(dir string, name string, conn Downloader, pluspngs bool) error {
+func DownloadBestPages(dir string, name string, conn Downloader) error {
key := filepath.Join(name, "best")
fn := filepath.Join(dir, "best")
err := conn.Download(conn.WIPStorageId(), key, fn)
@@ -35,12 +35,23 @@ func DownloadBestPages(dir string, name string, conn Downloader, pluspngs bool)
return fmt.Errorf("Failed to download file %s: %v", key, err)
}
}
+ return nil
+}
- if !pluspngs {
- return nil
+func DownloadBestPngs(dir string, name string, conn Downloader) error {
+ key := filepath.Join(name, "best")
+ fn := filepath.Join(dir, "best")
+ err := conn.Download(conn.WIPStorageId(), key, fn)
+ if err != nil {
+ return fmt.Errorf("Failed to download 'best' file: %v", err)
}
+ f, err := os.Open(fn)
+ if err != nil {
+ return fmt.Errorf("Failed to open best file: %v", err)
+ }
+ defer f.Close()
- s = bufio.NewScanner(f)
+ s := bufio.NewScanner(f)
for s.Scan() {
imgname := strings.Replace(s.Text(), ".hocr", ".png", 1)
key = filepath.Join(name, imgname)
@@ -55,14 +66,22 @@ func DownloadBestPages(dir string, name string, conn Downloader, pluspngs bool)
}
func DownloadPdfs(dir string, name string, conn Downloader) error {
- for _, suffix := range []string{".colour.pdf", ".binarised.pdf"} {
+ anydone := false
+ errmsg := ""
+ for _, suffix := range []string{".colour.pdf", ".binarised.pdf", ".original.pdf"} {
key := filepath.Join(name, name+suffix)
fn := filepath.Join(dir, name+suffix)
err := conn.Download(conn.WIPStorageId(), key, fn)
if err != nil {
- return fmt.Errorf("Failed to download PDF %s: %v", key, err)
+ _ = os.Remove(fn)
+ errmsg += fmt.Sprintf("Failed to download PDF %s: %v\n", key, err)
+ } else {
+ anydone = true
}
}
+ if anydone == false {
+ return fmt.Errorf("No PDFs could be downloaded, error(s): %v", errmsg)
+ }
return nil
}
@@ -71,7 +90,8 @@ func DownloadAnalyses(dir string, name string, conn Downloader) error {
key := filepath.Join(name, a)
fn := filepath.Join(dir, a)
err := conn.Download(conn.WIPStorageId(), key, fn)
- if err != nil {
+ // ignore errors with graph.png, as it will not exist in the case of a 1 page book
+ if err != nil && a != "graph.png" {
return fmt.Errorf("Failed to download analysis file %s: %v", key, err)
}
}