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';
99 my $url = 'http://www.cobiss.ba/scripts/cobiss?ukaz=GETID&lani=en';
103 my $mech = $self->{mech} || die "no mech?";
110 $mech->follow_link( text_regex => qr/union/ );
112 diag "switch to advanced form (select)";
114 $mech->follow_link( url_regex => qr/mode=3/ );
116 diag "submit search $query";
125 if ( $mech->content =~ m{hits:\s*<b>\s*(\d+)\s*</b>}s ) {
126 $self->{hits} = $hits = $1;
128 diag "get't find results in ", $mech->content;
132 diag "got $hits results, get first one";
134 $mech->follow_link( url_regex => qr/ukaz=DISP/ );
136 diag "in COMARC format";
138 $mech->follow_link( url_regex => qr/fmt=13/ );
145 my ($self,$format) = @_;
147 my $mech = $self->{mech} || die "no mech?";
149 $format ||= 'unimarc';
151 die "unknown format: $format" unless $format =~ m{(uni|us)marc};
155 if ( $mech->content =~ m{<pre>\s*(.+?(\d+)\.\s+ID=(\d+).+?)\s*</pre>}s ) {
161 diag "fetch $nr [$id] $format";
163 $markup =~ s{</?b>}{}gs;
164 $markup =~ s{<font[^>]*>}{<s>}gs;
165 $markup =~ s{</font>}{<e>}gs;
167 $markup =~ s/[\r\n]+\s{5}//gs; # join continuation lines
169 $self->save_marc( "$id.xml", $markup );
171 my $marc = MARC::Record->new;
172 my $comarc = MARC::Record->new;
174 foreach my $line ( split(/[\r\n]+/, $markup) ) {
176 if ( $line !~ s{^(\d\d\d)([01 ])([01 ])}{} ) {
181 my ( $f, $i1, $i2 ) = ( $1, $2, $3 );
183 our $marc_map = undef;
184 our $comarc_map = undef;
185 our $ignored = undef;
192 push @{ $comarc_map->{ $f } }, ( $sf, $v );
193 if ( my $m = $cobiss_marc21->{$f}->{$sf} ) {
194 push @{ $marc_map->{ $m->[0] } }, ( $m->[1], $v );
198 return ''; # fix warning
201 $l =~ s{<s>(\w)<e>([^<]+)}{sf_parse($f,$1, $2)}ges;
203 diag "[$format] $line -> ",dump( $comarc_map, $marc_map ) if $comarc_map;
205 foreach my $f ( keys %$comarc_map ) {
206 $comarc->add_fields( $f, $i1, $i2, @{ $comarc_map->{$f} } );
209 foreach my $f ( keys %$marc_map ) {
210 $marc->add_fields( $f, $i1, $i2, @{ $marc_map->{$f} } );
215 $self->save_marc( "$id.marc", $marc->as_usmarc );
216 $self->save_marc( "$id.unimarc", $comarc->as_usmarc );
217 diag $marc->as_formatted;
219 if ( $nr < $self->{hits} ) {
220 warn "# fetch next result";
222 $mech->follow_link( url_regex => qr/rec=$nr/ );
224 warn "# no more results";
229 die "can't fetch COMARC format from ", $mech->content;