Skip to content

Instantly share code, notes, and snippets.

@glejeune
Created December 16, 2011 21: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 glejeune/1488042 to your computer and use it in GitHub Desktop.
Save glejeune/1488042 to your computer and use it in GitHub Desktop.
My simple ID3v2 tag editor
#!/usr/bin/ruby
require 'rubygems'
require 'mp3info'
require 'readline'
TAGS = {
"AENC" => "Audio encryption",
"APIC" => "Attached picture",
"COMM" => "Comments",
"COMR" => "Commercial frame",
"ENCR" => "Encryption method registration",
"EQUA" => "Equalization",
"ETCO" => "Event timing codes",
"GEOB" => "General encapsulated object",
"GRID" => "Group identification registration",
"IPLS" => "Involved people list",
"LINK" => "Linked information",
"MCDI" => "Music CD identifier",
"MLLT" => "MPEG location lookup table",
"OWNE" => "Ownership frame",
"PRIV" => "Private frame",
"PCNT" => "Play counter",
"POPM" => "Popularimeter",
"POSS" => "Position synchronisation frame",
"RBUF" => "Recommended buffer size",
"RVAD" => "Relative volume adjustment",
"RVRB" => "Reverb",
"SYLT" => "Synchronized lyric/text",
"SYTC" => "Synchronized tempo codes",
"TALB" => "Album/Movie/Show title",
"TBPM" => "BPM (beats per minute)",
"TCOM" => "Composer",
"TCON" => "Content type",
"TCOP" => "Copyright message",
"TDAT" => "Date",
"TDLY" => "Playlist delay",
"TENC" => "Encoded by",
"TEXT" => "Lyricist/Text writer",
"TFLT" => "File type",
"TIME" => "Time",
"TIT1" => "Content group description",
"TIT2" => "Title/songname/content description",
"TIT3" => "Subtitle/Description refinement",
"TKEY" => "Initial key",
"TLAN" => "Language(s)",
"TLEN" => "Length",
"TMED" => "Media type",
"TOAL" => "Original album/movie/show title",
"TOFN" => "Original filename",
"TOLY" => "Original lyricist(s)/text writer(s)",
"TOPE" => "Original artist(s)/performer(s)",
"TORY" => "Original release year",
"TOWN" => "File owner/licensee",
"TPE1" => "Lead performer(s)/Soloist(s)",
"TPE2" => "Band/orchestra/accompaniment",
"TPE3" => "Conductor/performer refinement",
"TPE4" => "Interpreted, remixed, or otherwise modified by",
"TPOS" => "Part of a set",
"TPUB" => "Publisher",
"TRCK" => "Track number/Position in set",
"TRDA" => "Recording dates",
"TRSN" => "Internet radio station name",
"TRSO" => "Internet radio station owner",
"TSIZ" => "Size",
"TSRC" => "ISRC (international standard recording code)",
"TSSE" => "Software/Hardware and settings used for encoding",
"TYER" => "Year",
"TXXX" => "User defined text information frame",
"UFID" => "Unique file identifier",
"USER" => "Terms of use",
"USLT" => "Unsychronized lyric/text transcription",
"WCOM" => "Commercial information",
"WCOP" => "Copyright/Legal information",
"WOAF" => "Official audio file webpage",
"WOAR" => "Official artist/performer webpage",
"WOAS" => "Official audio source webpage",
"WORS" => "Official internet radio station homepage",
"WPAY" => "Payment",
"WPUB" => "Publishers official webpage",
"WXXX" => "User defined URL link frame"
}
mp3 = ARGV[0]
def help
puts <<HELP
id3editor
Commands :
- info : display file info
- list : list availables ID3v2 tags
- quit : save and quit
- help : display this page
Usage :
To change a tag value, use :
> TAG = value
where TAG is a valid ID3v2 tag
Most common tags : TABL, TPE1, TIT2
Licence :
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Grégoire Lejeune <gregoire.lejeune@free.fr>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public License, Version 2, as published by Sam Hocevar. See
http://sam.zoy.org/wtfpl/COPYING for more details.
HELP
end
def show(tag2)
tag2.each do |k, v|
puts "(#{k}) #{TAGS[k]} : #{v}"
end
end
Mp3Info.open(mp3) do |info|
help
while cmd = Readline.readline('> ', true)
cmd.chomp!
cmd.strip!
break if cmd =~ /quit/
if cmd =~ /list/
TAGS.each do |k, v|
puts "#{k} : #{v}"
end
elsif cmd =~ /info/
show(info.tag2)
elsif cmd =~ /help/
help
else
data = nil
if r = /^([^\=]*)=(.*$)/.match(cmd)
cmd = r[1].strip
data = r[2].strip
end
if TAGS.keys.include?(cmd)
unless data.nil?
info.tag2[cmd] = data
end
puts "#{TAGS[cmd]} : #{info.tag2[cmd]}"
else
puts "Unknow tag #{cmd}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment