Line # Revision Author
1 3 ahitrov@rambler.ru package Contenido::Type::Audio;
2 #-------------------------------------------------------------------------------
3 # ��� ������ - ����� ����
4 #-------------------------------------------------------------------------------
5 # ����:
6 # 1. �������� ������� �������������� ��� wma ������
7 #-------------------------------------------------------------------------------
8 use strict;
9 use warnings;
10 use Contenido::Globals;
11 use Contenido::File;
12 use Data::Dumper qw/Dumper/;
13 use base qw/Contenido::Type::File/;
14 use MP3::Info;
15 use Audio::WMA;
16 #-------------------------------------------------------------------------------
17 # �������������� ������
18 # ����������:
19 # - ������������ ���������� (duration)
20 # - ������� (bitrate)
21 # - ������� ������������� (freq)
22 sub more_info {
23 my ($self) = @_;
24 return undef unless $self && ref $self && $self->{'ext'};
25 if ($self->{'ext'} eq 'mp3') {
26 my $info = get_mp3info($self->{'file_local'}) || return undef;
27 $self->{'duration'} = int($info->{'SECS'});
28 $self->{'bitrate'} = $info->{'BITRATE'};
29 $self->{'freq'} = $info->{'FREQUENCY'};
30 } elsif ($self->{'ext'} eq 'wma') {
31 my $wma = Audio::WMA->new($self->{'file_local'});
32 my $info = $wma->info() || return undef;
33 $self->{'duration'} = int($info->{'playtime_seconds'});
34 $self->{'bitrate'} = int($info->{'bitrate'}/1024);
35 }
36 warn (Dumper $self) if $state->development;
37 return 1;
38 }
39 #-------------------------------------------------------------------------------
40 # WMA -> MP3
41 sub wma2mp3 {
42 my ($self, %param) = @_;
43 return undef if $self->{'ext'} ne 'wma';
44 my $out_file = $param{'out_file'} || $self->{'file_local'};
45 $out_file =~s /wma$/mp3/g;
46 my $tmp_file = $state->{'tmp_dir'}.'/tmp_'.int(rand(100000)).'_'.time.'.wav';
47 my $command = 'mplayer -vo null -vc dummy -ao pcm:file='.$tmp_file.' '.$self->{'file_local'}.' && lame -m s -S '.$tmp_file.' -o '.$out_file;
48 system($command);
49 return undef unless -e $out_file;
50 unlink $self->{'file_local'} unless $param{'no_delete'};
51 unlink $tmp_file;
52 $self->{'file_local'} = $out_file;
53 $self->{'ext'} = 'mp3';
54 $self->file_info;
55 return 1;
56 }
57 #-------------------------------------------------------------------------------
58 # Change FREQUENCY 8, 12 => 11.025, 16, 24 => 22.05, 32, 48 => 44.1
59 sub change_frequency {
60 my ($self, %param) = @_;
61 my %freq_change = (
62 8 => 11.025,
63 12 => 11.025,
64 16 => 22.05,
65 24 => 22.05,
66 32 => 44.1,
67 48 => 44.1
68 );
69 return undef if $self->{'ext'} ne 'mp3';
70 return 2 unless $freq_change{$self->{'freq'}};
71 my $out_file = $param{'out_file'} || $self->{'file_local'};
72 $out_file =~s /\.mp3$/0\.mp3/i;
73 my $command = 'lame -b '.$self->{'bitrate'}.' -m s -S --resample '.$freq_change{$self->{'freq'}}.' '.$self->{'file_local'}.' -o '.$out_file;
74 system($command);
75 return undef unless -e $out_file;
76 unlink $self->{'file_local'};
77 $self->{'file_local'} = $out_file;
78 $self->file_info;
79 return 1;
80 }
81 1;