flac2mp3 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2.7 2008-06-27
2
+
3
+ * 1 enhancement:
4
+ * Can now run in silent mode
5
+
1
6
  == 0.2.6 2008-06-25
2
7
 
3
8
  * 1 enhancement:
data/bin/flac2mp3 CHANGED
@@ -15,7 +15,7 @@ require 'flac2mp3/version'
15
15
 
16
16
  # NOTE: the option -p/--path= is given as an example, and should probably be replaced in your application.
17
17
 
18
- OPTIONS = { :delete => false }
18
+ OPTIONS = { :delete => false, :silent => false }
19
19
  MANDATORY_OPTIONS = %w[]
20
20
 
21
21
  parser = OptionParser.new do |opts|
@@ -29,7 +29,8 @@ BANNER
29
29
  "Show the #{File.basename($0)} version number and exit") { puts "flac2mp3 #{Flac2mp3::VERSION::STRING}"; exit }
30
30
  opts.on('-d', '--[no-]delete',
31
31
  "Delete the original file after conversion") { |delete| OPTIONS[:delete] = delete }
32
-
32
+ opts.on('-s', '--silent',
33
+ "Don't show progress") { |silent| OPTIONS[:silent] = silent }
33
34
  opts.on('-h', '--help',
34
35
  'Show this help message.') { puts opts; exit }
35
36
  opts.parse!(ARGV)
@@ -47,4 +48,4 @@ unless filename
47
48
  exit
48
49
  end
49
50
 
50
- Flac2mp3.convert(filename.dup, OPTIONS[:delete])
51
+ Flac2mp3.convert(filename.dup, OPTIONS)
data/lib/flac2mp3.rb CHANGED
@@ -5,17 +5,20 @@ require 'mp3info'
5
5
 
6
6
  module Flac2mp3
7
7
  class << self
8
- def convert(filename, delete_flac = false)
8
+ def convert(filename, options = {})
9
9
  raise TypeError, "'#{filename}' is not a file" unless FileTest.file?(filename)
10
10
  filename.extend(Flac2mp3::StringExtensions)
11
11
  out_filename = output_filename(filename)
12
12
  out_filename.extend(Flac2mp3::StringExtensions)
13
13
 
14
- system "flac -c -d #{filename.safequote} | lame --preset standard - #{out_filename.safequote}"
14
+ commands = { :flac => 'flac', :mp3 => 'lame' }
15
+ commands.each { |k, v| v << ' --silent' } if options[:silent]
16
+
17
+ system "#{commands[:flac]} --stdout --decode #{filename.safequote} | #{commands[:mp3]} --preset standard - #{out_filename.safequote}"
15
18
 
16
19
  mp3data(out_filename, flacdata(filename))
17
20
 
18
- File.delete(filename) if delete_flac
21
+ File.delete(filename) if options[:delete]
19
22
  end
20
23
 
21
24
  def output_filename(filename)
@@ -2,7 +2,7 @@ module Flac2mp3 #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 6
5
+ TINY = 7
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -43,22 +43,37 @@ describe 'flac2mp3 command' do
43
43
  end
44
44
 
45
45
  it 'should pass on a true flac-deletion option if specified on the command line (using --delete)' do
46
- Flac2mp3.expects(:convert).with(anything, true)
46
+ Flac2mp3.expects(:convert).with(anything, has_entry(:delete => true))
47
47
  run_command('blah', '--delete')
48
48
  end
49
49
 
50
50
  it 'should pass on a false flac-deletion option if specified on the command line (using --no-delete)' do
51
- Flac2mp3.expects(:convert).with(anything, false)
51
+ Flac2mp3.expects(:convert).with(anything, has_entry(:delete => false))
52
52
  run_command('blah', '--no-delete')
53
53
  end
54
54
 
55
55
  it 'should pass on a true flac-deletion option if specified on the command line (using -d)' do
56
- Flac2mp3.expects(:convert).with(anything, true)
56
+ Flac2mp3.expects(:convert).with(anything, has_entry(:delete => true))
57
57
  run_command('blah', '-d')
58
58
  end
59
59
 
60
60
  it 'should pass on a false flac-deletion option if nothing specified on the command line' do
61
- Flac2mp3.expects(:convert).with(anything, false)
61
+ Flac2mp3.expects(:convert).with(anything, has_entry(:delete => false))
62
+ run_command('blah')
63
+ end
64
+
65
+ it 'should pass on a true silence option if specified on the command line (using --silent)' do
66
+ Flac2mp3.expects(:convert).with(anything, has_entry(:silent => true))
67
+ run_command('blah', '--silent')
68
+ end
69
+
70
+ it 'should pass on a true silence option if specified on the command line (using -s)' do
71
+ Flac2mp3.expects(:convert).with(anything, has_entry(:silent => true))
72
+ run_command('blah', '-s')
73
+ end
74
+
75
+ it 'should pass on a false silence option if nothing specified on the command line' do
76
+ Flac2mp3.expects(:convert).with(anything, has_entry(:silent => false))
62
77
  run_command('blah')
63
78
  end
64
79
  end
@@ -49,11 +49,13 @@ describe Flac2mp3, 'when converting and given a filename belonging to a regular
49
49
  before :each do
50
50
  @filename = 'blah.flac'
51
51
  FileTest.stubs(:file?).with(@filename).returns(true)
52
- File.stubs(:delete)
53
52
  @output_filename = 'blah.mp3'
54
53
  Flac2mp3.stubs(:output_filename).with(@filename).returns(@output_filename)
55
54
  Flac2mp3.stubs(:system)
56
55
 
56
+ @filename.stubs(:safequote).returns('-blah-flac-')
57
+ @output_filename.stubs(:safequote).returns('-blah-mp3-')
58
+
57
59
  @flacdata = {}
58
60
  Flac2mp3.stubs(:flacdata).with(@filename).returns(@flacdata)
59
61
  Flac2mp3.stubs(:mp3data)
@@ -65,7 +67,6 @@ describe Flac2mp3, 'when converting and given a filename belonging to a regular
65
67
 
66
68
  it 'should extend the filename with the string extensions' do
67
69
  @filename.expects(:extend).with(Flac2mp3::StringExtensions).returns(@filename)
68
- @filename.stubs(:safequote)
69
70
  Flac2mp3.convert(@filename)
70
71
  end
71
72
 
@@ -76,15 +77,11 @@ describe Flac2mp3, 'when converting and given a filename belonging to a regular
76
77
 
77
78
  it 'should extend the output filename with the string extensions' do
78
79
  @output_filename.expects(:extend).with(Flac2mp3::StringExtensions).returns(@output_filename)
79
- @output_filename.stubs(:safequote)
80
80
  Flac2mp3.convert(@filename)
81
81
  end
82
82
 
83
83
  it 'should use system commands to convert the FLAC to an MP3' do
84
- @filename.stubs(:safequote).returns('-blah-flac-')
85
- @output_filename.stubs(:safequote).returns('-blah-mp3-')
86
- Flac2mp3.expects(:system).with("flac -c -d #{@filename.safequote} | lame --preset standard - #{@output_filename.safequote}")
87
-
84
+ Flac2mp3.expects(:system).with("flac --stdout --decode #{@filename.safequote} | lame --preset standard - #{@output_filename.safequote}")
88
85
  Flac2mp3.convert(@filename)
89
86
  end
90
87
 
@@ -94,23 +91,42 @@ describe Flac2mp3, 'when converting and given a filename belonging to a regular
94
91
  end
95
92
 
96
93
  it 'should accept an option to delete the flac' do
97
- lambda { Flac2mp3.convert('blah.flac', true) }.should_not raise_error(ArgumentError)
94
+ lambda { Flac2mp3.convert('blah.flac', :delete => true) }.should_not raise_error(ArgumentError)
98
95
  end
99
96
 
100
97
  it 'should delete the original file if given a true value for the option' do
101
98
  File.expects(:delete).with(@filename)
102
- Flac2mp3.convert(@filename, true)
99
+ Flac2mp3.convert(@filename, :delete => true)
103
100
  end
104
101
 
105
102
  it 'should not delete the original file if given a false value for the option' do
106
103
  File.expects(:delete).never
107
- Flac2mp3.convert(@filename, false)
104
+ Flac2mp3.convert(@filename, :delete => false)
108
105
  end
109
106
 
110
107
  it 'should not delete the original file by default' do
111
108
  File.expects(:delete).never
112
109
  Flac2mp3.convert(@filename)
113
110
  end
111
+
112
+ it 'should accept an option to run silently' do
113
+ lambda { Flac2mp3.convert('blah.flac', :silent => true) }.should_not raise_error(ArgumentError)
114
+ end
115
+
116
+ it 'should tell the system commands to be silent if given a true value for the option' do
117
+ Flac2mp3.expects(:system).with("flac --silent --stdout --decode #{@filename.safequote} | lame --silent --preset standard - #{@output_filename.safequote}")
118
+ Flac2mp3.convert(@filename, :silent => true)
119
+ end
120
+
121
+ it 'should not tell the system commands to be silent if given a true value for the option' do
122
+ Flac2mp3.expects(:system).with("flac --stdout --decode #{@filename.safequote} | lame --preset standard - #{@output_filename.safequote}")
123
+ Flac2mp3.convert(@filename, :silent => false)
124
+ end
125
+
126
+ it 'should not tell the system commands to be silent by default' do
127
+ Flac2mp3.expects(:system).with("flac --stdout --decode #{@filename.safequote} | lame --preset standard - #{@output_filename.safequote}")
128
+ Flac2mp3.convert(@filename)
129
+ end
114
130
  end
115
131
 
116
132
  describe Flac2mp3, 'when converting and given a filename not belonging to a regular file' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flac2mp3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yossef Mendelssohn
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-25 00:00:00 -05:00
12
+ date: 2008-06-27 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency