flac2mp3 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.3.2 2008-11-29
2
+
3
+ * 3 enhancements:
4
+ * Added command-line option for only converting metadata
5
+ * Added new command for metadata conversion
6
+ * Added class method for metadata conversion
7
+
1
8
  == 0.3.1 2008-10-17
2
9
 
3
10
  * 1 enhancement:
data/Manifest.txt CHANGED
@@ -4,6 +4,7 @@ Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
6
  bin/flac2mp3
7
+ bin/metaflac2mp3
7
8
  config/hoe.rb
8
9
  config/requirements.rb
9
10
  lib/flac2mp3.rb
@@ -14,6 +15,7 @@ script/generate
14
15
  setup.rb
15
16
  spec/flac2mp3_command_spec.rb
16
17
  spec/flac2mp3_spec.rb
18
+ spec/metaflac2mp3_command_spec.rb
17
19
  spec/spec.opts
18
20
  spec/spec_helper.rb
19
21
  tasks/deployment.rake
data/README.txt CHANGED
@@ -1,12 +1,60 @@
1
- flac2mp3 is meant to, as the name implies, convert FLAC files to MP3 files.
1
+ = flac2mp3
2
2
 
3
- It presently requires the `flac` and `lame` binaries to execute, as those are used for the actual conversion.
4
- It moves tags using the flacinfo-rb and ruby-mp3info gems.
3
+ == DESCRIPTION:
5
4
 
6
- flac2mp3 operates on one file at a time. To convert more, try something like
5
+ flac2mp3 is meant to, as the name implies, convert FLAC files to MP3 files
6
+
7
+ == FEATURES/PROBLEMS:
8
+
9
+ * Will convert a file from FLAC to MP3 format, natch.
10
+ * Not *only* is the song data converted, but so is the metadata!
11
+ * Options:
12
+ * silent running
13
+ * delete the FLAC after conversion
14
+ * MP3 encoding (defaults to --preset standard)
15
+ * Reads options from YAML config file, ~/.flac2mp3
16
+
17
+ Currently operates on one file at a time. To convert more, try something like
7
18
 
8
19
  for f in *.flac; do flac2mp3 "$f"; done
9
20
 
10
21
  or
11
22
 
12
23
  find . -name '*.flac' -exec flac2mp3 {} \;
24
+
25
+ If neither of those commands will work for you, try using a different OS.
26
+
27
+ == SYNOPSIS:
28
+
29
+ $ flac2mp3 flac_filename
30
+ $ flac2mp3 flac_filename --silent
31
+ $ flac2mp3 --meta flac_filename mp3_filename
32
+ (or)
33
+ $ metaflac2mp3 flac_filename mp3_filename
34
+
35
+ or, if you insist
36
+
37
+ require 'flac2mp3'
38
+
39
+ Flac2mp3.convert(flac_filename)
40
+ Flac2mp3.convert(flac_filename, :silent => true)
41
+ Flac2mp3.convert_metadata(flac_filename, mp3_filename)
42
+
43
+
44
+ == REQUIREMENTS:
45
+
46
+ * flac, the binary
47
+ * lame, the binary
48
+ * flacinfo-rb, the gem
49
+ * ruby-mp3info, the gem
50
+ * ruby, the interpreter
51
+
52
+ == INSTALL:
53
+
54
+ * gem install flac2mp3
55
+
56
+ == THANKS:
57
+
58
+ * Rich Lafferty, for turning me on to the wonderful idea of keeping everything in FLAC format
59
+ * Apple, for having a bunch of little-i, capital-letter products that don't like FLAC format
60
+ * Robin Bowes, for flac2mp3.pl, which annoyed me enough to get me to write this
data/bin/flac2mp3 CHANGED
@@ -11,12 +11,10 @@ end
11
11
 
12
12
  require 'optparse'
13
13
  require 'flac2mp3'
14
- require 'flac2mp3/version'
15
-
16
- # NOTE: the option -p/--path= is given as an example, and should probably be replaced in your application.
17
14
 
18
15
  OPTIONS = {}
19
16
  MANDATORY_OPTIONS = %w[]
17
+ meta = false
20
18
 
21
19
  parser = OptionParser.new do |opts|
22
20
  opts.banner = <<BANNER
@@ -26,13 +24,15 @@ Options are:
26
24
  BANNER
27
25
  opts.separator ''
28
26
  opts.on('-v', '--version',
29
- "Show the #{File.basename($0)} version number and exit") { puts "flac2mp3 #{Flac2mp3::VERSION::STRING}"; exit }
27
+ "Show the #{File.basename($0)} version number and exit") { require 'flac2mp3/version'; puts "flac2mp3 #{Flac2mp3::VERSION::STRING}"; exit }
30
28
  opts.on('-d', '--[no-]delete',
31
29
  "Delete the original file after conversion") { |delete| OPTIONS[:delete] = delete }
32
30
  opts.on('-s', '--silent',
33
31
  "Don't show progress") { |silent| OPTIONS[:silent] = silent }
34
32
  opts.on('-e', '--encoding=ENCODING', String,
35
33
  "Set lame encoding options", "Default: #{Flac2mp3.default_encoding}") { |encoding| OPTIONS[:encoding] = encoding }
34
+ opts.on('-m', '--meta',
35
+ 'Convert metadata (requires a second filename)') { meta = true }
36
36
  opts.on('-h', '--help',
37
37
  'Show this help message.') { puts opts; exit }
38
38
  opts.parse!(ARGV)
@@ -45,9 +45,19 @@ end
45
45
  # do stuff
46
46
  filename = ARGV[0]
47
47
 
48
- unless filename
49
- puts "Usage: #{File.basename($0)} [filename]"
50
- exit
51
- end
48
+ if meta
49
+ mp3file = ARGV[1]
50
+ unless filename and mp3file
51
+ puts "Usage: #{File.basename($0)} --meta [filename] [mp3file]"
52
+ exit
53
+ end
54
+
55
+ Flac2mp3.convert_metadata(filename, mp3file)
56
+ else
57
+ unless filename
58
+ puts "Usage: #{File.basename($0)} [filename]"
59
+ exit
60
+ end
52
61
 
53
- Flac2mp3.convert(filename, OPTIONS)
62
+ Flac2mp3.convert(filename, OPTIONS)
63
+ end
data/bin/metaflac2mp3 ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-11-29.
4
+ # Copyright (c) 2008. All rights reserved.
5
+
6
+ begin
7
+ require 'rubygems'
8
+ rescue LoadError
9
+ # no rubygems to load, so we fail silently
10
+ end
11
+
12
+ require 'optparse'
13
+ require 'flac2mp3'
14
+
15
+ OPTIONS = {}
16
+ MANDATORY_OPTIONS = %w[]
17
+
18
+ parser = OptionParser.new do |opts|
19
+ opts.banner = <<BANNER
20
+ Usage: #{File.basename($0)} [filename] [mp3file]
21
+
22
+ Options are:
23
+ BANNER
24
+ opts.separator ''
25
+ opts.on('-v', '--version',
26
+ "Show the #{File.basename($0)} version number and exit") { require 'flac2mp3/version'; puts "metaflac2mp3 #{Flac2mp3::VERSION::STRING}"; exit }
27
+ opts.on('-h', '--help',
28
+ 'Show this help message.') { puts opts; exit }
29
+ opts.parse!(ARGV)
30
+
31
+ if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
32
+ puts opts; exit
33
+ end
34
+ end
35
+
36
+ # do stuff
37
+ filename = ARGV[0]
38
+ mp3file = ARGV[1]
39
+
40
+ unless filename and mp3file
41
+ puts "Usage: #{File.basename($0)} [filename] [mp3file]"
42
+ exit
43
+ end
44
+
45
+ Flac2mp3.convert_metadata(filename, mp3file)
@@ -2,7 +2,7 @@ class Flac2mp3 #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/flac2mp3.rb CHANGED
@@ -113,6 +113,10 @@ class Flac2mp3
113
113
  new(options).convert(filename)
114
114
  end
115
115
 
116
+ def convert_metadata(infile, outfile)
117
+ new.convert_metadata(infile, outfile)
118
+ end
119
+
116
120
  def tag_mapping
117
121
  {
118
122
  :album => :album,
@@ -10,7 +10,9 @@ describe 'flac2mp3 command' do
10
10
  end
11
11
 
12
12
  before :each do
13
- Flac2mp3.stubs(:convert)
13
+ @convert_state = states('convert').starts_as('setup')
14
+ Flac2mp3.stubs(:convert).when(@convert_state.is('setup'))
15
+ Flac2mp3.stubs(:convert_metadata)
14
16
 
15
17
  [:ARGV, :OPTIONS, :MANDATORY_OPTIONS].each do |const|
16
18
  Object.send(:remove_const, const) if Object.const_defined?(const)
@@ -80,4 +82,36 @@ describe 'flac2mp3 command' do
80
82
  Flac2mp3.expects(:convert).with(anything, Not(has_key(:encoding)))
81
83
  run_command('blah')
82
84
  end
85
+
86
+ it 'should take a --meta option to convert metadata' do
87
+ lambda { run_command('--meta', 'blah.flac', 'something.mp3') }.should_not raise_error(OptionParser::InvalidOption)
88
+ end
89
+
90
+ describe 'when converting metadata' do
91
+ before :each do
92
+ @infile = 'blah.flac'
93
+ @outfile = 'something.mp3'
94
+ end
95
+
96
+ it 'should require two filenames' do
97
+ self.expects(:puts) { |text| text.match(/usage.+filename/i) }
98
+ run_command('--meta', @infile)
99
+ end
100
+
101
+ it 'should pass the filenames to Flac2mp3 for metadata conversion' do
102
+ Flac2mp3.expects(:convert_metadata).with(@infile, @outfile)
103
+ run_command('--meta', @infile, @outfile)
104
+ end
105
+
106
+ it 'should not attempt to convert any files' do
107
+ @convert_state.become('test')
108
+ Flac2mp3.expects(:convert).never.when(@convert_state.is('test'))
109
+ run_command('--meta', @infile, @outfile)
110
+ end
111
+
112
+ it 'should accept a shorthand -m option' do
113
+ Flac2mp3.expects(:convert_metadata).with(@infile, @outfile)
114
+ run_command('-m', @infile, @outfile)
115
+ end
116
+ end
83
117
  end
@@ -824,6 +824,37 @@ describe Flac2mp3 do
824
824
  end
825
825
  end
826
826
 
827
+ it 'should convert metadata' do
828
+ Flac2mp3.should respond_to(:convert_metadata)
829
+ end
830
+
831
+ describe 'when converting metadata' do
832
+ before :each do
833
+ @infile = 'test.flac'
834
+ @outfile = 'some.mp3'
835
+ @flac2mp3 = stub('flac2mp3 object', :convert_metadata => nil)
836
+ Flac2mp3.stubs(:new).returns(@flac2mp3)
837
+ end
838
+
839
+ it 'should accept two filenames' do
840
+ lambda { Flac2mp3.convert_metadata(@infile, @outfile) }.should_not raise_error(ArgumentError)
841
+ end
842
+
843
+ it 'should require two filenames' do
844
+ lambda { Flac2mp3.convert_metadata(@infile) }.should raise_error(ArgumentError)
845
+ end
846
+
847
+ it 'should instantiate a new Flac2mp3 object' do
848
+ Flac2mp3.expects(:new).returns(@flac2mp3)
849
+ Flac2mp3.convert_metadata(@infile, @outfile)
850
+ end
851
+
852
+ it 'should use the Flac2mp3 object to convert the metadata between the given files' do
853
+ @flac2mp3.expects(:convert_metadata).with(@infile, @outfile)
854
+ Flac2mp3.convert_metadata(@infile, @outfile)
855
+ end
856
+ end
857
+
827
858
  it 'should provide a tag mapping' do
828
859
  Flac2mp3.should respond_to(:tag_mapping)
829
860
  end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe 'metaflac2mp3 command' do
4
+ def run_command(*args)
5
+ Object.const_set(:ARGV, args)
6
+ begin
7
+ eval File.read(File.join(File.dirname(__FILE__), *%w[.. bin metaflac2mp3]))
8
+ rescue SystemExit
9
+ end
10
+ end
11
+
12
+ before :each do
13
+ Flac2mp3.stubs(:convert_metadata)
14
+
15
+ [:ARGV, :OPTIONS, :MANDATORY_OPTIONS].each do |const|
16
+ Object.send(:remove_const, const) if Object.const_defined?(const)
17
+ end
18
+
19
+ @infile = 'blah.flac'
20
+ @outfile = 'something.mp3'
21
+ end
22
+
23
+ it 'should exist' do
24
+ lambda { run_command(@infile, @outfile) }.should_not raise_error(Errno::ENOENT)
25
+ end
26
+
27
+ it 'should require two filenames' do
28
+ self.expects(:puts) { |text| text.match(/usage.+filename/i) }
29
+ run_command(@infile)
30
+ end
31
+
32
+ it 'should pass the filenames to Flac2mp3 for metadata conversion' do
33
+ Flac2mp3.expects(:convert_metadata).with(@infile, @outfile)
34
+ run_command(@infile, @outfile)
35
+ end
36
+
37
+ it 'should not attempt to convert any files' do
38
+ Flac2mp3.expects(:convert).never
39
+ run_command(@infile, @outfile)
40
+ end
41
+ end
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.3.1
4
+ version: 0.3.2
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-10-17 00:00:00 -05:00
12
+ date: 2008-11-29 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -66,6 +66,7 @@ description: converter for FLAC to MP3
66
66
  email: ymendel@pobox.com
67
67
  executables:
68
68
  - flac2mp3
69
+ - metaflac2mp3
69
70
  extensions: []
70
71
 
71
72
  extra_rdoc_files:
@@ -80,6 +81,7 @@ files:
80
81
  - README.txt
81
82
  - Rakefile
82
83
  - bin/flac2mp3
84
+ - bin/metaflac2mp3
83
85
  - config/hoe.rb
84
86
  - config/requirements.rb
85
87
  - lib/flac2mp3.rb
@@ -90,6 +92,7 @@ files:
90
92
  - setup.rb
91
93
  - spec/flac2mp3_command_spec.rb
92
94
  - spec/flac2mp3_spec.rb
95
+ - spec/metaflac2mp3_command_spec.rb
93
96
  - spec/spec.opts
94
97
  - spec/spec_helper.rb
95
98
  - tasks/deployment.rake
@@ -119,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
122
  requirements: []
120
123
 
121
124
  rubyforge_project: yomendel
122
- rubygems_version: 1.3.0
125
+ rubygems_version: 1.3.1
123
126
  signing_key:
124
127
  specification_version: 2
125
128
  summary: converter for FLAC to MP3