~ubuntu-branches/ubuntu/jaunty/gnupod-tools/jaunty

« back to all changes in this revision

Viewing changes to src/gnupod_convert_FLAC.pl

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2005-11-27 15:21:19 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051127152119-teuqxsvrrzyyf7n0
Tags: 0.98.3-1ubuntu1
Resynchronise with Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# This product is not supported/written/published by Apple!
24
24
 
25
25
use strict;
 
26
use GNUpod::FooBar;
26
27
 
27
28
 
28
29
 
29
30
my $file  = $ARGV[0] or exit(1);
30
31
my $gimme = $ARGV[1];
 
32
my $quality = $ARGV[2];
31
33
 
32
34
if(!(-r $file)) {
33
35
        warn "$file is not readable!\n";
60
62
        print "FORMAT: FLAC\n";
61
63
}
62
64
elsif($gimme eq "GET_PCM") {
63
 
        my $tmpout = get_u_path("/tmp/gnupod_pcm", "wav");
 
65
        my $tmpout = GNUpod::FooBar::get_u_path("/tmp/gnupod_pcm", "wav");
64
66
        my $status = system("flac", "-d", "-s", "$file", "-o", $tmpout);
65
67
        if($status) {
66
68
                warn "flac exited with $status, $!\n";
72
74
elsif($gimme eq "GET_MP3") {
73
75
        #Open a secure flac pipe and open anotherone for lame
74
76
        #On errors, we'll get a BrokenPipe to stout
75
 
        my $tmpout = get_u_path("/tmp/gnupod_mp3", "mp3");
 
77
        my $tmpout = GNUpod::FooBar::get_u_path("/tmp/gnupod_mp3", "mp3");
76
78
        open(FLACOUT, "-|") or exec("flac", "-d", "-s", "-c", "$file") or die "Could not exec flac: $!\n";
77
 
        open(LAMEIN , "|-") or exec("lame", "--silent", "--preset","extreme", "-", $tmpout) or die "Could not exec lame: $!\n";
 
79
        open(LAMEIN , "|-") or exec("lame", "-V", $quality, "--silent", "-", $tmpout) or die "Could not exec lame: $!\n";
78
80
        while(<FLACOUT>) {
79
81
                print LAMEIN $_;
80
82
        }
84
86
}
85
87
elsif($gimme eq "GET_AAC" or $gimme eq "GET_AACBM") {
86
88
        #Yeah! FAAC is broken and can't write to stdout..
87
 
        my $tmpout = get_u_path("/tmp/gnupod_faac", "m4a");
88
 
           $tmpout = get_u_path("/tmp/gnupod_faac", "m4b") if $gimme eq "GET_AACBM";
 
89
        my $tmpout = GNUpod::FooBar::get_u_path("/tmp/gnupod_faac", "m4a");
 
90
           $tmpout = GNUpod::FooBar::get_u_path("/tmp/gnupod_faac", "m4b") if $gimme eq "GET_AACBM";
 
91
        $quality = 140 - ($quality*10);
89
92
        open(FLACOUT, "-|") or exec("flac", "-d", "-s", "-c", "$file") or die "Could not exec flac: $!\n";
90
 
        open(FAACIN , "|-") or exec("faac", "-w", "-q", "170", "-o", $tmpout, "-") or die "Could not exec faac: $!\n";
 
93
        open(FAACIN , "|-") or exec("faac", "-w", "-q", $quality, "-o", $tmpout, "-") or die "Could not exec faac: $!\n";
91
94
        while(<FLACOUT>) { #Feed faac
92
95
                print FAACIN $_;
93
96
        }
103
106
 
104
107
exit(0);
105
108
 
106
 
#############################################
107
 
# Get Unique path
108
 
sub get_u_path {
109
 
        my($prefix, $ext) = @_;
110
 
        my $dst = undef;
111
 
        while($dst = sprintf("%s_%d_%d.$ext",$prefix, int(time()), int(rand(99999)))) {
112
 
                last unless -e $dst;
113
 
        }
114
 
        return $dst;
115
 
}