| 1 | package Brackup::Chunker::MP3; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | my $HAVE_MP3_INFO; | |||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 0 | ▶ | $HAVE_MP3_INFO = eval "use MP3::Info (); 1;"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | } | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | sub chunks { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
chunks: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | my ($class, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | my @chunk_list; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | die "Required module MP3::Info not found. Needed by the MP3 file chunker.\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | unless $HAVE_MP3_INFO; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my $file_path = $file->path; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # file might've been renamed or deleted in the meantime: | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | warn "File went away: $file_path ; ignoring it.\n" unless -e $file_path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | return () unless -e $file_path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my ($music_offset, $music_size) = main_music_range($file_path); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $size = $file->size; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # add the ID3v2 header, if necessary: | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if ($music_offset != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | push @chunk_list, Brackup::PositionedChunk->new( | |||||||||||||||||||||||||||||||||||||||||
| 27 | file => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | offset => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | length => $music_offset, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # add the music chunk (one big chunk, at least for now) | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | push @chunk_list, Brackup::PositionedChunk->new( | |||||||||||||||||||||||||||||||||||||||||
| 35 | file => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | offset => $music_offset, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | length => $music_size, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # add the ID3v1 header chunk, if necessary: | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $music_end = $music_offset + $music_size; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ($music_end != $size) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | push @chunk_list, Brackup::PositionedChunk->new( | |||||||||||||||||||||||||||||||||||||||||
| 44 | file => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | offset => $music_end, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | length => $size - $music_end, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return @chunk_list; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub main_music_range { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
main_music_range: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $size = -s $file; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | # if not an mp3, include the whole file | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | unless ($file =~ /\.mp3$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return (0, $size); | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $info = MP3::Info::get_mp3info($file); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | unless ($info && defined $info->{OFFSET}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$info and defined $info->{"OFFSET"}
MC/DC0%0/2
$info and defined $info->{"OFFSET"}
$info
defined $info->{"OFFSET"}
Truth table0%0/3
A and B
A= $infoB= defined $info->{"OFFSET"}
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | return (0, $size); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $offset = $info->{OFFSET}; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $tag = MP3::Info::get_mp3tag($file); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($tag && $tag->{TAGVERSION} && $tag->{TAGVERSION} =~ /ID3v1/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$tag and $tag->{"TAGVERSION"} and $tag->{"TAGVERSION"} =~ /ID3v1/
$tag and $tag->{"TAGVERSION"}
MC/DC0%0/3
$tag and $tag->{"TAGVERSION"} and $tag->{"TAGVERSION"} =~ /ID3v1/
$tag
$tag->{"TAGVERSION"}
$tag->{"TAGVERSION"} =~ /ID3v1/
Truth table0%0/4
A and B and C
A= $tagB= $tag->{"TAGVERSION"}C= $tag->{"TAGVERSION"} =~ /ID3v1/
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return ($offset, $size - $offset - 128); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | return ($offset, $size - $offset); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||||||||||||||||