musicfix

music file renamer and tagger
git clone git://git.2f30.org/musicfix.git
Log | Files | Refs | README | LICENSE

commit 3291397c8b5c4b6d468a305666914d1110e78f3c
parent 639891b3378a9408aa8fa25f605b5945c0e0f337
Author: Lazaros Koromilas <lostd@2f30.org>
Date:   Sun,  4 Mar 2018 17:08:49 +0200

Clear tags and images before adding our own

Diffstat:
bin/musicfix | 76+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 75 insertions(+), 1 deletion(-)

diff --git a/bin/musicfix b/bin/musicfix @@ -162,6 +162,75 @@ def flatten_if_one ary end end +# Remove all tags and images for supported formats +def rmtags fname + TagLib::MPEG::File.open(fname) do |file| + tag = file.id3v2_tag + tag and tag.frame_list.each do |frame| + tag.remove_frame frame + end + tag = file.id3v1_tag + if tag then + tag.artist = nil + tag.album = nil + tag.title = nil + tag.track = 0 + tag.year = 0 + tag.genre = nil + tag.comment = nil + end + file.save + end + TagLib::MP4::File.open(fname) do |file| + tag = file.tag + tag and tag.item_list_map.clear + file.save + end + TagLib::Ogg::Vorbis::File.open(fname) do |file| + tag = file.tag + tag and tag.field_list_map.each do |field| + tag.remove_field field[0] + end + file.save + end + TagLib::FLAC::File.open(fname) do |file| + tag = file.xiph_comment + tag and tag.field_list_map.each do |field| + tag.remove_field field[0] + end + tag = file.id3v2_tag + tag and tag.frame_list.each do |frame| + tag.remove_frame frame + end + tag = file.id3v1_tag + if tag then + tag.artist = nil + tag.album = nil + tag.title = nil + tag.track = 0 + tag.year = 0 + tag.genre = nil + tag.comment = nil + end + file.remove_pictures + file.save + end + TagLib::RIFF::AIFF::File.open(fname) do |file| + tag = file.tag + tag and tag.frame_list.each do |frame| + tag.remove_frame frame + end + file.save + end + TagLib::RIFF::WAV::File.open(fname) do |file| + tag = file.tag + tag and tag.frame_list.each do |frame| + tag.remove_frame frame + end + file.save + end +end + # Parse command line usage = '' usage << "Usage: musicfix [fake] relid\n" @@ -403,7 +472,8 @@ end # Loop over the music files and # 1. Copy them over with proper names -# 2. Fix the tags on the new files +# 2. Clear all tags and stored images +# 3. Fix the tags on the new files tn = 0 fl.each do |ofname| tn = tn.next @@ -422,8 +492,12 @@ fl.each do |ofname| trk['file'] = nfname STDERR.puts "Copy track to #{nfname}" unless fake + # Copy FileUtils.makedirs(File.dirname nfname) FileUtils.copy(ofname, nfname) + # Clear + rmtags nfname + # Fix TagLib::FileRef.open(nfname) do |f| f.tag.artist = a f.tag.album = b