Skip to content

Instantly share code, notes, and snippets.

@mufid
Created March 31, 2016 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mufid/84d4e3b289d746388e55c68903600a2d to your computer and use it in GitHub Desktop.
Save mufid/84d4e3b289d746388e55c68903600a2d to your computer and use it in GitHub Desktop.
Convert all file in the directory to *.FLAC
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