diff --git a/app/iiif.go b/app/iiif.go index f103b0c..848cad5 100644 --- a/app/iiif.go +++ b/app/iiif.go @@ -26,18 +26,20 @@ type IIIF struct { type ResponseManifest struct { Sequences []struct { Canvases []struct { - Id string `json:"@id"` - Type string `json:"@type"` - Height int `json:"height"` + Id string `json:"@id"` + Type string `json:"@type"` + //兼容某些不正规的网站竟然用了string类型,见https://digitalarchive.npm.gov.tw/Antique/setJsonU?uid=58102&Dept=U + //Height int `json:"height"` Images []struct { Id string `json:"@id"` Type string `json:"@type"` On string `json:"on"` Resource struct { - Id string `json:"@id"` - Type string `json:"@type"` - Format string `json:"format"` - Height int `json:"height"` + Id string `json:"@id"` + Type string `json:"@type"` + Format string `json:"format"` + //兼容digitalarchive.npm.gov.tw + //Height int `json:"height"` Service struct { Id string `json:"@id"` } `json:"service"` @@ -45,7 +47,7 @@ type ResponseManifest struct { } `json:"resource"` } `json:"images"` Label string `json:"label"` - Width int `json:"width"` + //Width int `json:"width"` } `json:"canvases"` } `json:"sequences"` } diff --git a/build.sh b/build.sh index 880d994..b4d6572 100644 --- a/build.sh +++ b/build.sh @@ -1,5 +1,5 @@ -#ver="1.2.5" -ver=$(date "+%y%m%d") +ver="1.2.5" +#ver=$(date "+%y%m%d") sed -i '/const version = */c const version = "'"$ver"'"' config/init.go diff --git a/config/init.go b/config/init.go index 6c77876..b578faa 100644 --- a/config/init.go +++ b/config/init.go @@ -7,7 +7,7 @@ import ( var Conf Input -const version = "231208" +const version = "1.2.5" // initSeq false = 最小值 <= 当前页码 <= 最大值 func initSeq() { diff --git a/router/china.go b/router/china.go index e8be821..68ca333 100644 --- a/router/china.go +++ b/router/china.go @@ -4,7 +4,6 @@ import ( "bookget/app" "bookget/site/China/luoyang" "bookget/site/China/ncpssd" - "bookget/site/China/npmtw" "bookget/site/China/ouroots" "bookget/site/China/sdutcm" "bookget/site/China/szlib" @@ -43,15 +42,6 @@ func (p RbkdocNpmTw) getRouterInit(sUrl []string) (map[string]interface{}, error return nil, nil } -type DigitalarchiveNpmTw struct{} - -func (p DigitalarchiveNpmTw) getRouterInit(sUrl []string) (map[string]interface{}, error) { - for i, s := range sUrl { - npmtw.Init(i+1, s) - } - return nil, nil -} - type CuHk struct{} func (p CuHk) getRouterInit(sUrl []string) (map[string]interface{}, error) { diff --git a/router/init.go b/router/init.go index d3c6aed..a540767 100644 --- a/router/init.go +++ b/router/init.go @@ -49,8 +49,6 @@ func FactoryRouter(siteID string, sUrl []string) (map[string]interface{}, error) Router["lbezone.hkust.edu.hk"] = new(UstHk) //[中国]台北故宫博物院 - 古籍善本 rbkdocnpmtw.Init Router["rbk-doc.npm.edu.tw"] = new(RbkdocNpmTw) - //[中国]台北故宫博物院 - 典藏资料 npmtw.Init - Router["digitalarchive.npm.gov.tw"] = new(DigitalarchiveNpmTw) //[中国]洛阳市图书馆 Router["111.7.82.29:8090"] = new(LuoYang) //[中国]温州市图书馆 diff --git a/site/China/npmtw/npmtw.go b/site/China/npmtw/npmtw.go deleted file mode 100644 index dc1f56c..0000000 --- a/site/China/npmtw/npmtw.go +++ /dev/null @@ -1,69 +0,0 @@ -package npmtw - -import ( - "bookget/app" - "bookget/config" - "bookget/lib/curl" - "bookget/lib/util" - "encoding/json" - "fmt" - "log" - "regexp" -) - -func Init(iTask int, taskUrl string) (msg string, err error) { - bookId := "" - m := regexp.MustCompile(`\?pid=(\d+)`).FindStringSubmatch(taskUrl) - if m != nil { - bookId = m[1] - config.CreateDirectory(taskUrl, bookId) - StartDownload(iTask, taskUrl, bookId) - } - return "", err -} - -func StartDownload(iTask int, pageUrl, bookId string) { - name := util.GenNumberSorted(iTask) - log.Printf("Get %s %s\n", name, pageUrl) - canvases := getImageUrls(bookId, pageUrl) - if canvases.ImgUrls == nil { - return - } - log.Printf(" %d pages.\n", canvases.Size) - config.CreateDirectory(pageUrl, bookId) - - if config.Conf.UseDziRs { - app.DziDownload(pageUrl, bookId, canvases.IiifUrls) - } else { - app.NormalDownload(pageUrl, bookId, canvases.ImgUrls, nil) - } -} - -func getImageUrls(bookId, taskUrl string) (canvases Canvases) { - var manifest = new(Manifest) - u := fmt.Sprintf("https://digitalarchive.npm.gov.tw/Painting/setJson?pid=%s&Dept=P", bookId) - bs, err := curl.Get(u, nil) - if err != nil { - return - } - if err = json.Unmarshal(bs, manifest); err != nil { - log.Printf("json.Unmarshal failed: %s\n", err) - return - } - if len(manifest.Sequences) == 0 { - return - } - - i := len(manifest.Sequences[0].Canvases) - canvases.ImgUrls = make([]string, 0, i) - canvases.IiifUrls = make([]string, 0, i) - for _, canvase := range manifest.Sequences[0].Canvases { - for _, image := range canvase.Images { - u := fmt.Sprintf("%s/info.json", image.Resource.Service.Id) - canvases.IiifUrls = append(canvases.IiifUrls, u) - canvases.ImgUrls = append(canvases.ImgUrls, image.Resource.Id) - } - } - canvases.Size = len(canvases.ImgUrls) - return -} diff --git a/site/China/npmtw/struct.go b/site/China/npmtw/struct.go deleted file mode 100644 index ac6b3d1..0000000 --- a/site/China/npmtw/struct.go +++ /dev/null @@ -1,58 +0,0 @@ -package npmtw - -type Canvases struct { - ImgUrls []string - IiifUrls []string - Size int -} - -type Manifest struct { - Context string `json:"@context"` - Id string `json:"@id"` - Type string `json:"@type"` - Label string `json:"label"` - Logo string `json:"logo"` - Metadata []struct { - Label string `json:"label"` - Value string `json:"value"` - } `json:"metadata"` - Rendering []struct { - Id string `json:"@id"` - Format string `json:"format"` - Label string `json:"label"` - } `json:"rendering"` - License string `json:"license"` - ViewingDirection string `json:"viewingDirection"` - ViewingHint interface{} `json:"viewingHint"` - Sequences []struct { - Type string `json:"@type"` - Canvases []struct { - Label string `json:"label"` - Id string `json:"@id"` - Type string `json:"@type"` - Height string `json:"height"` - Width string `json:"width"` - Images []struct { - Id string `json:"@id"` - Type string `json:"@type"` - Motivation string `json:"motivation"` - On string `json:"on"` - Resource struct { - Description string `json:"description"` - Id string `json:"@id"` - Type string `json:"@type"` - Format string `json:"format"` - Service struct { - Id string `json:"@id"` - Context string `json:"@context"` - Profile string `json:"profile"` - } `json:"service"` - } `json:"resource"` - } `json:"images"` - OtherContent []struct { - Id string `json:"@id"` - Type string `json:"@type"` - } `json:"otherContent"` - } `json:"canvases"` - } `json:"sequences"` -}