diff options
Diffstat (limited to 'skate/schema.go')
-rw-r--r-- | skate/schema.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/skate/schema.go b/skate/schema.go index 42587b9..fda2e7a 100644 --- a/skate/schema.go +++ b/skate/schema.go @@ -480,6 +480,7 @@ type OpenLibraryEdition struct { Librarything []string `json:"librarything"` } `json:"identifiers"` Isbn10 []string `json:"isbn_10"` + Isbn13 []string `json:"isbn_13"` Key string `json:"key"` Languages []struct { Key string `json:"key"` @@ -516,7 +517,25 @@ type OpenLibraryEdition struct { } `json:"works"` } +// Isbns returns all found ISBN. Unique, non-normalized. +func (v OpenLibraryEdition) Isbns() []string { + s := set.New() + for _, w := range v.Isbn10 { + s.Add(w) + } + for _, w := range v.Isbn13 { + s.Add(w) + } + return s.Sorted() +} + // OpenLibraryEditionToRelease convert OL data into a release. XXX: release/work? -func OpenLibraryEditionToRelease(w *OpenLibraryEdition) (*Release, error) { - return nil, nil +func OpenLibraryEditionToRelease(v *OpenLibraryEdition) (*Release, error) { + var release = Release{} + release.Title = v.Title + release.ExtIDs.ISBN = v.Isbns() + if len(v.Publishers) > 0 { + release.Publisher = v.Publishers[0] + } + return &release, nil } |