Created
March 31, 2016 00:58
-
-
Save mufid/84d4e3b289d746388e55c68903600a2d to your computer and use it in GitHub Desktop.
Convert all file in the directory to *.FLAC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
target = ARGV.last | |
puts "Will process: #{target}" | |
class Fixnum | |
def mb | |
self * 1024 * 1024 | |
end | |
def to_mb | |
self / 1024 / 1024 | |
end | |
end | |
to_process = [] | |
def p x | |
puts x | |
true | |
end | |
Dir.glob("./#{target}/**/*.*").each do |x| | |
next if File.size(x) < 20.mb | |
next if x.match /rar$/ | |
p "Skip #{File.basename x} because it is flac" and next if x.match /flac$/ | |
dir = File.dirname x | |
fname = File.basename x | |
pair = fname.gsub(/\..+$/, '.flac') | |
pair = File.join(dir, pair) | |
p "Skip #{File.basename x} because conversion pair exists" and next if File.exists?(pair) | |
to_process << x | |
end | |
p "These file will be processed:" | |
to_process.each do |x| | |
p x | |
end | |
p " --- START PROCESSING! ---" | |
to_process.each do |x| | |
dir = File.dirname x | |
fname = File.basename x | |
target = fname.gsub(/\..+$/, '.flac') | |
%x{ffmpeg -i "#{x}" "#{target}"} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment