Class: Rupeepeethree::Tagger
- Inherits:
-
Object
- Object
- Rupeepeethree::Tagger
- Defined in:
- lib/rupeepeethree/tagger.rb
Defined Under Namespace
Classes: FileNotFound
Class Method Summary collapse
-
.clear(mp3) ⇒ Object
clear all tags.
- .print_tags(mp3) ⇒ Object
- .tag(mp3, tags) ⇒ Object
- .tags(mp3) ⇒ Object
Class Method Details
.clear(mp3) ⇒ Object
clear all tags
65 66 67 68 69 70 |
# File 'lib/rupeepeethree/tagger.rb', line 65 def self.clear(mp3) raise FileNotFound if !File.exist? mp3 TagLib::MPEG::File.open(mp3) do |f| f.strip end end |
.print_tags(mp3) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rupeepeethree/tagger.rb', line 72 def self.(mp3) raise FileNotFound if !File.exist? 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_in_seconds/60.0)}\n" end end return result end |
.tag(mp3, tags) ⇒ Object
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 |
# File 'lib/rupeepeethree/tagger.rb', line 7 def self.tag(mp3,) raise FileNotFound if !File.exist? 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(TagLib::MPEG::File::ID3v2) end end |
.tags(mp3) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rupeepeethree/tagger.rb', line 43 def self.(mp3) raise FileNotFound if !File.exist? mp3 hash = {} TagLib::MPEG::File.open(mp3) do |f| t = f.id3v2_tag hash[:title] = t.title hash[:artist] = t.artist hash[:album] = t.album hash[:track_number] = t.track hash[:year] = t.year properties = f.audio_properties hash[:length] = properties.length_in_seconds picture = t.frame_list("APIC").first if picture hash[:picture] = { mime_type: picture.mime_type, data: picture.picture } end end hash end |