blib/lib/Linux/DVB/DVBT/Utils.pm

filter: Statementstmt 71.1% 106 / 149 Branchbran 58.3% 42 / 72 Conditioncond 73.0% 19 / 26 MC/DCmcdc 60.0% 9 / 15 Subroutinesub 53.3% 8 / 15 Podpod 100% 13 / 13 totaltotal 67.9% 197 / 290 CC 50 SCAR 21.9
CC
50
Cov
68%
time2secs
20.0
timesec2secs
20.0
subtitle
12.0
CRAP 8.9
« blib/lib/Linux/DVB/DVBT/Config.pm ↑ Summary blib/lib/Linux/DVB/DVBT/Freq.pm »
1 package Linux::DVB::DVBT::Utils ;
2  
3 =head1 NAME
4  
5 Linux::DVB::DVBT::Utils - DVBT utilities
6  
7 =head1 SYNOPSIS
8  
9 use Linux::DVB::DVBT::Utils ;
10
11  
12 =head1 DESCRIPTION
13  
14 Module provides a set of useful miscellaneous utility routines used by the DVBT module. You may use them in your own scripts
15 if you wish to (I mainly use the time coversion functions in my scripts).
16  
17 =cut
18  
19  
20 11 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 11 our $VERSION = '2.07' ;
23 11 our $DEBUG = 0 ;
24  
25 11 our %CONTENT_DESC = (
26 0x10 => "Film|movie/drama (general)",
27 0x11 => "Film|detective/thriller",
28 0x12 => "Film|adventure/western/war",
29 0x13 => "Film|science fiction/fantasy/horror",
30 0x14 => "Film|comedy",
31 0x15 => "Film|soap/melodrama/folkloric",
32 0x16 => "Film|romance",
33 0x17 => "Film|serious/classical/religious/historical movie/drama",
34 0x18 => "Film|adult movie/drama",
35  
36 0x20 => "News|news/current affairs (general)",
37 0x21 => "News|news/weather report",
38 0x22 => "News|news magazine",
39 0x23 => "News|documentary",
40 0x24 => "News|discussion/interview/debate",
41  
42 0x30 => "Show|show/game show (general)",
43 0x31 => "Show|game show/quiz/contest",
44 0x32 => "Show|variety show",
45 0x33 => "Show|talk show",
46  
47 0x40 => "Sports|sports (general)",
48 0x41 => "Sports|special events (Olympic Games, World Cup etc.)",
49 0x42 => "Sports|sports magazines",
50 0x43 => "Sports|football/soccer",
51 0x44 => "Sports|tennis/squash",
52 0x45 => "Sports|team sports (excluding football)",
53 0x46 => "Sports|athletics",
54 0x47 => "Sports|motor sport",
55 0x48 => "Sports|water sport",
56 0x49 => "Sports|winter sports",
57 0x4A => "Sports|equestrian",
58 0x4B => "Sports|martial sports",
59  
60 0x50 => "Children|children's/youth programmes (general)",
61 0x51 => "Children|pre-school children's programmes",
62 0x52 => "Children|entertainment programmes for 6 to 14",
63 0x53 => "Children|entertainment programmes for 10 to 16",
64 0x54 => "Children|informational/educational/school programmes",
65 0x55 => "Children|cartoons/puppets",
66  
67 0x60 => "Music|music/ballet/dance (general)",
68 0x61 => "Music|rock/pop",
69 0x62 => "Music|serious music/classical music",
70 0x63 => "Music|folk/traditional music",
71 0x64 => "Music|jazz",
72 0x65 => "Music|musical/opera",
73 0x66 => "Music|ballet",
74  
75 0x70 => "Arts|arts/culture (without music, general)",
76 0x71 => "Arts|performing arts",
77 0x72 => "Arts|fine arts",
78 0x73 => "Arts|religion",
79 0x74 => "Arts|popular culture/traditional arts",
80 0x75 => "Arts|literature",
81 0x76 => "Arts|film/cinema",
82 0x77 => "Arts|experimental film/video",
83 0x78 => "Arts|broadcasting/press",
84 0x79 => "Arts|new media",
85 0x7A => "Arts|arts/culture magazines",
86 0x7B => "Arts|fashion",
87  
88 0x80 => "Social|social/political issues/economics (general)",
89 0x81 => "Social|magazines/reports/documentary",
90 0x82 => "Social|economics/social advisory",
91 0x83 => "Social|remarkable people",
92  
93 0x90 => "Education|education/science/factual topics (general)",
94 0x91 => "Education|nature/animals/environment",
95 0x92 => "Education|technology/natural sciences",
96 0x93 => "Education|medicine/physiology/psychology",
97 0x94 => "Education|foreign countries/expeditions",
98 0x95 => "Education|social/spiritual sciences",
99 0x96 => "Education|further education",
100 0x97 => "Education|languages",
101  
102 0xA0 => "Leisure|leisure hobbies (general)",
103 0xA1 => "Leisure|tourism/travel",
104 0xA2 => "Leisure|handicraft",
105 0xA3 => "Leisure|motoring",
106 0xA4 => "Leisure|fitness & health",
107 0xA5 => "Leisure|cooking",
108 0xA6 => "Leisure|advertizement/shopping",
109 0xA7 => "Leisure|gardening",
110  
111 0xB0 => "Special|original language",
112 0xB1 => "Special|black & white",
113 0xB2 => "Special|unpublished",
114 0xB3 => "Special|live broadcast",
115 );
116  
117 11 our %AUDIO_FLAGS = (
118 'AD' => 'is_audio_described',
119 'S' => 'is_subtitled',
120 'SL' => 'is_deaf_signed',
121 );
122  
123 11 our %CHAR_TRANSLATE ;
124  
125 #============================================================================================
126 11 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=13.9
127
128 11 foreach my $cc (0..255)
129 {
130 2816 my $chr = chr $cc ;
131 2816 my $xlt = $chr ;
132 2816 ▶ if (($cc < ord(' ')) || ($cc > ord('~') ))
Branch: 1 branch
BranchTrueFalseTotal
if ($cc < 32 or $cc > 126) 1771 1045 2816
Condition100%3/3
$cc < 32 or $cc > 126
l!l&&r!l&&!r
35214191045
MC/DC100%2/2
$cc < 32 or $cc > 126
$cc < 32 $cc > 126
Truth table100%3/3
A or B
A= $cc < 32B= $cc > 126
ABresult
1X1
011
000
133 {
134 1771 $xlt = '' ;
135 }
136 2816 $CHAR_TRANSLATE{$chr} = $xlt ;
137 }
138
139 11 $CHAR_TRANSLATE{"\n"} = ' ' ;
140 }
141  
142  
143 #============================================================================================
144  
145 =head2 Functions
146  
147 =over 4
148  
149 =cut
150  
151  
152  
153  
154 #-----------------------------------------------------------------------------
155  
156 =item B<time2mins($time)>
157  
158 Convert time (in HH:MM format) into minutes
159  
160 =cut
161  
162 sub time2mins
163 0 ▶{
Subroutine time2mins: not called CC=2 SCAR=17.9
Pod documented
164 0 my ($time) = @_ ;
165 0 my $mins=0;
166 0 ▶ if ($time =~ m/(\d+)\:(\d+)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($time =~ /(\d+)\:(\d+)/) 0 0 0
167 {
168 0 $mins = 60*$1 + $2 ;
169 }
170 0 return $mins ;
171 }
172  
173 #-----------------------------------------------------------------------------
174  
175 =item B<mins2time($mins)>
176  
177 Convert minutes into time (in HH:MM format)
178  
179 =cut
180  
181 sub mins2time
182 0 ▶{
Subroutine mins2time: not called CC=1 SCAR=6.9
Pod documented
183 0 my ($mins) = @_ ;
184 0 my $hours = int($mins/60) ;
185 0 $mins = $mins % 60 ;
186 0 my $time = sprintf "%02d:%02d", $hours, $mins ;
187 0 return $time ;
188 }
189  
190 #-----------------------------------------------------------------------------
191  
192 =item B<secs2time($secs)>
193  
194 Convert seconds into time (in HH:MM:SS format)
195  
196 =cut
197  
198 sub secs2time
199 0 ▶{
Subroutine secs2time: not called CC=1 SCAR=6.9
Pod documented
200 0 my ($secs) = @_ ;
201
202 0 my $mins = int($secs/60) ;
203 0 $secs = $secs % 60 ;
204
205 0 my $hours = int($mins/60) ;
206 0 $mins = $mins % 60 ;
207
208 0 my $time = sprintf "%02d:%02d:%02d", $hours, $mins, $secs ;
209 0 return $time ;
210 }
211  
212  
213  
214 #-----------------------------------------------------------------------------
215  
216 =item B<duration($start, $end)>
217  
218 Calculate duration in minutes between start and end times (in HH:MM format)
219  
220 =cut
221  
222 sub duration
223 0 ▶{
Subroutine duration: not called CC=2 SCAR=17.9
Pod documented
224 0 my ($start, $end) = @_ ;
225 0 my $start_mins = time2mins($start) ;
226 0 my $end_mins = time2mins($end) ;
227 0 ▶ $end_mins += 24*60 if ($end_mins < $start_mins) ;
Branch: 1 branch
BranchTrueFalseTotal
if $end_mins < $start_mins 0 0 0
228 0 my $duration_mins = $end_mins - $start_mins ;
229 0 my $duration = mins2time($duration_mins) ;
230  
231 #print STDERR "duration($start ($start_mins), $end ($end_mins)) = $duration ($duration_mins)\n" if $this->debug() ;
232  
233 0 return $duration ;
234 }
235  
236 #-----------------------------------------------------------------------------
237  
238 =item B<time2secs($time)>
239  
240 Convert time (in HH:MM, HH:MM:SS, or MM format) into seconds
241  
242 =cut
243  
244 sub time2secs
245 0 ▶{
Subroutine time2secs: not called CC=4 SCAR=30.0
Pod documented
246 0 my ($time) = @_ ;
247
248 # Default to 30mins
249 0 my $seconds = 30*60 ;
250
251 # Convert duration to seconds
252 0 ▶ if ($time =~ m/^(\d+)$/)
Branch: 3 branches
BranchTrueFalseTotal
if ($time =~ /^(\d+)$/) { } 0 0 0
elsif ($time =~ /^(\d+):(\d+):(\d+)$/) { } 0 0 0
elsif ($time =~ /^(\d+):(\d+)$/) { } 0 0 0
253 {
254 0 $seconds = 60 * $1 ;
255 }
256 elsif ($time =~ m/^(\d+):(\d+):(\d+)$/)
257 {
258 0 $seconds = (60*60 * $1) + (60 * $2) + $3 ;
259 }
260 elsif ($time =~ m/^(\d+):(\d+)$/)
261 {
262 0 $seconds = (60*60 * $1) + (60 * $2) ;
263 }
264 0 return $seconds ;
265 }
266  
267 #-----------------------------------------------------------------------------
268  
269 =item B<timesec2secs($time)>
270  
271 Convert time (in HH:MM, HH:MM:SS, or SS format) into seconds
272  
273 (i.e. if integer value is specified, treat it as a time in seconds rather than minutes)
274  
275 =cut
276  
277 sub timesec2secs
278 0 ▶{
Subroutine timesec2secs: not called CC=4 SCAR=30.0
Pod documented
279 0 my ($time) = @_ ;
280
281 # Default to 30mins
282 0 my $seconds = 30*60 ;
283
284 # Convert duration to seconds
285 0 ▶ if ($time =~ m/^(\d+)$/)
Branch: 3 branches
BranchTrueFalseTotal
if ($time =~ /^(\d+)$/) { } 0 0 0
elsif ($time =~ /^(\d+):(\d+):(\d+)$/) { } 0 0 0
elsif ($time =~ /^(\d+):(\d+)$/) { } 0 0 0
286 {
287 0 $seconds = $1 ;
288 }
289 elsif ($time =~ m/^(\d+):(\d+):(\d+)$/)
290 {
291 0 $seconds = (60*60 * $1) + (60 * $2) + $3 ;
292 }
293 elsif ($time =~ m/^(\d+):(\d+)$/)
294 {
295 0 $seconds = (60*60 * $1) + (60 * $2) ;
296 }
297 0 return $seconds ;
298 }
299  
300 #============================================================================================
301  
302 =back
303  
304 =head2 EPG Functions
305  
306 =over 4
307  
308 =cut
309  
310  
311 #-----------------------------------------------------------------------------
312  
313 =item B<text($text)>
314  
315 (Used by EPG function)
316  
317 Ensure text returned by epg() is formatted as text.
318  
319 =cut
320  
321 sub text
322 46 ▶{
Subroutine text: called CC=5 SCAR=16.1
Pod documented
323 46 my ($text) = @_ ;
324  
325 46 ▶ if ($text)
Branch: 1 branch
BranchTrueFalseTotal
if ($text) 46 0 46
326 {
327 ## if text starts with non-ascii then assume it is encrypted and skip it
328 46 ▶ if ($text =~ /^\\x([\da-fA-F]{2})/)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^\\x([\da-fA-F]{2})/) 3 43 46
329 {
330 3 my $cc = hex $1 ;
331 3 ▶ if ( ($cc < 0x20) || ($cc > 0x7e) )
Branch: 1 branch
BranchTrueFalseTotal
if ($cc < 32 or $cc > 126) 2 1 3
Condition100%3/3
$cc < 32 or $cc > 126
l!l&&r!l&&!r
111
MC/DC100%2/2
$cc < 32 or $cc > 126
$cc < 32 $cc > 126
Truth table100%3/3
A or B
A= $cc < 32B= $cc > 126
ABresult
1X1
011
000
332 {
333 2 return "" ;
334 }
335 }
336
337 44 $text =~ s/\\x([\da-fA-F]{2})/$CHAR_TRANSLATE{chr hex $1}/ge ;
338  
339 # remove newlines
340 44 $text =~ s/[\r\n]/ /g ;
341 # replace multiple whitespace
342 44 $text =~ s/\s+/ /g ;
343 # remove leading space
344 44 $text =~ s/^\s+//g ;
345 # remove trailing space
346 44 $text =~ s/\s+$//g ;
347 }
348 44 return $text ;
349 }
350  
351 #-----------------------------------------------------------------------------
352  
353 =item B<genre($cat)>
354  
355 (Used by EPG function)
356  
357 Convert category code into genre string.
358  
359 =cut
360  
361 sub genre
362 0 ▶{
Subroutine genre: not called CC=3 SCAR=24.8
Pod documented
363 0 my ($cat) = @_ ;
364  
365 0 my $genre = "" ;
366 0 ▶ if ($cat && exists($CONTENT_DESC{$cat}))
Branch: 1 branch
BranchTrueFalseTotal
if ($cat and exists $Linux::DVB::DVBT::Utils::CONTENT_DESC{$cat}) 0 0 0
Condition0%0/3
$cat and exists $Linux::DVB::DVBT::Utils::CONTENT_DESC{$cat}
!ll&&!rl&&r
000
MC/DC0%0/2
$cat and exists $Linux::DVB::DVBT::Utils::CONTENT_DESC{$cat}
$cat exists $Linux::DVB::DVBT::Utils::CONTENT_DESC{$cat}
Truth table0%0/3
A and B
A= $catB= exists $Linux::DVB::DVBT::Utils::CONTENT_DESC{$cat}
ABresult
0X0
100
111
367 {
368 0 $genre = $CONTENT_DESC{$cat} ;
369 }
370
371 0 return $genre ;
372 }
373  
374  
375  
376 #-----------------------------------------------------------------------------
377 # Usually run in the order:
378 #
379 # fix_title(\$title, \$synopsis) ;
380 # fix_synopsis(\$title, \$synopsis, \$new_program) ;
381 # fix_episodes(\$title, \$synopsis, \$episode, \$num_episodes) ;
382 # fix_audio(\$title, \$synopsis, \%flags) ;
383 # subtitle(\$synopsis, \$subtitle) ;
384  
385  
386 =item B<fix_title($title_ref, $synopsis_ref)>
387  
388 (Used by EPG function)
389  
390 Fix title when title is truncated by ellipses and the synopsis continues the title.
391  
392 For example:
393  
394 title = Julian Fellowes Investigates...
395 synopsis = ...a Most Mysterious Murder. The Case of xxxx
396
397 Returns:
398  
399 title = Julian Fellowes Investigates a Most Mysterious Murder.
400 synopsis = The Case of xxxx
401  
402 =cut
403  
404 sub fix_title
405 23 ▶{
Subroutine fix_title: called CC=7 SCAR=19.7
Pod documented
406 23 my ($title_ref, $synopsis_ref) = @_ ;
407  
408 23 ▶ return unless ($$title_ref && $$synopsis_ref) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $$title_ref and $$synopsis_ref 1 22 23
Condition66%2/3
$$title_ref and $$synopsis_ref
!ll&&!rl&&r
1022
MC/DC50%1/2
$$title_ref and $$synopsis_ref
$$title_ref $$synopsis_ref
Truth table66%2/3
A and B
A= $$title_refB= $$synopsis_ref
ABresult
0X0
100
111
409  
410 22 ▶print STDERR "fix_title(title=\"$$title_ref\", synopsis=\"$$synopsis_ref\")\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Utils::DEBUG 0 22 22
411  
412 # fix title when title is 'Julian Fellowes Investigates...'
413 # and synopsis is '...a Most Mysterious Murder. The Case of xxxxx'
414 22 ▶ if ($$synopsis_ref =~ s/^\.\.\.\s?//)
Branch: 1 branch
BranchTrueFalseTotal
if ($$synopsis_ref =~ s/^\.\.\.\s?//) 1 21 22
415 {
416 # remove trailing ... from title
417 1 $$title_ref =~ s/\.\.\.//;
418
419 # synopsis = 'a Most Mysterious Murder. The Case of xxxxx'
420 # match = 'a Most Mysterious Murder'
421 # new synopsis = 'The Case of xxxxx'
422 1 $$synopsis_ref =~ s/^(.+?)\. //;
423 1 ▶ if ($1)
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 1 0 1
424 {
425 # new title = 'Julian Fellowes Investigates a Most Mysterious Murder'
426 1 $$title_ref .= ' ' . $1;
427
428 # remove duplicate spaces
429 1 $$title_ref =~ s/ {2,}/ /;
430 }
431 }
432  
433 # Followed by ...
434 22 $$synopsis_ref =~ s/Followed by .*// ;
435
436 # Strip leading/trailing space
437 22 $$title_ref =~ s/^\s+// ;
438 22 $$title_ref =~ s/\s+$// ;
439 22 $$synopsis_ref =~ s/^\s+// ;
440 22 $$synopsis_ref =~ s/\s+$// ;
441
442
443 22 ▶print STDERR "fix_title() - END title=\"$$title_ref\", synopsis=\"$$synopsis_ref\"\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Utils::DEBUG 0 22 22
444 }
445  
446 #-----------------------------------------------------------------------------
447  
448 =item B<fix_synopsis($title_ref, $synopsis_ref, $new_prog_ref)>
449  
450 (Used by EPG function)
451  
452 Checks the synopsis for any indication that this is a new program/series.
453  
454 Examples of supported new program indication are:
455  
456 New.
457 Brand new ****.
458 All new ****.
459  
460 Also removes extraneous information like:
461  
462 Also in HD.
463  
464 =cut
465  
466 sub fix_synopsis
467 23 ▶{
Subroutine fix_synopsis: called CC=6 SCAR=18.1
Pod documented
468 23 my ($title_ref, $synopsis_ref, $new_prog_ref) = @_ ;
469  
470 23 ▶ $$synopsis_ref ||= "" ;
Condition100%2/2
$$synopsis_ref ||= ""
l!l
221
MC/DC100%1/1
$$synopsis_ref ||= ""
$$synopsis_ref
Truth table100%2/2
A
A= $$synopsis_ref
Aresult
11
00
471 23 ▶ $$new_prog_ref ||= 0 ;
Condition50%1/2
$$new_prog_ref ||= 0
l!l
023
MC/DC0%0/1
$$new_prog_ref ||= 0
$$new_prog_ref
Truth table50%1/2
A
A= $$new_prog_ref
Aresult
11
00
472  
473 23 ▶print STDERR "fix_synopsis(title=\"$$title_ref\", synopsis=\"$$synopsis_ref\")\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Utils::DEBUG 0 23 23
474  
475 # Examples:
476
477 # All New!
478 # Brand new series.
479 # New.
480 # New:
481 23 ▶ if ($$synopsis_ref =~ s%^\s*(all\s+|brand\s+){0,1}new(\s+\S+){0,1}\s*([\.\!\:\-]+\s*)%%i)
Branch: 1 branch
BranchTrueFalseTotal
if ($$synopsis_ref =~ s/^\s*(all\s+|brand\s+){0,1}new(\s+\S+){0,1}\s*([\.\!\:\-]+\s*)//i) 6 17 23
482 {
483 6 $$new_prog_ref = 1 ;
484 }
485
486 # Also in HD.
487 23 $$synopsis_ref =~ s%\s*Also in HD[\.\s]*%%i ;
488  
489 # Strip leading/trailing space
490 23 $$synopsis_ref =~ s/^\s+// ;
491 23 $$synopsis_ref =~ s/\s+$// ;
492  
493 23 ▶print STDERR "fix_synopsis() - END title=\"$$title_ref\", synopsis=\"$$synopsis_ref\", newprog=$$new_prog_ref\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Utils::DEBUG 0 23 23
494 }
495  
496  
497  
498  
499 #-----------------------------------------------------------------------------
500  
501 =item B<fix_episodes($title_ref, $synopsis_ref, $episode_ref, $num_episodes_ref)>
502  
503 (Used by EPG function)
504  
505 Checks the synopsis for mention of episodes and removes this information if found (setting
506 the $episode_ref and $num_episodes_ref refs accordingly).
507  
508 Examples of supported episode descriptions are:
509  
510 (part 1 of 7)
511 1/7
512 Episode 1 of 7
513  
514 =cut
515  
516 sub fix_episodes
517 23 ▶{
Subroutine fix_episodes: called CC=5 SCAR=16.2
Pod documented
518 23 my ($title_ref, $synopsis_ref, $episode_ref, $num_episodes_ref) = @_ ;
519  
520 23 ▶ $$synopsis_ref ||= "" ;
Condition100%2/2
$$synopsis_ref ||= ""
l!l
221
MC/DC100%1/1
$$synopsis_ref ||= ""
$$synopsis_ref
Truth table100%2/2
A
A= $$synopsis_ref
Aresult
11
00
521  
522 23 ▶print STDERR "fix_episodes(title=\"$$title_ref\", synopsis=\"$$synopsis_ref\")\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Utils::DEBUG 0 23 23
523  
524 # optional ()
525 # optional ending .
526 #
527 # "(XXX 1 of 7)"
528 # "1/7"
529 # "Episode 1 of 7."
530 # "Part 1 of 7."
531 # "(1/7)."
532
533 # (* word* dig /|\|of dig :.)*
534 23 ▶ if ($$synopsis_ref =~ s%\(*\s*\w*\s*(\d+)\s*(?:/|\\|of)\s*(\d+)[\:\.\s\)]*%%i)
Branch: 1 branch
BranchTrueFalseTotal
if ($$synopsis_ref =~ s[\(*\s*\w*\s*(\d+)\s*(?:/|\\|of)\s*(\d+)[\:\.\s\)]*][]i) 11 12 23
535 {
536 11 $$episode_ref = $1;
537 11 $$num_episodes_ref = $2;
538 }
539  
540 # Strip leading/trailing space
541 23 $$synopsis_ref =~ s/^\s+// ;
542 23 $$synopsis_ref =~ s/\s+$// ;
543
544 23 ▶print STDERR "fix_episodes() - END title=\"$$title_ref\", synopsis=\"$$synopsis_ref\", episode=$$episode_ref, num_episodes_ref=$$num_episodes_ref\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Utils::DEBUG 0 23 23
545 }
546  
547 #-----------------------------------------------------------------------------
548  
549 =item B<fix_audio($title_ref, $synopsis_ref, $flags_href)>
550  
551 (Used by EPG function)
552  
553 Searches the synopsis string and removes any audio information, adding the information
554 to the $flags HASH reference.
555  
556 The flags supported are:
557  
558 'AD' => 'is_audio_described',
559 'S' => 'is_subtitled',
560 'SL' => 'is_deaf_signed',
561  
562 =cut
563  
564 sub fix_audio
565 23 ▶{
Subroutine fix_audio: called CC=7 SCAR=19.7
Pod documented
566 23 my ($title_ref, $synopsis_ref, $flags_href) = @_ ;
567  
568 23 ▶print STDERR "fix_audio(title=\"$$title_ref\", synopsis=\"$$synopsis_ref\")\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Utils::DEBUG 0 23 23
569  
570 # extract audio described / subtitled / deaf_signed from synopsis
571 23 ▶ $$synopsis_ref ||= "" ;
Condition100%2/2
$$synopsis_ref ||= ""
l!l
221
MC/DC100%1/1
$$synopsis_ref ||= ""
$$synopsis_ref
Truth table100%2/2
A
A= $$synopsis_ref
Aresult
11
00
572 23 ▶ return unless $$synopsis_ref =~ s/\[([A-Z,]+)\][\.\s]*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $$synopsis_ref =~ s/\[([A-Z,]+)\][\.\s]*// 21 2 23
573
574 2 my $flags = $1;
575 2 foreach my $flag (split ",", $flags)
576 {
577 4 ▶ my $method = $AUDIO_FLAGS{$flag} || next; # bad data
Condition50%1/2
$Linux::DVB::DVBT::Utils::AUDIO_FLAGS{$flag} || (next)
l!l
40
MC/DC0%0/1
$Linux::DVB::DVBT::Utils::AUDIO_FLAGS{$flag} || (next)
$Linux::DVB::DVBT::Utils::AUDIO_FLAGS{$flag}
Truth table50%1/2
A
A= $Linux::DVB::DVBT::Utils::AUDIO_FLAGS{$flag}
Aresult
11
00
578 4 $flags_href->{$method} = 1;
579 }
580 2 ▶print STDERR "fix_audio() - END title=\"$$title_ref\", synopsis=\"$$synopsis_ref\"\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Utils::DEBUG 0 2 2
581 }
582  
583 #-----------------------------------------------------------------------------
584  
585 =item B<subtitle($synopsis_ref, $subtitle_ref, $genre_ref)>
586  
587 Extracts a sub-title from the synopsis. Looks for text of the format:
588  
589 Some sort of subtitle: the rest of the synopsis....
590
591 And returns the sentence before the ':' i.e.
592
593 Some sort of subtitle
594  
595 Returns empty string if not found.
596  
597 NOTE: Not to be confused with subtitling for the hard of hearing!
598  
599 =cut
600  
601 =item B<subtitle($synopsis)>
602  
603 Same as L</subtitle($synopsis_ref, $subtitle_ref, $genre_ref)> but supports old-style
604 interface.
605  
606 =cut
607  
608 sub subtitle
609 46 ▶{
Subroutine subtitle: called CC=12 SCAR=24.9
Pod documented
610 46 my ($synopsis_ref, $subtitle_ref, $genre_ref) = @_ ;
611  
612 ## Allow for old-style interface
613 46 ▶ if (!ref($synopsis_ref))
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $synopsis_ref) 23 23 46
614 {
615 23 my $synopsis = $synopsis_ref ;
616 23 $synopsis_ref = \$synopsis ;
617 }
618 46 my $subtitle = "" ;
619 46 ▶ $subtitle_ref ||= \$subtitle ;
Condition100%2/2
$subtitle_ref ||= \$subtitle
l!l
2323
MC/DC100%1/1
$subtitle_ref ||= \$subtitle
$subtitle_ref
Truth table100%2/2
A
A= $subtitle_ref
Aresult
11
00
620 46 my $genre = "" ;
621 46 ▶ $genre_ref ||= \$genre ;
Condition50%1/2
$genre_ref ||= \$genre
l!l
046
MC/DC0%0/1
$genre_ref ||= \$genre
$genre_ref
Truth table50%1/2
A
A= $genre_ref
Aresult
11
00
622  
623  
624 ## Defaults
625 46 $$genre_ref = "" ;
626 46 $$subtitle_ref = "" ;
627  
628 46 ▶print STDERR "subtitle(synopsis=\"$$synopsis_ref\")\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Utils::DEBUG 0 46 46
629  
630 46 my $restore_synopsis ;
631  
632 # Strip out "* series." from start (e.g. Drama series, Crime drama series, etc)
633 ## Check what's left of synopsis to remove any genre info
634 46 ▶ if ($$synopsis_ref =~ s/^\s*(\w+\s+){1,2}series\.\s*//i)
Branch: 1 branch
BranchTrueFalseTotal
if ($$synopsis_ref =~ s/^\s*(\w+\s+){1,2}series\.\s*//i) 1 45 46
635 {
636 1 $$genre_ref = $1 ;
637 }
638
639 ## Don't treat time(s) as start of subtitle
640 ## e.g. 4:50 from paddington
641 # "Blood Wedding (Part 1): ...."
642 46 ▶ if ($$synopsis_ref =~ s/^\s*(.+?)\:(?!\d\d)\s*//)
Branch: 1 branch
BranchTrueFalseTotal
if ($$synopsis_ref =~ s/^\s*(.+?)\:(?!\d\d)\s*//) 32 14 46
643 {
644 32 $$subtitle_ref = $1;
645 32 $restore_synopsis = ':' ;
646 }
647
648 # If none found then see if we can use a sort sentence from the start of the synopsis
649 46 ▶ if (!$$subtitle_ref)
Branch: 1 branch
BranchTrueFalseTotal
unless ($$subtitle_ref) 14 32 46
650 {
651 14 ▶ if ($$synopsis_ref =~ s/^\s*([^\.]+)\.\s*//)
Branch: 1 branch
BranchTrueFalseTotal
if ($$synopsis_ref =~ s/^\s*([^\.]+)\.\s*//) { } 12 2 14
652 {
653 12 $$subtitle_ref = $1;
654 12 $restore_synopsis = '.' ;
655 }
656 else
657 {
658 # get a limited subset
659 2 $$subtitle_ref = $$synopsis_ref ;
660 2 $$subtitle_ref =~ s/^\s+// ;
661 2 $$subtitle_ref = substr $$subtitle_ref, 0, 32 ;
662 }
663 }
664  
665 ## Check what's left of synopsis to remove any genre info
666 # Drama series.
667 46 ▶ if ($$synopsis_ref =~ s/^\s*(\w+\s+){1,2}series\.\s*//i)
Branch: 1 branch
BranchTrueFalseTotal
if ($$synopsis_ref =~ s/^\s*(\w+\s+){1,2}series\.\s*//i) 3 43 46
668 {
669 3 $$genre_ref = $1 ;
670 }
671
672
673 ## Glue subtitle back onto front of synopsis
674 46 ▶ if ($restore_synopsis)
Branch: 1 branch
BranchTrueFalseTotal
if ($restore_synopsis) 44 2 46
675 {
676 44 $$synopsis_ref = "$$subtitle_ref$restore_synopsis $$synopsis_ref" ;
677 }
678  
679 # Strip leading/trailing space
680 46 $$synopsis_ref =~ s/^\s+// ;
681 46 $$synopsis_ref =~ s/\s+$// ;
682 46 $$subtitle_ref =~ s/^\s+// ;
683 46 $$subtitle_ref =~ s/\s+$// ;
684  
685 46 ▶print STDERR "subtitle() - END synopsis=\"$$synopsis_ref\", subtitle=\"$$subtitle_ref\"\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Utils::DEBUG 0 46 46
686  
687 # return subtitle
688 46 return $$subtitle_ref ;
689 }
690  
691  
692  
693  
694  
695 # ============================================================================================
696 # END OF PACKAGE
697  
698 =back
699  
700 =cut
701  
702 11 1;
703  
« blib/lib/Linux/DVB/DVBT/Config.pm ↑ Summary blib/lib/Linux/DVB/DVBT/Freq.pm »