diff options
author | Nick White <git@njw.name> | 2021-05-11 14:05:37 +0100 |
---|---|---|
committer | Nick White <git@njw.name> | 2021-05-11 14:05:37 +0100 |
commit | 94f3533eda3a581742a0794490c547c1f95b12ee (patch) | |
tree | 7cfbab6103f2515b9ef8d4295de1f1da8f62c4fa /cmd/iiifdownloader | |
parent | a46d2b0b2fb8232587944b7a310cfb0a36fda058 (diff) |
Handle pages with png suffix correctly
Example book: https://content.staatsbibliothek-berlin.de/dc/687222079/manifest
Diffstat (limited to 'cmd/iiifdownloader')
-rw-r--r-- | cmd/iiifdownloader/main.go | 17 |
1 files 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. |