7 use Data::Dump qw/dump/;
12 '010' => { a => [ '020', 'a' ] },
17 205 => { a => [ 250 , 'a' ] },
39 # Bib-1 @and @and @and @and @and @and @and @or
45 # @attr 1=21 subject-holding
46 # @attr 1=12 control-no
47 # @attr 1=1007 standard-id
52 # CB= Autor - korporacija
54 # CP= Mesto sast./dod. nazivu korp.
58 # P2= Zaključna godina izdanja
60 # TO= Naslov originala
64 # PN= Predmetna odrednica - lično ime
65 # CS= Predm. odred. - naziv korporacije
66 # DU= Slobodno oblikovane predm. odred.
67 # SU= Predmetne odrednice - sve
68 # AC= Kod za vrstu autorstva
69 # CC= Kod za vrstu sadržaja
70 # CO= Zemlja/regija izdavanja
71 # FC= Šifra organizacije
73 # LC= Kod za književni oblik
74 # LO= Jezik izvornog dela
75 # TA= Kod za predviđene korisnike
76 # TD= Tipologija dok./dela
77 # UC= UDK za pretraživanje
81 7 => 'BN', # FIXME check
82 8 => 'SP', # FIXME check
94 my ( $self, $query ) = @_;
96 die "need query" unless defined $query;
98 my $url = 'http://cobiss.izum.si/scripts/cobiss?ukaz=GETID&lani=en';
102 my $mech = $self->{mech} || die "no mech?";
109 $mech->follow_link( text_regex => qr/union/ );
111 diag "switch to advanced form (select)";
113 $mech->follow_link( url_regex => qr/mode=3/ );
115 diag "submit search $query";
124 if ( $mech->content =~ m{hits:\s*<b>\s*(\d+)\s*</b>}s ) {
125 $self->{hits} = $hits = $1;
127 diag "get't find results in ", $mech->content;
131 diag "got $hits results, get first one";
133 $mech->follow_link( url_regex => qr/ukaz=DISP/ );
135 diag "in COMARC format";
137 $mech->follow_link( url_regex => qr/fmt=13/ );
144 my ($self,$format) = @_;
146 my $mech = $self->{mech} || die "no mech?";
148 $format ||= 'unimarc';
150 die "unknown format: $format" unless $format =~ m{(uni|us)marc};
154 if ( $mech->content =~ m{<pre>\s*(.+?(\d+)\.\s+ID=(\d+).+?)\s*</pre>}s ) {
160 diag "fetch $nr [$id] $format";
162 $markup =~ s{</?b>}{}gs;
163 $markup =~ s{<font[^>]*>}{<s>}gs;
164 $markup =~ s{</font>}{<e>}gs;
166 $markup =~ s/[\r\n]+\s{5}//gs; # join continuation lines
168 $self->save_marc( "$id.xml", $markup );
170 my $marc = MARC::Record->new;
171 my $comarc = MARC::Record->new;
173 foreach my $line ( split(/[\r\n]+/, $markup) ) {
175 if ( $line !~ s{^(\d\d\d)([01 ])([01 ])}{} ) {
180 my ( $f, $i1, $i2 ) = ( $1, $2, $3 );
182 our $marc_map = undef;
183 our $comarc_map = undef;
184 our $ignored = undef;
191 push @{ $comarc_map->{ $f } }, ( $sf, $v );
192 if ( my $m = $cobiss_marc21->{$f}->{$sf} ) {
193 push @{ $marc_map->{ $m->[0] } }, ( $m->[1], $v );
197 return ''; # fix warning
200 $l =~ s{<s>(\w)<e>([^<]+)}{sf_parse($f,$1, $2)}ges;
202 diag "[$format] $line -> ",dump( $comarc_map, $marc_map ) if $comarc_map;
204 foreach my $f ( keys %$comarc_map ) {
205 $comarc->add_fields( $f, $i1, $i2, @{ $comarc_map->{$f} } );
208 foreach my $f ( keys %$marc_map ) {
209 $marc->add_fields( $f, $i1, $i2, @{ $marc_map->{$f} } );
214 $self->save_marc( "$id.marc", $marc->as_usmarc );
215 $self->save_marc( "$id.unimarc", $comarc->as_usmarc );
216 diag $marc->as_formatted;
218 if ( $nr < $self->{hits} ) {
219 warn "# fetch next result";
221 $mech->follow_link( url_regex => qr/rec=$nr/ );
223 warn "# no more results";
228 die "can't fetch COMARC format from ", $mech->content;