1 |
|
---|
2 | # plugin which processes an the BBC Sound archive exported in an ASCII format
|
---|
3 |
|
---|
4 | package BRSPlug;
|
---|
5 |
|
---|
6 | use BasPlug;
|
---|
7 | use ghtml;
|
---|
8 |
|
---|
9 | sub BEGIN
|
---|
10 | {
|
---|
11 | @ISA = ('BasPlug');
|
---|
12 | unshift (@INC, "$ENV{'GSDLCOLLECTDIR'}/perllib");
|
---|
13 | }
|
---|
14 |
|
---|
15 | %Exclude = ();
|
---|
16 |
|
---|
17 |
|
---|
18 | # Note: sext is short for scrollable text
|
---|
19 |
|
---|
20 | #field_id label disp_type crit_type width height brs_para
|
---|
21 | #----------------------------------------------------------------
|
---|
22 | #10 sport prdcr text text 30 1 T006
|
---|
23 | #1 text sext text 40 16 TEXT
|
---|
24 | #16 scol ref text text text 30 1 SCOL
|
---|
25 | #19 date text date 10 1 D001
|
---|
26 | #25 Item title text text 20 1 T001
|
---|
27 | #26 B/W Seqs text text 30 1 S001
|
---|
28 | #27 Medium text text 30 1 S002
|
---|
29 | #28 shot type text text 30 1 S003
|
---|
30 | #29 B/W Prog/Item text text 30 1 S004
|
---|
31 | #30 Seqs text text 10 1 S005
|
---|
32 | #31 Format text text 30 1 S006
|
---|
33 | #32 prog/item text text 30 1 S007
|
---|
34 | #35 reg libno text text 30 1 S008
|
---|
35 | #36 reg tape no text text 30 1 S009
|
---|
36 | #37 C Indicator text text 30 1 S010
|
---|
37 | #38 C Holder text text 30 1 T002
|
---|
38 | #39 cprd ind text text 30 1 S011
|
---|
39 | #40 cprd name text text 30 1 T003
|
---|
40 | #44 reference sext text 30 5 R001
|
---|
41 | #49 prog num text text 10 1 PRNO
|
---|
42 | #59 news title text text 30 1 T005
|
---|
43 | #65 cat num text text 10 1 CATN
|
---|
44 | #72 Record number text text 30 1 T007
|
---|
45 | #73 rx_date text date 10 1 S013
|
---|
46 | #74 Music performer text text 30 2 T008
|
---|
47 | #75 Composer text text 30 2 T009
|
---|
48 | #76 mono/stereo text text 30 1 S014
|
---|
49 | #77 music medium text text 30 1 S015
|
---|
50 | #82 Sound Tech text text 30 1 S016
|
---|
51 | #83 Music publisher text text 30 1 S017
|
---|
52 | #84 music tape text text 30 1 T012
|
---|
53 | #89 catalogue text text 3 1 CODE
|
---|
54 | #104 subcat text text 10 1 SUBC
|
---|
55 | #106 prog title text text 40 1 TTLE
|
---|
56 | #109 screen type text text 10 1 DOCT
|
---|
57 | #110 stock title text text 30 1 T013
|
---|
58 | #113 stock ln 4 text text 30 1 T015
|
---|
59 | #114 stock lib 1 text text 30 1 S020
|
---|
60 | #115 stock lib 2 text text 30 1 S021
|
---|
61 | #----------------------------------------------------------------
|
---|
62 |
|
---|
63 |
|
---|
64 | my @brs_field_table
|
---|
65 | = (
|
---|
66 | { field_name => "TTLE", field_id => 106, label => "Prog title",
|
---|
67 | disp_type => "text", crit_type => "text",
|
---|
68 | width => 40, height => 1 },
|
---|
69 | { field_name => "T001", field_id => 25, label => "Item title",
|
---|
70 | disp_type => "text", crit_type => "text",
|
---|
71 | width => 20, height => 1 },
|
---|
72 | { field_name => "T005", field_id => 59, label => "News title",
|
---|
73 | disp_type => "text", crit_type => "text",
|
---|
74 | width => 30, height => 1 },
|
---|
75 | { field_name => "T013", field_id => 110, label => "Stock title",
|
---|
76 | disp_type => "text", crit_type => "text",
|
---|
77 | width => 30, height => 1 },
|
---|
78 | { field_name => "T007", field_id => 72, label => "Record number",
|
---|
79 | disp_type => "text", crit_type => "text",
|
---|
80 | width => 30, height => 1 },
|
---|
81 | { field_name => "TEXT", field_id => 1, label => "Text",
|
---|
82 | disp_type => "scrl", crit_type => "text",
|
---|
83 | width => 40, height => 16 },
|
---|
84 |
|
---|
85 | { field_name => "T006", field_id => 10, label => "Sport prdcr",
|
---|
86 | disp_type => "text", crit_type => "text",
|
---|
87 | width => 30, height => 1 },
|
---|
88 | { field_name => "SCOL", field_id => 16, label => "Scol ref text",
|
---|
89 | disp_type => "text", crit_type => "text",
|
---|
90 | width => 30, height => 1 },
|
---|
91 | { field_name => "D001", field_id => 19, label => "Date",
|
---|
92 | disp_type => "text", crit_type => "date",
|
---|
93 | width => 10, height => 1 },
|
---|
94 | { field_name => "S001", field_id => 26, label => "B/W Seqs",
|
---|
95 | disp_type => "text", crit_type => "text",
|
---|
96 | width => 30, height => 1 },
|
---|
97 | { field_name => "S002", field_id => 27, label => "Medium",
|
---|
98 | disp_type => "text", crit_type => "text",
|
---|
99 | width => 30, height => 1 },
|
---|
100 | { field_name => "S003", field_id => 28, label => "Shot type",
|
---|
101 | disp_type => "text", crit_type => "text",
|
---|
102 | width => 30, height => 1 },
|
---|
103 | { field_name => "S004", field_id => 29, label => "B/W Prog/Item",
|
---|
104 | disp_type => "text", crit_type => "text",
|
---|
105 | width => 30, height => 1 },
|
---|
106 | { field_name => "S005", field_id => 30, label => "Seqs",
|
---|
107 | disp_type => "text", crit_type => "text",
|
---|
108 | width => 10, height => 1 },
|
---|
109 | { field_name => "S006", field_id => 31, label => "Format",
|
---|
110 | disp_type => "text", crit_type => "text",
|
---|
111 | width => 30, height => 1 },
|
---|
112 | { field_name => "S007", field_id => 32, label => "Prog/item",
|
---|
113 | disp_type => "text", crit_type => "text",
|
---|
114 | width => 30, height => 1 },
|
---|
115 | { field_name => "S008", field_id => 35, label => "Reg libno",
|
---|
116 | disp_type => "text", crit_type => "text",
|
---|
117 | width => 30, height => 1 },
|
---|
118 | { field_name => "S009", field_id => 36, label => "Reg tape no",
|
---|
119 | disp_type => "text", crit_type => "text",
|
---|
120 | width => 30, height => 1 },
|
---|
121 | { field_name => "S010", field_id => 37, label => "C Indicator",
|
---|
122 | disp_type => "text", crit_type => "text",
|
---|
123 | width => 30, height => 1 },
|
---|
124 | { field_name => "T002", field_id => 38, label => "C Holder",
|
---|
125 | disp_type => "text", crit_type => "text",
|
---|
126 | width => 30, height => 1 },
|
---|
127 | { field_name => "S011", field_id => 39, label => "Cprd ind",
|
---|
128 | disp_type => "text", crit_type => "text",
|
---|
129 | width => 30, height => 1 },
|
---|
130 | { field_name => "T003", field_id => 40, label => "Cprd name",
|
---|
131 | disp_type => "text", crit_type => "text",
|
---|
132 | width => 30, height => 1 },
|
---|
133 | { field_name => "R001", field_id => 44, label => "Reference",
|
---|
134 | disp_type => "scrl", crit_type => "text",
|
---|
135 | width => 30, height => 5 },
|
---|
136 | { field_name => "PRNO", field_id => 49, label => "Prog num",
|
---|
137 | disp_type => "text", crit_type => "text",
|
---|
138 | width => 10, height => 1 },
|
---|
139 | { field_name => "CATN", field_id => 65, label => "Cat num",
|
---|
140 | disp_type => "text", crit_type => "text",
|
---|
141 | width => 10, height => 1 },
|
---|
142 | { field_name => "S013", field_id => 73, label => "Rx_date",
|
---|
143 | disp_type => "text", crit_type => "date",
|
---|
144 | width => 10, height => 1 },
|
---|
145 | { field_name => "T008", field_id => 74, label => "Music performer",
|
---|
146 | disp_type => "text", crit_type => "text",
|
---|
147 | width => 30, height => 2 },
|
---|
148 | { field_name => "T009", field_id => 75, label => "Composer",
|
---|
149 | disp_type => "text", crit_type => "text",
|
---|
150 | width => 30, height => 2 },
|
---|
151 | { field_name => "S014", field_id => 76, label => "Mono/stereo",
|
---|
152 | disp_type => "text", crit_type => "text",
|
---|
153 | width => 30, height => 1 },
|
---|
154 | { field_name => "S015", field_id => 77, label => "Music medium",
|
---|
155 | disp_type => "text", crit_type => "text",
|
---|
156 | width => 30, height => 1 },
|
---|
157 | { field_name => "S016", field_id => 82, label => "Sound Tech",
|
---|
158 | disp_type => "text", crit_type => "text",
|
---|
159 | width => 30, height => 1 },
|
---|
160 | { field_name => "S017", field_id => 83, label => "Music publisher",
|
---|
161 | disp_type => "text", crit_type => "text",
|
---|
162 | width => 30, height => 1 },
|
---|
163 | { field_name => "T012", field_id => 84, label => "Music tape",
|
---|
164 | disp_type => "text", crit_type => "text",
|
---|
165 | width => 30, height => 1 },
|
---|
166 | { field_name => "CODE", field_id => 89, label => "Catalogue",
|
---|
167 | disp_type => "text", crit_type => "text",
|
---|
168 | width => 3, height => 1 },
|
---|
169 | { field_name => "SUBC", field_id => 104, label => "Subcat",
|
---|
170 | disp_type => "text", crit_type => "text",
|
---|
171 | width => 10, height => 1 },
|
---|
172 | { field_name => "DOCT", field_id => 109, label => "Screen type",
|
---|
173 | disp_type => "text", crit_type => "text",
|
---|
174 | width => 10, height => 1 },
|
---|
175 | { field_name => "T015", field_id => 113, label => "Stock ln 4",
|
---|
176 | disp_type => "text", crit_type => "text",
|
---|
177 | width => 30, height => 1 },
|
---|
178 | { field_name => "S020", field_id => 114, label => "Stock lib 1",
|
---|
179 | disp_type => "text", crit_type => "text",
|
---|
180 | width => 30, height => 1 },
|
---|
181 | { field_name => "S021", field_id => 115, label => "Stock lib 2",
|
---|
182 | disp_type => "text", crit_type => "text",
|
---|
183 | width => 30, height => 1 }
|
---|
184 | );
|
---|
185 |
|
---|
186 |
|
---|
187 | my @brs_title_list = ("TTLE", "T001", "T005", "T013", "T007", "zzTI");
|
---|
188 | my %cat_num_list = ();
|
---|
189 |
|
---|
190 | sub new {
|
---|
191 | my ($class) = @_;
|
---|
192 | my $self = new BasPlug ($class, @_);
|
---|
193 |
|
---|
194 | return bless $self, $class;
|
---|
195 | }
|
---|
196 |
|
---|
197 | sub get_default_process_exp {
|
---|
198 | my $self = shift (@_);
|
---|
199 |
|
---|
200 | return q^(?i)\.brs$^;
|
---|
201 | }
|
---|
202 |
|
---|
203 | my $brs_doc_count = 0;
|
---|
204 | my $brs_dot_count = 0;
|
---|
205 | my $brs_line_no = 0;
|
---|
206 |
|
---|
207 | sub brs_error
|
---|
208 | {
|
---|
209 | my ($file, $mess, $outhandle) = @_;
|
---|
210 |
|
---|
211 | print $outhandle "Malformed BRS recorded at line $brs_line_no in $file:\n";
|
---|
212 | print $outhandle " $mess\n";
|
---|
213 | }
|
---|
214 |
|
---|
215 | sub read_brs_record
|
---|
216 | {
|
---|
217 | my ($recordref, $file, $outhandle) = @_;
|
---|
218 |
|
---|
219 | my $extra_trigger = '\s*>';
|
---|
220 | my $text_divider = "-" x 78;
|
---|
221 | my $text_end = "..R001";
|
---|
222 |
|
---|
223 | # Print "." to signify processing if enough records have been read in
|
---|
224 | $brs_doc_count++;
|
---|
225 | if (($brs_doc_count % 10) == 0)
|
---|
226 | {
|
---|
227 | print $outhandle ".";
|
---|
228 | $brs_dot_count++;
|
---|
229 | print $outhandle "\n" if (($brs_dot_count % 80) == 0);
|
---|
230 | }
|
---|
231 |
|
---|
232 | my $brs_rec = undef;
|
---|
233 | my $line = undef;
|
---|
234 |
|
---|
235 | # read in the record
|
---|
236 | my @brs_lines = split /\n/, $$recordref;
|
---|
237 |
|
---|
238 | while (scalar(@brs_lines)>0)
|
---|
239 | {
|
---|
240 | $line = shift(@brs_lines);
|
---|
241 | $line =~ s/\cM//g;
|
---|
242 |
|
---|
243 | $brs_line_no++;
|
---|
244 |
|
---|
245 | if ($line =~ m/^\.\.([A-Z]|[0-9]){4}:$/)
|
---|
246 | {
|
---|
247 | my $field_name = substr($line,2,4);
|
---|
248 |
|
---|
249 | if ($field_name eq "TEXT")
|
---|
250 | {
|
---|
251 | my $text_above = "";
|
---|
252 | my $text_extra = "";
|
---|
253 | my $text_below = "";
|
---|
254 |
|
---|
255 | my $add_mode = "above";
|
---|
256 |
|
---|
257 | while (scalar(@brs_lines)>0)
|
---|
258 | {
|
---|
259 | last if ($brs_lines[0] =~ m/^$text_end/);
|
---|
260 |
|
---|
261 | $line = shift(@brs_lines);
|
---|
262 | $brs_line_no++;
|
---|
263 |
|
---|
264 | if ($line =~ m/^$text_divider/)
|
---|
265 | {
|
---|
266 | $add_mode = "below";
|
---|
267 | next;
|
---|
268 | }
|
---|
269 |
|
---|
270 | if ($line =~ m/^$extra_trigger/)
|
---|
271 | {
|
---|
272 | $text_extra .= "$line\n";
|
---|
273 | $add_mode = "below";
|
---|
274 | next;
|
---|
275 | }
|
---|
276 |
|
---|
277 | if ($line =~ m/^\.\.([A-Z]|[0-9]){4}:/)
|
---|
278 | {
|
---|
279 | if ($line =~ m/^\.\.TEXT/)
|
---|
280 | {
|
---|
281 | $add_mode = "above";
|
---|
282 | next;
|
---|
283 | }
|
---|
284 | else
|
---|
285 | {
|
---|
286 | brs_error($file, "Unexpected field $line", $outhandle);
|
---|
287 | # put field name back
|
---|
288 | unshift(@brs_lines, $line);
|
---|
289 | $brs_line_no--;
|
---|
290 | last;
|
---|
291 | }
|
---|
292 | }
|
---|
293 |
|
---|
294 | if ($line !~ m/^\s+(-){10,}$/)
|
---|
295 | {
|
---|
296 | if ($add_mode eq "above")
|
---|
297 | {
|
---|
298 | $text_above .= "$line ";
|
---|
299 | }
|
---|
300 | else
|
---|
301 | {
|
---|
302 | $text_below .= "$line ";
|
---|
303 | }
|
---|
304 | }
|
---|
305 | }
|
---|
306 |
|
---|
307 | $brs_rec->{TEXTA} .= $text_above if ($text_above ne "");
|
---|
308 | $brs_rec->{TEXTB} .= $text_below if ($text_below ne "");
|
---|
309 | $brs_rec->{TEXTE} .= $text_extra if ($text_extra ne "");
|
---|
310 | }
|
---|
311 | elsif ($field_name eq "R001")
|
---|
312 | {
|
---|
313 | # read zz fields until end of record
|
---|
314 |
|
---|
315 | while (scalar(@brs_lines)>0)
|
---|
316 | {
|
---|
317 | $line = shift(@brs_lines);
|
---|
318 | $brs_line_no++;
|
---|
319 |
|
---|
320 | if ($line =~ m/^(zz[A-Z]+)( +)(.*)/)
|
---|
321 | {
|
---|
322 | my $field_name = $1;
|
---|
323 | my $field_text = $3;
|
---|
324 |
|
---|
325 | while (scalar(@brs_lines)>0)
|
---|
326 | {
|
---|
327 | my $line_ahead = $brs_lines[0];
|
---|
328 |
|
---|
329 | last if ($line_ahead =~ m/^zz[A-Z]+/);
|
---|
330 |
|
---|
331 | $line = shift(@brs_lines);
|
---|
332 | $brs_line_no++;
|
---|
333 |
|
---|
334 | $field_text .= $line;
|
---|
335 | }
|
---|
336 |
|
---|
337 | if (!defined($brs_rec->{$field_name}))
|
---|
338 | {
|
---|
339 | $brs_rec->{$field_name} = [$field_text];
|
---|
340 | }
|
---|
341 | else
|
---|
342 | {
|
---|
343 | push(@{$brs_rec->{$field_name}},$field_text);
|
---|
344 | }
|
---|
345 | }
|
---|
346 | else
|
---|
347 | {
|
---|
348 | brs_error($file, "Unexpected field $line", $outhandle);
|
---|
349 | }
|
---|
350 | }
|
---|
351 | }
|
---|
352 | else
|
---|
353 | {
|
---|
354 | my $field_entry = "";
|
---|
355 | while ($brs_lines[0] !~ m/^..([A-Z]|[0-9]){4}:$/)
|
---|
356 | {
|
---|
357 | $field_entry .= shift(@brs_lines);
|
---|
358 | $brs_line_no++;
|
---|
359 | last if (scalar(@brs_lines)==0);
|
---|
360 | }
|
---|
361 |
|
---|
362 | if (!defined($brs_rec->{$field_name}))
|
---|
363 | {
|
---|
364 | $brs_rec->{$field_name} = $field_entry;
|
---|
365 | }
|
---|
366 | else
|
---|
367 | {
|
---|
368 | brs_error($file, "$field_name already defined.", $outhandle);
|
---|
369 | }
|
---|
370 | }
|
---|
371 | }
|
---|
372 | else
|
---|
373 | {
|
---|
374 | brs_error($file, "Malformed field: $line.", $outhandle);
|
---|
375 | }
|
---|
376 | }
|
---|
377 |
|
---|
378 | # format the programme number if required
|
---|
379 | &format_prognum($brs_rec);
|
---|
380 |
|
---|
381 | return ($brs_rec);
|
---|
382 | }
|
---|
383 |
|
---|
384 | my $brs_processed_count = 0;
|
---|
385 |
|
---|
386 | sub brs_full_record_in_html
|
---|
387 | {
|
---|
388 | my ($doc_obj,$cursection,$brs_rec) = @_;
|
---|
389 |
|
---|
390 | my $html_table = "";
|
---|
391 | my $table_line = "";
|
---|
392 | my $cell_count = 0;
|
---|
393 | my $long_lines = "";
|
---|
394 |
|
---|
395 | my $i;
|
---|
396 | for ($i=0; $i<=$#brs_field_table; $i++)
|
---|
397 | {
|
---|
398 | my $field_name = $brs_field_table[$i]->{'field_name'};
|
---|
399 | if (defined($brs_rec->{$field_name}))
|
---|
400 | {
|
---|
401 | my $field_label = $brs_field_table[$i]->{'label'};
|
---|
402 | my $field_value = $brs_rec->{$field_name};
|
---|
403 |
|
---|
404 | # these fields get their own line
|
---|
405 | if ($field_label =~ /^(Prog|Item|News|Stock) title$/) {
|
---|
406 | my $safe_value = $field_value;
|
---|
407 | &ghtml::urlsafe ($safe_value);
|
---|
408 | $long_lines .= "<tr valign=top><td><b>$field_label:</b></td><td colspan=5>";
|
---|
409 | $long_lines .= "<a href=\"_httpquerytitle_&q=$safe_value\">$field_value</a></td></tr>\n";
|
---|
410 | $long_lines .= "$field_value</td></tr>\n";
|
---|
411 |
|
---|
412 | } else {
|
---|
413 |
|
---|
414 | if (($cell_count>0) && ($cell_count%3 == 0))
|
---|
415 | {
|
---|
416 | $html_table .= "\n<tr valign=top>\n$table_line\n</tr>\n";
|
---|
417 | $table_line = "";
|
---|
418 | }
|
---|
419 | $cell_count++;
|
---|
420 | if ($field_name eq "D001") # a Dublin core style date
|
---|
421 | {
|
---|
422 | my @mon_convert
|
---|
423 | = ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
---|
424 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
|
---|
425 |
|
---|
426 | my ($year,$monnum,$day)
|
---|
427 | = ($field_value =~ m/(\d{4})(\d{2})(\d{2})/);
|
---|
428 | my $moneng = $mon_convert[$monnum-1];
|
---|
429 |
|
---|
430 | $field_value = "$day $moneng $year";
|
---|
431 |
|
---|
432 | } elsif ($field_name eq "PRNO") {
|
---|
433 | my $safe_value = $field_value;
|
---|
434 | &ghtml::urlsafe ($safe_value);
|
---|
435 | $field_value = "<a href=\"_httpqueryprogname_&q=$safe_value\">$field_value</a>";
|
---|
436 |
|
---|
437 | } elsif ($field_name eq "CATN") {
|
---|
438 | my $safe_value = $field_value;
|
---|
439 | &ghtml::urlsafe ($safe_value);
|
---|
440 | $field_value = "<a href=\"_httpquerycatnum_&q=$safe_value\">$field_value</a>";
|
---|
441 |
|
---|
442 | } elsif ($field_name eq "T003") {
|
---|
443 | my $safe_value = $field_value;
|
---|
444 | &ghtml::urlsafe ($safe_value);
|
---|
445 | $field_value = "<a href=\"_httpqueryzzabn_&q=$safe_value\">$field_value</a>";
|
---|
446 | }
|
---|
447 |
|
---|
448 | $table_line .= "<td><b>$field_label:</b></td><td>$field_value</td>\n";
|
---|
449 | }
|
---|
450 | }
|
---|
451 | }
|
---|
452 |
|
---|
453 | if ($cell_count%3 != 0) {
|
---|
454 | $table_line .= "<td colspan=" . (3-($cell_count%3))*2 . "></td>";
|
---|
455 | }
|
---|
456 |
|
---|
457 | $html_table .= "\n<tr>\n$table_line\n</tr>\n";
|
---|
458 | $html_table = "<table>\n$long_lines$html_table\n</table>\n";
|
---|
459 |
|
---|
460 | $doc_obj->add_utf8_text($cursection, $html_table);
|
---|
461 | }
|
---|
462 |
|
---|
463 | sub process_brs_record
|
---|
464 | {
|
---|
465 | my ($processor, $brs_rec, $file, $outhandle) = @_;
|
---|
466 |
|
---|
467 | if (defined($brs_rec))
|
---|
468 | {
|
---|
469 |
|
---|
470 | # only include those records in the chosen subcats - these lines
|
---|
471 | # should be commented out to build the entire collection
|
---|
472 |
|
---|
473 | # National Sound Archive collection
|
---|
474 | if (!defined ($brs_rec->{'SUBC'}) ||
|
---|
475 | $brs_rec->{'SUBC'} !~ /^(RADCOMP|RADIOX|RADPROG|RADNEWS|BDSPROG|UNCATRAD|RADIOREF|WILDSOUND)$/) {
|
---|
476 | return;
|
---|
477 | }
|
---|
478 |
|
---|
479 | # British Film Institute collection
|
---|
480 | # if (!defined ($brs_rec->{'SUBC'}) ||
|
---|
481 | # $brs_rec->{'SUBC'} !~ /^(LONPROG|NEWS)$/) {
|
---|
482 | # return;
|
---|
483 | # }
|
---|
484 |
|
---|
485 | # "the rest" collection
|
---|
486 | # if (!defined ($brs_rec->{'SUBC'}) ||
|
---|
487 | # $brs_rec->{'SUBC'} =~ /^(LONPROG|NEWS|RADCOMP|RADIOX|RADPROG|RADNEWS|BDSPROG|UNCATRAD|RADIOREF)$/) {
|
---|
488 | # return;
|
---|
489 | # }
|
---|
490 |
|
---|
491 | # don't include the secret stuff ;-)
|
---|
492 | if (defined ($brs_rec->{'SUBC'}) && $brs_rec->{'SUBC'} eq "HISTORY") {
|
---|
493 | print STDERR "excluding secret stuff - line $brs_line_no\n";
|
---|
494 | return;
|
---|
495 | }
|
---|
496 |
|
---|
497 |
|
---|
498 | my $doc_obj = new doc ($file, "indexed_doc");
|
---|
499 | $brs_processed_count++;
|
---|
500 |
|
---|
501 | my $cursection = $doc_obj->get_top_section();
|
---|
502 |
|
---|
503 | my $found_match = "no";
|
---|
504 |
|
---|
505 | my $pot_title;
|
---|
506 | foreach $pot_title ( @brs_title_list )
|
---|
507 | {
|
---|
508 | if (defined ($brs_rec->{$pot_title}))
|
---|
509 | {
|
---|
510 | my $title = "";
|
---|
511 |
|
---|
512 | if ($pot_title =~ m/^zz/)
|
---|
513 | {
|
---|
514 | my $zz_join = join(" ", @{$brs_rec->{$pot_title}});
|
---|
515 | my @zz_split = split(" ", $zz_join);
|
---|
516 | map { $title .= "$_ " if ($_ !~ m/^xx/); } @zz_split;
|
---|
517 | }
|
---|
518 | else
|
---|
519 | {
|
---|
520 | $title = $brs_rec->{$pot_title};
|
---|
521 | }
|
---|
522 |
|
---|
523 | my $tl_ref = $doc_obj->get_metadata ($cursection, "Title");
|
---|
524 |
|
---|
525 | if (scalar(@$tl_ref==0))
|
---|
526 | {
|
---|
527 | $doc_obj->add_utf8_metadata ($cursection, "Title", $title);
|
---|
528 | }
|
---|
529 | else
|
---|
530 | {
|
---|
531 | my $exists = "no";
|
---|
532 |
|
---|
533 | map { $exists = "yes" if ($title eq $_); } @$tl_ref;
|
---|
534 | if ($exists eq "no")
|
---|
535 | {
|
---|
536 | $doc_obj->add_utf8_metadata($cursection, "Title", $title);
|
---|
537 | }
|
---|
538 | }
|
---|
539 | $found_match = "yes";
|
---|
540 | }
|
---|
541 | }
|
---|
542 | if ($found_match eq "no")
|
---|
543 | {
|
---|
544 | if (defined($brs_rec->{TEXTA}))
|
---|
545 | {
|
---|
546 | my $sub_title = substr($brs_rec->{TEXTA},0,60) . " ... ";
|
---|
547 | $doc_obj->add_utf8_metadata ($cursection, "Title", $sub_title);
|
---|
548 | }
|
---|
549 | elsif (defined($brs_rec->{TEXTB}))
|
---|
550 | {
|
---|
551 | my $sub_title = substr($brs_rec->{TEXTB},0,60) . " ... ";
|
---|
552 | $doc_obj->add_utf8_metadata ($cursection, "Title", $sub_title);
|
---|
553 | }
|
---|
554 | else
|
---|
555 | {
|
---|
556 | print $outhandle " No title or text for record ending at line ";
|
---|
557 | print $outhandle $brs_line_no-1, " ";
|
---|
558 | }
|
---|
559 | }
|
---|
560 |
|
---|
561 | if (defined($brs_rec->{'T001'})) # item title
|
---|
562 | {
|
---|
563 | $doc_obj->add_utf8_metadata ($cursection, "ItemTitle", $brs_rec->{'T001'});
|
---|
564 | }
|
---|
565 |
|
---|
566 | if (defined($brs_rec->{'D001'})) # date
|
---|
567 | {
|
---|
568 | $doc_obj->add_utf8_metadata ($cursection, "Date", $brs_rec->{'D001'});
|
---|
569 | }
|
---|
570 | else
|
---|
571 | {
|
---|
572 | print $outhandle " No date for record ending at line ";
|
---|
573 | print $outhandle $brs_line_no-1, " ";
|
---|
574 | }
|
---|
575 |
|
---|
576 | if (defined($brs_rec->{'PRNO'})) # programme number
|
---|
577 | {
|
---|
578 | $doc_obj->add_utf8_metadata ($cursection, "ProgNumber", $brs_rec->{'PRNO'});
|
---|
579 | }
|
---|
580 |
|
---|
581 | if (defined($brs_rec->{'CATN'})) # catalogue number
|
---|
582 | {
|
---|
583 | $doc_obj->add_utf8_metadata ($cursection, "CatNum", $brs_rec->{'CATN'});
|
---|
584 | }
|
---|
585 |
|
---|
586 | # zzAN, zzAB and T003 fields
|
---|
587 | if (defined($brs_rec->{'zzAB'}) || defined($brs_rec->{'zzAN'}) || defined($brs_rec->{'T003'}))
|
---|
588 | {
|
---|
589 | my $zzabn = "";
|
---|
590 | if (defined($brs_rec->{'zzAB'})) {
|
---|
591 | foreach my $a (@{$brs_rec->{'zzAB'}}) {
|
---|
592 | $a =~ s/[^a-zA-Z0-9]//g;
|
---|
593 | $zzabn .= " " . $a;
|
---|
594 | }
|
---|
595 | }
|
---|
596 | if (defined($brs_rec->{'zzAN'})) {
|
---|
597 | foreach my $a (@{$brs_rec->{'zzAN'}}) {
|
---|
598 | $a =~ s/[^a-zA-Z0-9]//g;
|
---|
599 | $zzabn .= " " . $a;
|
---|
600 | }
|
---|
601 | }
|
---|
602 | if (defined($brs_rec->{'T003'})) {
|
---|
603 | my $value = $brs_rec->{'T003'};
|
---|
604 | $value =~ s/[^a-zA-Z0-9]//g;
|
---|
605 | $zzabn .= " " . $value;
|
---|
606 | }
|
---|
607 | print STDERR "zzabn: '$zzabn'\n";
|
---|
608 | $doc_obj->add_utf8_metadata ($cursection, "zzabn", $zzabn);
|
---|
609 | }
|
---|
610 |
|
---|
611 | if (defined($brs_rec->{zzN}))
|
---|
612 | {
|
---|
613 | my $name;
|
---|
614 | foreach $name (@{$brs_rec->{zzN}})
|
---|
615 | {
|
---|
616 | $doc_obj->add_utf8_metadata ($cursection, "People", $name);
|
---|
617 | }
|
---|
618 | }
|
---|
619 |
|
---|
620 | brs_full_record_in_html($doc_obj,$cursection,$brs_rec);
|
---|
621 |
|
---|
622 | if (defined($brs_rec->{TEXTA}))
|
---|
623 | {
|
---|
624 |
|
---|
625 | my $desc_texta = "<h3>Description</h3>$brs_rec->{TEXTA}";
|
---|
626 | $doc_obj->add_utf8_text ($cursection, $desc_texta);
|
---|
627 |
|
---|
628 | if (defined($brs_rec->{TEXTE}))
|
---|
629 | {
|
---|
630 | my $raw_texte = $brs_rec->{TEXTE};
|
---|
631 | $raw_texte =~ s/^\s*>\s*/<li>/mg;
|
---|
632 |
|
---|
633 | my $test_empty = $raw_texte;
|
---|
634 | $test_empty =~ s/(<li>)+//g;
|
---|
635 |
|
---|
636 | if ($test_empty ne "")
|
---|
637 | {
|
---|
638 | my $desc_texte = $raw_texte;
|
---|
639 | $desc_texte =~ s/^<li>(.*)$/<li><i>$1<\/i>/mg;
|
---|
640 | $desc_texte = "<p>Additional:<ul>$desc_texte</ul>";
|
---|
641 | $doc_obj->add_utf8_text ($cursection, $desc_texte);
|
---|
642 | }
|
---|
643 | }
|
---|
644 | }
|
---|
645 |
|
---|
646 | if (defined($brs_rec->{TEXTB}))
|
---|
647 | {
|
---|
648 | my $desc_textb = "<h3>Comments</h3>$brs_rec->{TEXTB}";
|
---|
649 | $doc_obj->add_utf8_text($cursection, $desc_textb);
|
---|
650 | }
|
---|
651 |
|
---|
652 | my $full_text = "";
|
---|
653 | $full_text .= "$brs_rec->{TEXTA}\n" if (defined($brs_rec->{TEXTA}));
|
---|
654 | $full_text .= "$brs_rec->{TEXTE}\n" if (defined($brs_rec->{TEXTE}));
|
---|
655 | $full_text .= "$brs_rec->{TEXTB}\n" if (defined($brs_rec->{TEXTB}));
|
---|
656 |
|
---|
657 | my @zz_list = ( "zzPG", "zzLO", "zzN" );
|
---|
658 | my $zz;
|
---|
659 | foreach $zz ( @zz_list)
|
---|
660 | {
|
---|
661 | if (defined($brs_rec->{$zz}))
|
---|
662 | {
|
---|
663 | my $filtered_text = "";
|
---|
664 |
|
---|
665 | my $name;
|
---|
666 | foreach $name (@{$brs_rec->{$zz}})
|
---|
667 | {
|
---|
668 | my @split_zz = split(' ',$name);
|
---|
669 | map { $filtered_text .= "$_ " if ($_ =~ m/^xx/) } @split_zz
|
---|
670 | }
|
---|
671 |
|
---|
672 | $full_text .= "$filtered_text\n";
|
---|
673 | }
|
---|
674 | }
|
---|
675 |
|
---|
676 | # format zz fields (tail end of record)
|
---|
677 | my $zz_html = "<table>\n";
|
---|
678 |
|
---|
679 | my $pot_zz;
|
---|
680 | foreach $pot_zz (keys %{$brs_rec})
|
---|
681 | {
|
---|
682 | if ($pot_zz =~ m/^zz/)
|
---|
683 | {
|
---|
684 | my $zz = $pot_zz;
|
---|
685 | my $name;
|
---|
686 | foreach $name (@{$brs_rec->{$zz}})
|
---|
687 | {
|
---|
688 | if ($zz eq "zzN") {
|
---|
689 | my $safe_name = $name;
|
---|
690 | &ghtml::urlsafe ($safe_name);
|
---|
691 | $zz_html .= "<tr><td><b>$zz:</b></td><td><a href=\"_httpquerypeople_&q=$safe_name\">$name</a></td></tr>\n";
|
---|
692 | } elsif ($zz =~ /^zzA[BN]$/) {
|
---|
693 | my $safe_name = $name;
|
---|
694 | &ghtml::urlsafe ($safe_name);
|
---|
695 | $zz_html .= "<tr><td><b>$zz:</b></td><td><a href=\"_httpqueryzzabn_&q=$safe_name\">$name</a></td></tr>\n";
|
---|
696 |
|
---|
697 | } else {
|
---|
698 | $zz_html .= "<tr><td><b>$zz:</b></td><td>$name</td></tr>\n";
|
---|
699 | }
|
---|
700 | }
|
---|
701 | }
|
---|
702 | }
|
---|
703 | $zz_html .= "</table>\n";
|
---|
704 | $doc_obj->add_utf8_text($cursection, $zz_html);
|
---|
705 |
|
---|
706 | # add OID - we'll use the catalog number (hoping it's unique)
|
---|
707 | my $cat_num = $brs_rec->{'CATN'};
|
---|
708 | if (!defined $cat_num) {
|
---|
709 | die "bugger!!\n";
|
---|
710 | }
|
---|
711 | if (defined ($cat_num_list{$cat_num})) {
|
---|
712 | print $outhandle "WARNING: catalog number $cat_num used more than once\n";
|
---|
713 | }
|
---|
714 | $doc_obj->set_OID ("bbc" . $cat_num);
|
---|
715 | $cat_num_list{$cat_num} = 1;
|
---|
716 |
|
---|
717 | # process the document
|
---|
718 | $processor->process($doc_obj);
|
---|
719 | }
|
---|
720 | else
|
---|
721 | {
|
---|
722 | print $outhandle "BRS record empty\n";
|
---|
723 | }
|
---|
724 |
|
---|
725 | }
|
---|
726 |
|
---|
727 | sub read {
|
---|
728 | my $self = shift (@_);
|
---|
729 | my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs) = @_;
|
---|
730 | my $outhandle = $self->{'outhandle'};
|
---|
731 |
|
---|
732 | my $filename = &util::filename_cat($base_dir, $file);
|
---|
733 | # return 0 if $self->{'block_exp'} ne "" && $filename =~ /$self->{'block_exp'}/;
|
---|
734 | if ($filename !~ /$self->{'process_exp'}/ || !-f $filename) {
|
---|
735 | return undef;
|
---|
736 | }
|
---|
737 | # my $plugin_name = ref ($self);
|
---|
738 | $file =~ s/^[\/\\]+//; # $file often begins with / so we'll tidy it up
|
---|
739 |
|
---|
740 | # create a new document
|
---|
741 | # my $doc_obj = new doc ($filename, "indexed_doc");
|
---|
742 |
|
---|
743 | # read in file ($text will be in utf8)
|
---|
744 | # my $text = "";
|
---|
745 | # $self->read_file ($filename, \$text);
|
---|
746 |
|
---|
747 | # if ($text !~ /\w/) {
|
---|
748 | # print $outhandle "$plugin_name: ERROR: $file contains no text\n" if $self->{'verbosity'};
|
---|
749 | # return 0;
|
---|
750 | # }
|
---|
751 |
|
---|
752 | # text is always plain ascii
|
---|
753 | undef $/;
|
---|
754 | open (FILE, $filename) || die;
|
---|
755 | my $text = <FILE>;
|
---|
756 | close FILE;
|
---|
757 | $/ = "\n";
|
---|
758 |
|
---|
759 |
|
---|
760 | # include any metadata passed in from previous plugins
|
---|
761 | # note that this metadata is associated with the top level section
|
---|
762 | # $self->extra_metadata ($doc_obj, $doc_obj->get_top_section(), $metadata);
|
---|
763 |
|
---|
764 | print $outhandle "BBC Sound Archive Plug for BRS format: processing $file\n"
|
---|
765 | if $self->{'verbosity'} > 1;
|
---|
766 |
|
---|
767 | my @records = split /\*\*\* BRS DOCUMENT BOUNDARY \*\*\*\s+/, $text;
|
---|
768 | $text = "";
|
---|
769 |
|
---|
770 | foreach $record (@records) {
|
---|
771 | next if $record !~ /\w/; # first record will be empty
|
---|
772 | my $brs_rec = &read_brs_record(\$record, $file, $self->{'outhandle'});
|
---|
773 | &process_brs_record ($processor, $brs_rec, $file, $self->{'outhandle'});
|
---|
774 | }
|
---|
775 |
|
---|
776 | print $outhandle "\nNumber of BRS records = $brs_doc_count\n";
|
---|
777 | print $outhandle "Number of BRS records processed = $brs_processed_count\n";
|
---|
778 |
|
---|
779 | return 1; # processed the file
|
---|
780 | }
|
---|
781 |
|
---|
782 | sub end {
|
---|
783 | my $self = shift (@_);
|
---|
784 | my ($processor) = @_;
|
---|
785 |
|
---|
786 | $processor->close_file_output() if defined $processor;
|
---|
787 | }
|
---|
788 |
|
---|
789 | sub format_prognum {
|
---|
790 | my ($brs_rec) = @_;
|
---|
791 |
|
---|
792 | return unless defined $brs_rec->{'PRNO'};
|
---|
793 |
|
---|
794 | my $old_num = $brs_rec->{'PRNO'};
|
---|
795 |
|
---|
796 | if (defined $brs_rec->{'magazine'}) {
|
---|
797 | if ($brs_rec->{'PRNO'} =~ /^\S\S /) { # space at position 3
|
---|
798 | if ($brs_rec->{'magazine'} =~ /(\d+)/) {
|
---|
799 | # algorithm A
|
---|
800 | my $magnumber = $1;
|
---|
801 | $brs_rec->{'PRNO'} =~ /(\S\S) (\S\S)(\S+)/;
|
---|
802 | $brs_rec->{'PRNO'} = $2 . $1 . $3 . $magnumber;
|
---|
803 | } else {
|
---|
804 | # common algorithm
|
---|
805 | $brs_rec->{'PRNO'} =~ /(\S\S) (\S\S)(\S+)/;
|
---|
806 | $brs_rec->{'PRNO'} = $2 . $1 . $3;
|
---|
807 | }
|
---|
808 | }
|
---|
809 | } else {
|
---|
810 | if ($brs_rec->{'PRNO'} =~ /^\S\S / && $brs_rec->{'PRNO'} !~ /:/) { # space at position 3 and no colon
|
---|
811 | # common algorithm
|
---|
812 | $brs_rec->{'PRNO'} =~ /(\S\S) (\S\S)(\S+)/;
|
---|
813 | $brs_rec->{'PRNO'} = $2 . $1 . $3;
|
---|
814 | } elsif ($brs_rec->{'PRNO'} =~ /^(\S):(\S\S) (\S\S)(\S+)/) { # colon at position 2 and space at position 5
|
---|
815 | # algorithm B
|
---|
816 | $brs_rec->{'PRNO'} = $3 . $2 . $4 . $1;
|
---|
817 | }
|
---|
818 | }
|
---|
819 |
|
---|
820 | # if ($brs_rec->{'PRNO'} ne $old_num) {
|
---|
821 | # print STDERR "\n$old_num ... " . $brs_rec->{'PRNO'} . "\n";
|
---|
822 | # }
|
---|
823 | }
|
---|
824 |
|
---|
825 | 1;
|
---|