summaryrefslogtreecommitdiff
blob: 38fad9bc9abc33849972c336cf5a3d3db55dcac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
--- mp32ogg.orig	2005-01-01 15:32:32.138906448 +0000
+++ mp32ogg	2005-01-01 15:52:33.061338488 +0000
@@ -9,6 +9,8 @@
 # 0.11-gentoo
 #     * Jeremy Huddleston <eradicator@gentoo.org>:
 #       Added support for mpg321
+#     * --quality option support (from Debian 0.11-r3 release)
+#     * Non-zero exit code on failure (from Debian 0.11-r3 release)
 #
 # 0.11
 #     * Have output reflect change in license (doh)
@@ -104,8 +106,10 @@
 print "(c) 2000-2002 Nathan Walp\n";
 print "Released without warranty under the terms of the Artistic License\n\n";
 
+my $userquality=-2.0;
 
 GetOptions("help|?",\&showhelp,
+		"quality=f" => \$userquality,
 		"delete", 
 		"rename=s", 
 		"lowercase",
@@ -116,6 +120,8 @@
 sub showhelp() {
 	print "Usage: $0 [options] dir1 dir2 file1 file2 ...\n\n";
 	print "Options:\n";
+	print "--quality=[-1..10]       Set Ogg/Vorbis quality level\n";
+	print "                         Defaults to bitrate of original .mp3\n";
 	print "--delete                 Delete files after converting\n";
 	print "--rename=format          Instead of simply replacing the .mp3 with\n";
 	print "                         .ogg for the output file, produce output \n";
@@ -174,20 +180,26 @@
 	}
 
 	$mp3bitrate = $fileinfo->{BITRATE};
-	if($mp3bitrate ne "") {
-	   if($mp3bitrate > 256) {
-	      $quality = 8;
-	   } elsif($mp3bitrate > 192) {
-	      $quality = 7;
-	   } elsif($mp3bitrate > 128) {
-	      $quality = 6;
-	   } else {
-	      $quality = 5;
-	   }
+	if (($userquality < -1) || ($userquality > 10)) {
+	    # Set quality adjacent to mp3 bitrate
+	    if($mp3bitrate ne "") {
+		if($mp3bitrate > 256) {
+		    $quality = 8;
+		} elsif($mp3bitrate > 192) {
+		    $quality = 7;
+		} elsif($mp3bitrate > 128) {
+		    $quality = 6;
+		} else {
+		    $quality = 5;
+		}
+	    }
 	} else {
 	   $quality = 5;
 	   print "MP3::Info didn't report the bitrate... weird. Corrupt MP3 file? Bug?\n";
+	   # User defined quality
+	   $quality = $userquality;
 	}
+
 	if($filename eq "" ||
 		((/\%a/) && $info->{ARTIST} eq "") ||
 		((/\%t/) && $info->{TITLE} eq "") ||
@@ -276,19 +288,19 @@
 	      {
 		 warn "Conversion failed ($oggoutputfile truncated).\n";
 		 close CHECK;
-		 return;
+		 exit 1;
 	      }
 	      elsif($_ eq "header_integrity=fail\n")
 	      {
 		 warn "Conversion failed ($oggoutputfile header integrity check failed).\n";
 		 close CHECK;
-		 return;
+		 exit 1;
 	      }
 	      elsif($_ eq "stream_integrity=fail\n")
 	      {
 		 warn "Conversion failed ($oggoutputfile header integrity check failed).\n";
 		 close CHECK;
-		 return;
+		 exit 1;
 	      }
 	   }
 	   close CHECK;
@@ -300,5 +312,6 @@
 	}
 	else {
 	   warn "Conversion failed ($oggenc returned $result).\n";
+	   exit 1
 	}
 }