Skip to content

Instantly share code, notes, and snippets.

@n0ts
Created March 13, 2010 02:02
Show Gist options
  • Save n0ts/331037 to your computer and use it in GitHub Desktop.
Save n0ts/331037 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'id3lib'
# Set file name
filename = ARGV[0]
exit unless FileTest.exists?(filename)
basename = File::basename(filename, '.mp3').scan(/.*_(.*)-(.*)/)
season = basename[0][0]
chapter = basename[0][1]
# Load a tag from a file
tag = ID3Lib::Tag.new(filename)
#p tag
#exit
# Set tag information
tag << { :id => :TPE1, :text => "FRIENDS" }
tag << { :id => :TALB, :text => "FRIENDS-#{season}" }
tag << { :id => :TIT2, :text => "FRIENDS_#{season}-#{chapter}" }
tag << { :id => :TRCK, :text => "#{chapter}/24" }
tag << { :id => :TCON, :text => "TV" }
# Add an attached picture frame
cover = {
:id => :APIC,
:mimetype => 'image/jpeg',
:picturetype => 3,
:description => '',
:textenc => 0,
:data => File.read("/Users/n0ts/Desktop/#{season}.jpg")
}
tag << cover
# Update tag information
tag.update!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment