I wanted to add book cover images and publication dates, plus links to reviews to my book lists and individual book review pages (which I will get to someday.) I would like to automate the assignment of cover images as much as possible; there are a lot of titles listed here already and the last thing I want to do is a lot of unnecessary data entry.
My first thought was to use Amazon affiliate links with images. Unfortunately some ad-blocking extensions block the images, and using these links requires joining the Amazon Affiliates program. To stay in the program you have to bring in a base level of income in the first six months; they don’t want any low earning accounts. Also, while the search results in the Amazon Affiliate interface are quite good I didn’tsee a simple way to automate the searches.
So I turned to Open Library and Good Reads. Open Library offers a book cover API with three sizes of cover images, accessible with an ISBN (10 or 13 digit version) or Open Library ID. Open Library’s cover API will also take ‘/librarything/’ or ‘/goodreads/’ endpoint, presumably looking up those IDs and matching them with Open Library entries where those IDs are in the Open Library database.
Since it’s free and easy I decided to try it out on this site. I’ll probably experiment with the Good Reads API sometime soon as well.
First challenge: Whether using Amazon, Open Library or Good Reads, I have to find a useful ID for the book starting with only the author and book title. Amazon, Open Library and Good Reads searches all return multiple editions of any book. Some books have been republished many times and have audio and e-book editions listed in search results. More on this later.
Second challenge: Picking the best edition to link to from the book images and review page so that the information found when looking up that edition is what I want: Publication year, publisher etc.
After today’s results it’s clear each auto-generated link requires some QA. A few books had entries in Open Library but no images; others have incorrect publication dates or default to returning audio versions of the books. Many books got a good image and good link on the first try though.
For instance “The Hitch-Hikers Guide to the Galaxy” gives an edition from 2005 if you pick the first match; but picking the earliest match gives a “first published” date of 1969 which is wrong. A few other books when searched for return ISBN numbers that Open Library can’t turn around and serve up, even though their database gave it to us in the results.
Today I focused on Open Library and used their search API in my Ruby site builder script. It’s quite simple to get results:
openlibrary.org/search.json?title=title+words&author=author+name
The search gives back JSON with listings for all matches; very often the first edition listed, or the edition with the oldest publication date is exactly what I want. What I want in this case is the ISBN, since the ISBN can be used to retrieve the cover image from Open Library and is useful for finding more information on the book elsewhere. As I said many books have lots of ISBNs but Open Library seems to keep the same cover image for all (most?) of them.
http://covers.openlibrary.org/b/isbn/123456789-S.jpg
The results are fairly inconsistent in what fields are provided but at the least they have an OLID and normally one or more ISBNs. A “cover_i” field is usually included which looks to be the cover ID, but it appears it is associated with all the ISBNs already.
Here’s a sample of search results… just an excerpt of what you get back when looking for “The Long Dark Tea-Time of the Soul”
....
"title_suggest": "The long dark tea-time of the soul",
"edition_key": [
"OL18699051M",
"OL16409666M",
"OL17575328M",
"OL16627709M",
"OL13924619M",
"OL2246256M",
"OL18536708M",
"OL8603378M",
"OL17208411M",
"OL22250202M",
"OL17575335M",
"OL7663946M",
"OL7667462M",
"OL8845004M",
"OL8845002M"
],
"cover_i": 8291276,
"isbn": [
"9781590070604",
"9780671742515",
"0671881450",
"0434009210",
"9780330309554",
"0753104733",
"9781558001596",
"9780753104736",
"1590070607",
"0671694049",
"9780671881450",
"0671625837",
"9780434009213",
"9781590070758",
"0330309552",
"9780671625832",
"0671742515",
"9780671694043",
"155800159X",
"1590070755"
],
......
"author_name": [
"Douglas Adams"
],
"contributor": [
"Adams, Douglas."
],
"ia_loaded_id": [
"longdarkteatime00adam"
],
.......
"title": "The long dark tea-time of the soul",
"lending_identifier_s": "longdarkteatime00adam",
"ia_collection_s": "printdisabled;toronto;china;americana;internetarchivebooks;delawarecountydistrictlibrary;inlibrary",
"publish_date": [
"1990",
"February 15, 1991",
"June 2001",
"February 2002",
"1988",
"1989",
"December 1989",
"June 1, 1993"
],
"type": "work",
"ebook_count_i": 2,
"publish_place": [
"New York",
"London"
],
"ia_box_id": [
"IA117005",
"IA153512"
],
"edition_count": 15,
"first_publish_year": 1988,
"key": "/works/OL2163717W",
"id_goodreads": [
"862855",
"357",
"1125621",
"823660",
"1125620",
"1196557",
"862856",
"76615",
"364",
"1125622"
],
"public_scan_b": false,
"publisher": [
"Heinemann",
"Guild",
"Audioworks",
"Pocket",
"Simon and Schuster",
"Pocket Books",
"New Millennium Audio",
"PanBooks",
"Isis",
"Audio Literature",
"Guild Publishing"
],
"language": [
"eng"
],
"lccn": [
"89120700"
],
"last_modified_i": 1557895729,
"lending_edition_s": "OL18536708M",
"id_librarything": [
"5833"
],
"cover_edition_key": "OL18536708M",
"first_sentence": [
"It can hardly be a coincidence that no language on earth has ever produced the expression \"As pretty as an airport.\""
],
"person": [
"Dirk Gently"
],
"publish_year": [
1991,
1990,
1993,
1988,
1989,
2002,
2001
],
"printdisabled_s": "OL17575335M;OL18536708M",
"place": [
"London (England)"
]
},
Good Reads provides an API with title search and perhaps I’ll find it easier to deal with automatically.