LP#1306823: try to increase changes of fetching added content from the OL user/gmcharlt/lp1306823_fetch_more_covers_from_ol
authorGalen Charlton <gmc@esilibrary.com>
Fri, 11 Apr 2014 21:48:00 +0000 (14:48 -0700)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 11 Apr 2014 21:48:00 +0000 (14:48 -0700)
For works that have more than one edition in the Open Library's
database, using 'isbn' as the search key can sometimes fail to
bring up the edition that has a cover image.  This patch instead
uses "isbn_10" or "isbn_13", depending on the length of the ISBN,
to try to retrieve the right edition.

This is known to work with ISBN 9264023607.  However, it is also
entirely possible that this works only because of a quirk in OL
as of the date of this patch; for example, neither "isbn_10"
nor "isbn_13" are listed as valid ID types in
https://openlibrary.org/dev/docs/api/read.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/OpenLibrary.pm

index c2c2cc6..fcfbcb1 100644 (file)
@@ -259,7 +259,11 @@ sub fetch_response {
 
     # TODO: OpenLibrary can also accept lccn, oclc, olid...
     # Hardcoded to only accept ISBNs for now.
-    $key = "isbn:$key";
+    if (length($key) <= 10) {
+        $key = "isbn_10:$key";
+    } else {
+        $key = "isbn_13:$key";
+    }
 
     my $url = $read_api . $key;
     my $response = $AC->get_url($url)->content();