#!/usr/bin/env ruby # Install: kid3-common require "fileutils" $stdout.sync = true files = Dir.glob("*.mp3").sort if files.empty? $stderr.puts "No .mp3 files found" exit 1 end unless File.exist?("albumart.jpg") $stderr.puts "albumart.jpg not found" exit 1 end unless File.exist?("info.txt") $stderr.puts "info.txt not found" exit 1 end info = File.read("info.txt") info =~ /^artist: (.*)$/ artist = $1 info =~ /^album: (.*)$/ album = $1 info =~ /^year: (.*)$/ date = $1 unless artist && album && date $stderr.puts "invalid info.txt format" exit 1 end #$stdout.write("Release date (YYYY-MM-DD): ") #date = gets.chomp #unless date =~ /^\d{4}-\d{2}-\d{2}$/ # $stderr.puts "Unexpected date format" # exit 1 #end files.each do |file| if file =~ /^(\d+)\s*(.*)\.mp3$/ track_number, title = $1.to_i, $2 command = %w[kid3-cli] command += ["-c", "revert", "-c", "save"] command += ["-c", %[set artist "#{artist}" 12]] command += ["-c", %[set title "#{title}" 12]] command += ["-c", %[set album "#{album}" 12]] command += ["-c", %[set date "#{date}" 12]] command += ["-c", %[set track "#{track_number}" 12]] command += ["-c", %[set picture:albumart.jpg 'Front Cover' 2]] command += ["-c", "save"] command << file system(*command) else $stderr.puts "Warning: skipping #{file}, unrecognized name format" end end