Brackup

 view release on metacpan or  search on metacpan

lib/Brackup/Chunker/MP3.pm  view on Meta::CPAN

                                                        file   => $file,
                                                        offset => 0,
                                                        length => $music_offset,
                                                        );
    }

    # add the music chunk (one big chunk, at least for now)
    push @chunk_list, Brackup::PositionedChunk->new(
                                                    file   => $file,
                                                    offset => $music_offset,
                                                    length => $music_size,
                                                    );

    # add the ID3v1 header chunk, if necessary:
    my $music_end = $music_offset + $music_size;
    if ($music_end != $size) {
        push @chunk_list, Brackup::PositionedChunk->new(
                                                        file   => $file,
                                                        offset => $music_end,
                                                        length => $size - $music_end,
                                                        );
    }

    return @chunk_list;
}

sub main_music_range {
    my $file = shift;
    my $size = -s $file;

    # if not an mp3, include the whole file
    unless ($file =~ /\.mp3$/i) {
        return (0, $size);
    }

    my $info = MP3::Info::get_mp3info($file);
    unless ($info && defined $info->{OFFSET}) {
        return (0, $size);
    }

    my $offset = $info->{OFFSET};
    my $tag = MP3::Info::get_mp3tag($file);
    if ($tag && $tag->{TAGVERSION} && $tag->{TAGVERSION} =~ /ID3v1/) {
        return ($offset, $size - $offset - 128);
    }
    return ($offset, $size - $offset);
}


1;

__END__

=head1 NAME

Brackup::Chunker::MP3 - an mp3-aware file chunker

=head1 ABOUT

This chunker knows about the structure of MP3 files (by using
L<MP3::Info>) and will instruct Brackup to backup the metadata and the
audio bytes separately.  That way if you re-tag your music and later
do an interative backup, you only back up the new metadata bits
(tiny).




( run in 1.884 second using v1.01-cache-2.11-cpan-98e64b0badf )