lib/mpeghelper.rb in mpeghelper-1.2.1 vs lib/mpeghelper.rb in mpeghelper-1.3.0
- old
+ new
@@ -69,12 +69,117 @@
return song
end
end
end
+
+ def self.mp3_artwork_output(file, output, bitrate, covername, sizes)
+ Mp3Info.open(file) do |mp3|
+
+ if mp3.bitrate == bitrate.to_i
+ song = {}
+ song['artist'] = mp3.tag.artist
+ song['album'] = mp3.tag.album
+ song['title'] = mp3.tag.title
+ song['track_no'] = mp3.tag.tracknum
+ song['audio_bitrate'] = mp3.bitrate
+ song['audio_length'] = mp3.length
+ song['audio_file_name'] = file
+ song['audio_file_size'] = File.size(file)
+ song['audio_content_type'] = "audio/mpeg"
+
+ `eyeD3 -i ./ #{file}`
+
+ Dir.foreach("./") do |cover|
+ if cover =~ /.*\.jpeg$/
+ @covername = cover
+ elsif cover =~ /.*\.png$/
+ @covername = cover
+ elsif cover =~ /.*\.gif$/
+ @covername = cover
+ elsif cover =~ /.*\.jpg$/
+ @covername = cover
+ end
+ end
+
+ cover = Magick::ImageList.new(@covername)
+ cover.resize_to_fill!(500, 500)
+ cover.write(@covername)
+
+ count = 0
+ song['covers'] = []
+
+ sizes.each do |width, height|
+ cover = Magick::ImageList.new(@covername)
+ cover.resize_to_fill!(width, height)
+ cover.write("#{width}x#{height}-#{covername}")
+ song['covers'] << "#{width}x#{height}-#{covername}"
+ end
+
+ return song
+
+ else
+
+ `eyeD3 -i ./ #{file}`
+
+ Dir.foreach("./") do |cover|
+ if cover =~ /.*\.jpeg$/
+ @covername = cover
+ elsif cover =~ /.*\.png$/
+ @covername = cover
+ elsif cover =~ /.*\.gif$/
+ @covername = cover
+ elsif cover =~ /.*\.jpg$/
+ @covername = cover
+ end
+ end
+
+ cover = Magick::ImageList.new(@covername)
+ cover.resize_to_fill!(500, 500)
+ cover.write(@covername)
+
+ `lame -b #{bitrate} #{file} #{output} --ti #{@covername}`
+
+ FileUtils.mv @covername, covername
+
+ song = {}
+ song['artist'] = mp3.tag.artist
+ song['album'] = mp3.tag.album
+ song['title'] = mp3.tag.title
+ song['track_no'] = mp3.tag.tracknum
+ song['audio_bitrate'] = bitrate
+ song['audio_length'] = mp3.length
+ song['audio_file_name'] = output
+ song['audio_file_size'] = File.size(output)
+ song['audio_content_type'] = "audio/mpeg"
+
+ FileUtils.remove_file file
+
+ Mp3Info.open(output) do |mp3|
+ mp3.tag.artist = song['artist']
+ mp3.tag.album = song['album']
+ mp3.tag.title = song['title']
+ mp3.tag.tracknum = song['track_no']
+ end
+
+ count = 0
+ @song['covers'] = []
+
+ sizes.each do |width, height|
+ cover = Magick::ImageList.new(covername)
+ cover.resize_to_fill!(width, height)
+ cover.write("#{width}x#{height}-#{covername}")
+ @song['covers'] << "#{width}x#{height}-#{covername}"
+ end
+
+ FileUtils.remove_file covername
+
+ return song
+ end
+
def self.mp4_to_mp3(file, output, bitrate)
io = File.new(file)
@mp4info = MP4Info.new(io)
@@ -178,9 +283,9 @@
FileUtils.remove_file covername
return @song
end
-end
-
-
-
+ def self.crop(input, output, fromtime, totime)
+ `mp3splt #{input} #{input} #{output} -o #{output}`
+ end
+end
\ No newline at end of file