Skip to content

Instantly share code, notes, and snippets.

@maruks
Created December 7, 2013 22:20
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/7850031 to your computer and use it in GitHub Desktop.
Save maruks/7850031 to your computer and use it in GitHub Desktop.
WAV->FLAC encoding/tagging script
!/usr/bin/env ruby
if ARGV.length < 4
puts "Usage: enc-flac 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 = "-T TITLE=\"#{title}\" -T TRACKNUMBER=#{num} -T DATE=\"#{date}\" -T ALBUM=\"#{album}\" -T ARTIST=\"#{artist}\" -T ALBUMARTIST=\"#{artist}\""
cmd = "flac --picture \"#{picture}\" #{tags} --best \"#{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