mpeghelper 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Alex Barlow
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = MpegHelper
2
+
3
+ MpegHelper is a gem, mostly for my own use that takes mp3's and mp4's performs certain tasks on them.
4
+
5
+
6
+ = Dependencies
7
+
8
+ mpgtx (For cutting, trimming mp3's)
9
+ faad (to change mp4's to mp3's)
10
+ lame (For re-enconding mp3's)
11
+ ruby-mp3info (Reading and writing mp3 tags)
12
+ MP4Info (Reading and writing mp4 tags including artwork)
13
+ rmagick and imagemagick (Getting with and playing covers)
14
+ eyed3 (For getting mp3 artwork)
15
+
16
+
17
+ = Install
18
+
19
+ To install MpegHelper simply..
20
+
21
+ gem sources -a http://gems.github.com (you only have to do this once)
22
+
23
+ sudo gem install arbarlow-mpeghelper
24
+
25
+
26
+ = Usage
27
+
28
+ Essentially there are 3 (soon to be 4) methods, theres are...
29
+
30
+ MpegHelper.mp3 (Takes an mp3 file, if it matches the bitrate given is returns tag info, if not, its converts to that bitrate then returns info)
31
+
32
+ MpegHelper.mp4_to_mp3 (Takes an mp4 file and converts it to an mp3 file of desired bitrate and keeps all info and artwork!)
33
+
34
+ MpegHelper.mp4_to_mp3_artwork_output (Does the same as above method however it also outputs the artwork to 1 or more files of the dimensions you choose)
35
+
36
+ = Examples
37
+
38
+ Assuming your in the directory of the mp3s and thats where its working...
39
+
40
+ song = MpegHelper.mp3('1.mp3', '2.mp3', '192') input, output(if transcoded), bitrate
41
+
42
+ song = MpegHelper.mp4_to_mp3('1.m4a', '1.mp3', '192') input, output, bitrate
43
+
44
+ song = MpegHelper.mp3('1.mp3', '2.mp3', '192', 'extracted-cover.jpg', [[50,50], [100,100], [200,200]]) input, output, bitrate, covername, sizes(an array of [width, height] arrays)
45
+
46
+ = Coming Soon
47
+
48
+ I'm adding the ability to cut and crop mp3's, to make samples etc.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "mpeghelper"
8
+ gem.summary = "RubyGem for converting, editing and striping mp3's and mp4's"
9
+ gem.description = "RubyGem for converting, editing and striping mp3's and mp4's"
10
+ gem.email = "alexbarlowis@me.com"
11
+ gem.homepage = "http://github.com/arbarlow/mpeghelper"
12
+ gem.authors = ["Alex Barlow"]
13
+ #gem.add_development_dependency "thoughtbot-shoulda"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "mpeghelper #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/lib/mpeghelper.rb ADDED
@@ -0,0 +1,186 @@
1
+ require 'mp3info'
2
+ require 'mp4info'
3
+ require 'rmagick'
4
+
5
+ class MpegHelper
6
+
7
+ def self.mp3(file, output, bitrate)
8
+
9
+ Mp3Info.open(file) do |mp3|
10
+
11
+ if mp3.bitrate == bitrate.to_i
12
+
13
+ song = {}
14
+ song['artist'] = mp3.tag.artist
15
+ song['album'] = mp3.tag.album
16
+ song['title'] = mp3.tag.title
17
+ song['track_no'] = mp3.tag.tracknum
18
+ song['audio_bitrate'] = mp3.bitrate
19
+ song['audio_length'] = mp3.length
20
+ song['audio_file_name'] = file
21
+ song['audio_file_size'] = File.size(file)
22
+ song['audio_content_type'] = "audio/mpeg"
23
+
24
+ return song
25
+
26
+ else
27
+ `eyeD3 -i ./ #{file}`
28
+
29
+ Dir.foreach("./") do |cover|
30
+ if cover =~ /.*\.jpeg$/
31
+ @covername = cover
32
+ elsif cover =~ /.*\.png$/
33
+ @covername = cover
34
+ elsif cover =~ /.*\.gif$/
35
+ @covername = cover
36
+ elsif cover =~ /.*\.jpg$/
37
+ @covername = cover
38
+ end
39
+ end
40
+
41
+ cover = Magick::ImageList.new(@covername)
42
+ cover.resize_to_fill!(500, 500)
43
+ cover.write(@covername)
44
+
45
+ `lame -b #{bitrate} #{file} #{output} --ti #{@covername}`
46
+
47
+ FileUtils.remove_file @covername
48
+
49
+ song = {}
50
+ song['artist'] = mp3.tag.artist
51
+ song['album'] = mp3.tag.album
52
+ song['title'] = mp3.tag.title
53
+ song['track_no'] = mp3.tag.tracknum
54
+ song['audio_bitrate'] = bitrate
55
+ song['audio_length'] = mp3.length
56
+ song['audio_file_name'] = output
57
+ song['audio_file_size'] = File.size(output)
58
+ song['audio_content_type'] = "audio/mpeg"
59
+ pictranscode = mp3.tag2.PIC
60
+
61
+ FileUtils.remove_file file
62
+
63
+ Mp3Info.open(output) do |mp3|
64
+ mp3.tag.artist = song['artist']
65
+ mp3.tag.album = song['album']
66
+ mp3.tag.title = song['title']
67
+ mp3.tag.tracknum = song['track_no']
68
+ end
69
+
70
+ return song
71
+ end
72
+ end
73
+ end
74
+
75
+
76
+ def self.mp4_to_mp3(file, output, bitrate)
77
+
78
+ io = File.new(file)
79
+
80
+ @mp4info = MP4Info.new(io)
81
+
82
+ FileUtils.mv file, "preconverted.m4a"
83
+
84
+ tempfilename = "tempcover#{Time.new.to_i}.jpg"
85
+
86
+ File.open(tempfilename, "a") { |f| f.write(@mp4info.COVR) }
87
+
88
+ cover = Magick::ImageList.new(tempfilename)
89
+ cover.resize_to_fill!(500, 500)
90
+ cover.write(tempfilename)
91
+
92
+ `faad -q -o - preconverted.m4a | lame -b #{bitrate} - #{output} --ti #{tempfilename}`
93
+
94
+ FileUtils.remove_file "preconverted.m4a"
95
+
96
+ FileUtils.remove_file tempfilename
97
+
98
+ Mp3Info.open(output) do |mp3|
99
+
100
+ mp3.tag.artist = @mp4info.ART
101
+ mp3.tag.album = @mp4info.ALB
102
+ mp3.tag.title = @mp4info.NAM
103
+ if @mp4info.TRKN[0] != nil
104
+ mp3.tag.tracknum = 0
105
+ else
106
+ mp3.tag.tracknum = @mp4info.TRKN[0]
107
+ end
108
+ mp3.tag2.PIC = @mp4info.COVR
109
+
110
+ @song = {}
111
+ @song['artist'] = mp3.tag.artist
112
+ @song['album'] = mp3.tag.album
113
+ @song['title'] = mp3.tag.title
114
+ @song['track_no'] = mp3.tag.tracknum
115
+ @song['audio_bitrate'] = bitrate
116
+ @song['audio_length'] = mp3.length
117
+ @song['audio_file_name'] = file
118
+ @song['audio_file_size'] = File.size(output)
119
+ @song['audio_content_type'] = "audio/mpeg"
120
+ end
121
+
122
+ return @song
123
+ end
124
+
125
+
126
+ def self.mp4_to_mp3_artwork_output(file, output, bitrate, covername, sizes)
127
+
128
+ io = File.new(file)
129
+
130
+ @mp4info = MP4Info.new(io)
131
+
132
+ FileUtils.mv file, "preconverted.m4a"
133
+
134
+ File.open(covername, "a") { |f| f.write(@mp4info.COVR) }
135
+
136
+ cover = Magick::ImageList.new(covername)
137
+ cover.resize_to_fill!(500, 500)
138
+ cover.write(covername)
139
+
140
+ `faad -q -o - preconverted.m4a | lame -b #{bitrate} - #{output} --ti #{covername}`
141
+
142
+ FileUtils.remove_file "preconverted.m4a"
143
+
144
+ Mp3Info.open(output) do |mp3|
145
+
146
+ mp3.tag.artist = @mp4info.ART
147
+ mp3.tag.album = @mp4info.ALB
148
+ mp3.tag.title = @mp4info.NAM
149
+ if @mp4info.TRKN[0] != nil
150
+ mp3.tag.tracknum = 0
151
+ else
152
+ mp3.tag.tracknum = @mp4info.TRKN[0]
153
+ end
154
+ mp3.tag2.PIC = @mp4info.COVR
155
+
156
+ @song = {}
157
+ @song['artist'] = mp3.tag.artist
158
+ @song['album'] = mp3.tag.album
159
+ @song['title'] = mp3.tag.title
160
+ @song['track_no'] = mp3.tag.tracknum
161
+ @song['audio_bitrate'] = bitrate
162
+ @song['audio_length'] = mp3.length
163
+ @song['audio_file_name'] = file
164
+ @song['audio_file_size'] = File.size(output)
165
+ @song['audio_content_type'] = "audio/mpeg"
166
+ end
167
+
168
+ count = 0
169
+ @song['covers'] = []
170
+
171
+ sizes.each do |width, height|
172
+ cover = Magick::ImageList.new(covername)
173
+ cover.resize_to_fill!(width, height)
174
+ cover.write("#{width}x#{height}-#{covername}")
175
+ @song['covers'] << "#{width}x#{height}-#{covername}"
176
+ end
177
+
178
+ FileUtils.remove_file covername
179
+
180
+ return @song
181
+ end
182
+
183
+ end
184
+
185
+
186
+
@@ -0,0 +1,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mpeghelper}
8
+ s.version = "1.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alex Barlow"]
12
+ s.date = %q{2009-10-01}
13
+ s.description = %q{RubyGem for converting, editing and striping mp3's and mp4's}
14
+ s.email = %q{alexbarlowis@me.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "lib/mpeghelper.rb",
26
+ "mpeghelper.gemspec",
27
+ "test/mpeghelper_test.rb",
28
+ "test/test_helper.rb",
29
+ "version.yml"
30
+ ]
31
+ s.homepage = %q{http://github.com/arbarlow/mpeghelper}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{RubyGem for converting, editing and striping mp3's and mp4's}
36
+ s.test_files = [
37
+ "test/mpeghelper_test.rb",
38
+ "test/test_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ else
47
+ end
48
+ else
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class MpeghelperTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'mpeghelper'
8
+
9
+ class Test::Unit::TestCase
10
+ end
data/version.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 1
3
+ :major: 1
4
+ :minor: 2
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mpeghelper
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Barlow
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-01 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: RubyGem for converting, editing and striping mp3's and mp4's
17
+ email: alexbarlowis@me.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - lib/mpeghelper.rb
32
+ - mpeghelper.gemspec
33
+ - test/mpeghelper_test.rb
34
+ - test/test_helper.rb
35
+ - version.yml
36
+ has_rdoc: true
37
+ homepage: http://github.com/arbarlow/mpeghelper
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: RubyGem for converting, editing and striping mp3's and mp4's
64
+ test_files:
65
+ - test/mpeghelper_test.rb
66
+ - test/test_helper.rb