jseifer (owner)

Revisions

gist: 45254 Download_button fork
public
Public Clone URL: git://gist.github.com/45254.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# This is my Rails Envy mp3 tagger script because I'm too lazy to do it every week manually.
 
require 'rubygems'
require 'id3lib'
require 'optparse'
require 'pp'
 
app = Hash.new
 
opts = OptionParser.new do |opts|
  opts.banner = "Usage: id3tagger.rb [options]"
  opts.separator ""
  opts.separator "Specific options:"
  
  opts.on("-f", "--file MP3", "File is required") do |opt|
    app[:file] = opt
  end
  
  opts.on('-e', '--episode NUM', 'Episode Number') do |opt|
    app[:episode] = opt
  end
  
  opts.on('-d', '--date DATE', 'Date') do |opt|
    app[:date] = opt
  end
end
 
begin
  opts.parse!(ARGV)
rescue OptionParser::ParseError => e
  puts e
end
 
 
# Load a tag from a file
tag = ID3Lib::Tag.new(File.join(File.expand_path(File.dirname(__FILE__), app[:file])))
 
# Get and set text frames with convenience methods
tag.title = "Rails Envy Podcast - Episode ##{app[:episode]} - #{app[:date]}"
tag.album = "Rails Envy Podcast"
tag.track = app[:episode]
tag.genre = "Podcast"
 
# Remove all comment frames
tag.delete_if{ |frame| frame[:id] == :COMM }
 
# Get info about APIC frame to see which fields are allowed
ID3Lib::Info.frame(:APIC)
 
# Add an attached picture frame
cover = {
  :id => :APIC,
  :mimetype => 'image/jpeg',
  :picturetype => 3,
  :description => 'Rails Envy Podcast',
  :textenc => 0,
  :data => File.read(File.expand_path(File.dirname(__FILE__) + '/podcast.jpg'))
}
tag << cover
 
if tag.update!
  puts "Succesfully updated tag"
else
  puts "Did not update tag!"
end