Book images on Amazon need 10-digit ISBN

Bug #870171 reported by Ian Bays
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Evergreen
Fix Released
Undecided
Dan Scott
2.0
Fix Released
Undecided
Unassigned
2.1
Fix Released
Undecided
Unassigned

Bug Description

From experience, Amazon book cover requests mostly only responds to 10-digit ISBNs as the Amazon ID matches the 10-digit ISBN. Amazon's line has always been that they provide images keyed on their Amazon ID. Many catalogue records have a mixture of 10-digit and 13-digit ISBNs in no particular order. Specifically for Amazon content it would be good to intercept the ISBN before the URL is created for the image and convert 13-digit ISBN to 10-digits.
The perl module Business::ISBN can be used for a reliable conversion.
The code to change is in /openils/lib/perl5/OpenILS/WWW/AddedContent/Amazon.pm
We have tested this change on Evergreen version 2.0.5
diff of the code including diagnostic comments is here:
diff Amazon.pm Amazon_safe.pm
9d8
< use Business::ISBN;
70,81d68
< # open( my $diag, '>>/tmp/diagISBN.log' );
< # print $diag "before: $key\n";
< # print $diag "length: " . length($key) . "\n";
< if (length($key) == 13) {
< my $isbn = Business::ISBN->new( $key );
< $isbn = $isbn->as_isbn10 if $isbn->type eq 'ISBN13';
< if (defined $isbn) {
< $key = $isbn->as_string([]);
< }
< }
< # print $diag "after : $key\n";
< # close ($diag);

Revision history for this message
Dan Scott (denials) wrote :

Hello, Ian, and thanks for the code submission!

One suggestion for the code as submitted: use Perl to strip hyphens and starting / ending spaces from the incoming ISBN before checking its length (otherwise, it is unlikely to match 13). Otherwise, this looks like it will help sites that are using the Amazon added content plugin.

Note that this qualifies as a small submission under "Small additions and changes" (http://evergreen-ils.org/dokuwiki/doku.php?id=contributing#small_additions_and_changes) but we request that the process under "Submitting code o the project" (http://evergreen-ils.org/dokuwiki/doku.php?id=contributing&#submitting_code_to_the_project) be followed; for example, the use of the "git sign-off" tag to assert that you have the right to contribute the code.

Dan Scott (denials)
Changed in evergreen:
assignee: nobody → Dan Scott (denials)
Revision history for this message
Dan Scott (denials) wrote :

I went ahead and created a slight variation on your patch that makes use of Business::ISBN's built-in normalization whenever a key longer than 10 digits is passed, just in case the invoking process does not do the right space/hyphen/non-digit normalization. cleanISBN() in the JSPAC does, but there can be other front ends for Evergreen or invokers of the added content services.

This also preserves the working case where sites have added Amazon IDs as ISBNs (via 020 $a) to get cover art rather than teaching the OPAC & added content service to handle different kinds of keys :/

Committed to master through rel_2_0; the master commit hash is 856ca6d995b8723e3fc17eef70ee738fe24219dc and can be seen at http://git.evergreen-ils.org/?p=Evergreen.git;a=commit;h=856ca6d995b8723e3fc17eef70ee738fe24219dc

Thanks again, Ian!

Changed in evergreen:
milestone: none → 2.2.0
status: New → Fix Committed
Changed in evergreen:
status: Fix Committed → Fix Released
Revision history for this message
Neal Mack Hansen (n-hans3n) wrote :

I've hit this issue again and I've created my own fix, here is the diff for the two files. It simply creates a new Business::ISBN key and puts it as a string. Since there are hyphens, the ISBN10 will be 13 characters long. Check if it is over 13, and if so convert it to ISBN10. Move it back to a string and store it as the original value, then strip the dashes from it for Amazon API friendliness and let the script continue.

# diff Amazon.pm Amazon.pm.backup
9,10d8
< use Business::ISBN;
<
71,77d68
< my $tempkey = Business::ISBN->new($key);
< my $tempkeystring = $tempkey->as_string;
< if(length($tempkeystring)>13) {
< $tempkey = $tempkey->as_isbn10;
< $key = $tempkey->as_string;
< $key =~ s/-//g;
< }

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.