From 94f3533eda3a581742a0794490c547c1f95b12ee Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 11 May 2021 14:05:37 +0100 Subject: Handle pages with png suffix correctly Example book: https://content.staatsbibliothek-berlin.de/dc/687222079/manifest --- cmd/iiifdownloader/main.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/iiifdownloader/main.go b/cmd/iiifdownloader/main.go index d6802a6..b6cca97 100644 --- a/cmd/iiifdownloader/main.go +++ b/cmd/iiifdownloader/main.go @@ -168,7 +168,8 @@ func parseIIIFManifest(u string, c *http.Client) ([]string, error) { // redirects to a info.json unless we manually add the appropriate // iiif parameters. if strings.HasPrefix(u, "https://iiif.bodleian.ox.ac.uk") && - !strings.HasSuffix(u, ".jpg") && !strings.HasSuffix(u, ".jpeg") { + !strings.HasSuffix(u, ".jpg") && !strings.HasSuffix(u, ".jpeg") && + !strings.HasSuffix(u, ".png") { u += "/full/full/0/native.jpg" } urls = append(urls, u) @@ -185,9 +186,15 @@ func urlToPgName(u string) string { safe := strings.Replace(u, "/", "_", -1) b := path.Base(u) - if b != "default.jpg" && b != "native.jpg" { + ext := path.Ext(b) + if ext == "" { + ext = ".jpg" + } + + if b != "default.jpg" && b != "native.jpg" && + b != "default.png" && b != "native.png" { if path.Ext(b) == "" { - return b + ".jpg" + return b + ext } return b } @@ -211,10 +218,10 @@ func urlToPgName(u string) string { pgnumint, err := strconv.Atoi(pgnum) if err != nil { - return pgnum + ".jpg" + return pgnum + ext } - return fmt.Sprintf("%04d.jpg", pgnumint) + return fmt.Sprintf("%04d%s", pgnumint, ext) } // dlPage downloads a page url to bookdir. -- cgit v1.2.1-24-ge1ad