Class: Tagger
- Inherits:
-
Object
- Object
- Tagger
- Defined in:
- lib/rupeepeethree/tagger.rb
Class Method Summary collapse
-
.clear(mp3) ⇒ Object
clear all tags.
- .print_tags(mp3) ⇒ Object
- .tag(mp3, tags) ⇒ Object
Class Method Details
.clear(mp3) ⇒ Object
clear all tags
41 42 43 44 45 |
# File 'lib/rupeepeethree/tagger.rb', line 41 def self.clear(mp3) TagLib::MPEG::File.open(mp3) do |f| f.strip end end |
.print_tags(mp3) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rupeepeethree/tagger.rb', line 47 def self.(mp3) result = "" TagLib::MPEG::File.open(mp3) do |f| t = f.id3v2_tag result << "title: #{t.title}\n" result << "artist: #{t.artist}\n" result << "album: #{t.album}\n" result << "track number: #{t.track}\n" result << "year: #{t.year}\n" t.frame_list('APIC').each do |cover| result << "image: [#{cover.mime_type}] [#{cover.picture.length} bytes]\n" end prop = f.audio_properties if prop result << "Bitrate: #{prop.bitrate}\n" result << "Channels: #{prop.channels}\n" result << "Sample Rate: #{prop.sample_rate}\n" result << "Length: #{sprintf("%.2f", prop.length/60.0)}\n" end end return result end |
.tag(mp3, tags) ⇒ Object
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 |
# File 'lib/rupeepeethree/tagger.rb', line 5 def self.tag(mp3,) TagLib::MPEG::File.open(mp3) do |f| t = f.id3v2_tag || TagLib::ID3v2::Tag.new if [:title] t.title = [:title] end if [:artist] t.artist = [:artist] end if [:album] t.album = [:album] end if [:year] t.year = [:year].to_i end if [:track] t.track = [:track].to_i end if [:picture] image_file = File.([:picture]) # delete old frame if it exists cover = t.frame_list('APIC').first if cover t.remove_frame(cover) end cover = TagLib::ID3v2::AttachedPictureFrame.new cover.mime_type = mime_type(image_file) cover.type = TagLib::ID3v2::AttachedPictureFrame::FrontCover cover.picture = File.open(image_file,"rb"){|f|f.read} t.add_frame(cover) end f.save end end |