#!/usr/local/bin/ruby18 # Copyright 2003 by Adam Luter # This file is part of Squash, a C/Ncurses-based unix music player. # # Squash is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Squash is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Squash; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA require 'find' require 'tempfile' require 'musicdb_lib.rb' # export_info.rb will take a list of directories, and # for each music file (mp3 or ogg) it will read a # matching info file. The data in the info file is then # written to the music file. You can either add only # new key's to music files, or overwrite all existing # keys. $help = < db_info[ key ].sort) == 0 same = false break end else unless db_info.has_key?( key ) \ and (value.sort <=> db_info[ key ].sort) == 0 same = false break end end end end if same next else puts " New info ^^^" if verbose end end # Ogg and Flac commands are easier to work with if we do the adding if replace_type == "additive" and file_type == "ogg" music_info.each do |key, value| unless db_info.has_key?( key ) insert_pair( db_info, key, value ) end end end # db_info now has we need to write # We need to clear the mp3 tag if we are doing an overwrite, # and we need to always clear out the flac, ogg is cleared implicitly if replace_type == "overwrite" and file_type == "mp3" system "id3v2 -D #{filename.sq}" end if file_type == "flac" system "metaflac --remove-vc-all #{filename.sq}" end if file_type == "ogg" or file_type == "flac" if file_type == "ogg" command = "vorbiscomment -R -w -c - #{filename.sq}" else command = "metaflac --import-vc-from=- #{filename.sq}" end out = IO.popen( command, "w" ) db_info.each do |key, value| out.puts "#{key}=#{value}" end out.close else command = "id3v2 -2 " db_info.each do |key, value| next if key == "disc_total" or key == "tracknumber_total" new_key = $db_to_id3v2[key] if new_key.nil? puts "Warning didn't know what to do with #{key}" if verbose next end new_value = "" value.each do |val| if key == "disc" and db_info.has_key?( "disc_total " ) disc_total = db_info[ "disc_total" ].first val += "/" + disc_total unless disc_total.nil? end if key == "tracknumber" and db_info.has_key?( "tracknumber_total " ) tracknumber_total = db_info[ "tracknumber_total" ].first val += "/" + tracknumber_total unless tracknumber_total.nil? end new_value += "; " unless new_value.empty? new_value += val end if key == "url" # if id3v2 0.1.9 is fixed we can then add url tags # until then don't even bother # (when it is fixed, it will work like "user_text" below. next end if key == "user_text" new_value = ":" + new_value elsif key == "comment" or key == "lyrics" # remove ':' until id3v2 0.1.9 is fixed, when it is # use this line instead: # new_value = ":" + new_value + ":" new_value.gsub!(/:/, "") end command += "--#{new_key} #{new_value.sq} " end command += filename.sq system command end end end