[Koha-devel] EAN to ISBN

Daniel Holth dholth at fastmail.fm
Fri Jan 23 18:28:00 CET 2004


I've been frustrated that Koha woudn't accept EAN numbers like this,
that I scan with a certain cat-shaped barcode wand:

9780061020674

This is the EAN for a paperback edition of Sourcerer (a novel of
Discworld) by Terry Pratchett.  It's encoded in a barcode.  The ISBN is
0-06-102067-2 - embedded in the EAN, except the EAN has its own
checksum.

Enter a module I dub ISBNParse.pm - in my tree (newest 2.x .tar.gz
downloaded from sourceforge) I put this in
koha/intranet/modules/C4/ISBNParse.pm; then files like isbnsearch.pl can
be modified:

----

use C4::ISBNParse;

if ( !$isbn && !$title ) {
    print $input->redirect('addbooks.pl');
}
else {
        $isbn = C4::ISBNParse::isbnfu($isbn);
        $input->param('isbn', $isbn);

----

If Business::ISBN is installed you get EAN-to-ISBN conversion, and this
agrees nicely with my barcode scanner.  If I had a CueCat that output
scrambled data, I would further enhance ISBNParse.pl to unscramble the
CueCat data (if /that/ module was available).

I hope this can work for somebody!  The main trick is figuring out where
to insert it; perhaps the isbnfu() calls could find a home in Search.pm.

It might make sense to enforce dashes (or their absence) in ISBN
numbers?

- Daniel Holth

-------- ISBNParse.pm:

# Convert EAN to ISBN when given EAN; when given ISBN, pass through.
# When given unrecognizable text, pass through.

package C4::ISBNParse;

# This is free software; you can redistribute it and/or modify it under
the
# terms of the GNU General Public License as published by the Free
Software
# Foundation; either version 2 of the License, or (at your option) any
later
# version.
#
# This is distributed in the hope that it will be useful, but WITHOUT
ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU General Public License for more
details.
#
# Copyright 2004 Daniel Holth <dholth at fastmail.fm>

use strict;
require Exporter;

use vars qw($VERSION @ISA @EXPORT $HaveISBN);

$VERSION = 0.01;
@ISA     = qw(Exporter);
@EXPORT  = qw(&isbnfu);

BEGIN { eval 'use Business::ISBN qw ( is_valid_checksum isbn_to_ean
ean_to_isbn )'; 
        $HaveISBN=1 unless $@; }

sub isbnfu {
    my $input = shift;
    print STDERR "\n$HaveISBN isbnfu $input\n";
    my $isbn;
    if($HaveISBN) {
        print $input;
        $isbn = ean_to_isbn($input);
        if($isbn) { $isbn = new Business::ISBN($isbn)->as_string; }
        unless($isbn) {
            $isbn = new Business::ISBN($_);
            if($isbn) { $isbn = $isbn->as_string; }
        }
        unless($isbn) { $isbn = $input; }
    } else { $isbn = $input; }
    return $isbn;
}






More information about the Koha-devel mailing list