Skip to content

Instantly share code, notes, and snippets.

@maruks
Created December 7, 2013 22:24
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 maruks/7850064 to your computer and use it in GitHub Desktop.
Save maruks/7850064 to your computer and use it in GitHub Desktop.
WAV->MP3 encoding/tagging script
!/usr/bin/env ruby
if ARGV.length < 4
puts "Usage: enc-mp3 artist year album picture"
exit
end
artist = ARGV[0]
date = ARGV[1]
album = ARGV[2]
picture = ARGV[3]
unless File.file?(picture)
puts "picture file #{picture} not found"
exit
end
puts "artist: #{artist}"
puts "date: #{date}"
puts "album: #{album}"
puts "picture: #{picture}"
def encode (file, artist, date, album, picture)
match = file.match /(\d+)\s+([^\.]+)\.wav/
if match
num = match[1].to_i
title = match[2]
tags = "--ti \"#{picture}\" --tt \"#{title}\" --tn #{num} --ty \"#{date}\" --tl \"#{album}\" --ta \"#{artist}\""
cmd = "lame #{tags} --preset insane -q 0 \"#{file}\""
puts cmd
res = %x[ #{cmd} ]
puts res
else
puts "NO MATCH #{file}"
end
end
files = Dir.entries(Dir.pwd)
files.each{ |f| encode(f, artist, date, album, picture) if File.file?(f) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment