Fix Amazon cover for UNIMARC
In UNIMARC, 010 tag contains ISBN. In UNIMARC, ISBN with '-' are valid. This patch modify ISBN normalization in order to automaticaly suppress '-' before sending ISBN to Amazon to get book cover. Signed-off-by: Galen Charlton <galen.charlton@liblime.com> Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
This commit is contained in:
parent
94f698da22
commit
fa7e8e493e
126
C4/Koha.pm
126
C4/Koha.pm
|
|
@ -1132,6 +1132,132 @@ sub display_marc_indicators {
|
|||
return $indicators;
|
||||
}
|
||||
|
||||
sub GetNormalizedUPC {
|
||||
my ($record,$marcflavour) = @_;
|
||||
my (@fields,$upc);
|
||||
|
||||
if ($marcflavour eq 'MARC21') {
|
||||
@fields = $record->field('024');
|
||||
foreach my $field (@fields) {
|
||||
my $indicator = $field->indicator(1);
|
||||
my $upc = _normalize_match_point($field->subfield('a'));
|
||||
if ($indicator == 1 and $upc ne '') {
|
||||
return $upc;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { # assume unimarc if not marc21
|
||||
@fields = $record->field('072');
|
||||
foreach my $field (@fields) {
|
||||
my $upc = _normalize_match_point($field->subfield('a'));
|
||||
if ($upc ne '') {
|
||||
return $upc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Normalizes and returns the first valid ISBN found in the record
|
||||
sub GetNormalizedISBN {
|
||||
my ($isbn,$record,$marcflavour) = @_;
|
||||
my @fields;
|
||||
if ($isbn) {
|
||||
return _isbn_cleanup($isbn);
|
||||
}
|
||||
return undef unless $record;
|
||||
|
||||
if ($marcflavour eq 'MARC21') {
|
||||
@fields = $record->field('020');
|
||||
foreach my $field (@fields) {
|
||||
$isbn = $field->subfield('a');
|
||||
if ($isbn) {
|
||||
return _isbn_cleanup($isbn);
|
||||
} else {
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { # assume unimarc if not marc21
|
||||
@fields = $record->field('010');
|
||||
foreach my $field (@fields) {
|
||||
my $isbn = $field->subfield('a');
|
||||
if ($isbn) {
|
||||
return _isbn_cleanup($isbn);
|
||||
} else {
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub GetNormalizedEAN {
|
||||
my ($record,$marcflavour) = @_;
|
||||
my (@fields,$ean);
|
||||
|
||||
if ($marcflavour eq 'MARC21') {
|
||||
@fields = $record->field('024');
|
||||
foreach my $field (@fields) {
|
||||
my $indicator = $field->indicator(1);
|
||||
$ean = _normalize_match_point($field->subfield('a'));
|
||||
if ($indicator == 3 and $ean ne '') {
|
||||
return $ean;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { # assume unimarc if not marc21
|
||||
@fields = $record->field('073');
|
||||
foreach my $field (@fields) {
|
||||
$ean = _normalize_match_point($field->subfield('a'));
|
||||
if ($ean ne '') {
|
||||
return $ean;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sub GetNormalizedOCLCNumber {
|
||||
my ($record,$marcflavour) = @_;
|
||||
my (@fields,$oclc);
|
||||
|
||||
if ($marcflavour eq 'MARC21') {
|
||||
@fields = $record->field('035');
|
||||
foreach my $field (@fields) {
|
||||
$oclc = $field->subfield('a');
|
||||
if ($oclc =~ /OCoLC/) {
|
||||
$oclc =~ s/\(OCoLC\)//;
|
||||
return $oclc;
|
||||
} else {
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { # TODO: add UNIMARC fields
|
||||
}
|
||||
}
|
||||
|
||||
sub _normalize_match_point {
|
||||
my $match_point = shift;
|
||||
(my $normalized_match_point) = $match_point =~ /([\d-]*[X]*)/;
|
||||
$normalized_match_point =~ s/-//g;
|
||||
|
||||
return $normalized_match_point;
|
||||
}
|
||||
|
||||
sub _isbn_cleanup ($) {
|
||||
my $normalized_isbn = shift;
|
||||
$normalized_isbn =~ s/-//g;
|
||||
$normalized_isbn =~/([0-9]{1,})/;
|
||||
$normalized_isbn = $1;
|
||||
if (
|
||||
$normalized_isbn =~ /\b(\d{13})\b/ or
|
||||
$normalized_isbn =~ /\b(\d{10})\b/ or
|
||||
$normalized_isbn =~ /\b(\d{9}X)\b/i
|
||||
) {
|
||||
return $1;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
|
|
|||
Loading…
Reference in New Issue