Class: UnitF::Tag::FLAC

Inherits:
File
  • Object
show all
Defined in:
lib/unitf/tag/flac.rb

Instance Attribute Summary

Attributes inherited from File

#dirname, #extname, #path, #realpath

Instance Method Summary collapse

Methods inherited from File

#auto_cover!, #auto_tag!, #auto_tags, #close, #cover_available?, #cover_path, #flac?, #format_json, #format_line, #mp3?, #open, #print, #properties!, #save, #tag, #to_s, #update

Constructor Details

#initialize(file_path) ⇒ FLAC

Returns a new instance of FLAC.



4
5
6
7
# File 'lib/unitf/tag/flac.rb', line 4

def initialize(file_path)
  super(file_path)
  @file = TagLib::FLAC::File.new(file_path)
end

Instance Method Details

#album_artist=(artist) ⇒ Object



38
39
40
# File 'lib/unitf/tag/flac.rb', line 38

def album_artist=(artist)
  @file.xiph_comment.add_field('ALBUM ARTIST', artist, true)
end

#cover!(file_path) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/unitf/tag/flac.rb', line 24

def cover!(file_path)
  UnitF::Log.info("Setting cover #{file_path}")
  pic = TagLib::FLAC::Picture.new
  pic.type = TagLib::FLAC::Picture::FrontCover
  pic.mime_type = 'image/jpeg'
  pic.description = 'Front Cover'
  pic.data = ::File.binread(file_path)
  @file.add_picture(pic)
end

#cover?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/unitf/tag/flac.rb', line 17

def cover?
  @file.picture_list.each do |pic|
    return true if pic.type == TagLib::FLAC::Picture::FrontCover
  end
  false
end

#delete_cover!Object



34
35
36
# File 'lib/unitf/tag/flac.rb', line 34

def delete_cover!
  @file.remove_pictures
end

#dumpObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/unitf/tag/flac.rb', line 47

def dump
  puts "File: #{realpath}"
  tag = @file.xiph_comment
  tag.field_list_map.each_key do |key|
    puts "#{key}: #{tag.field_list_map[key]}"
  end

  @file.picture_list.each do |pic|
    puts "Picture: type=#{pic.type}, desc=#{pic.description}"
  end
  puts
end

#infoObject



9
10
11
12
13
14
15
# File 'lib/unitf/tag/flac.rb', line 9

def info
  super.merge!({
    stats: stats,
    sample_rate: @file.audio_properties.sample_rate,
    bits_per_sample: @file.audio_properties.bits_per_sample
  })
end

#statsObject



42
43
44
45
# File 'lib/unitf/tag/flac.rb', line 42

def stats
  stats = @file.audio_properties
  sprintf('%.1fkHz/%d-bit %dkbps', stats.sample_rate / 1000.to_f, stats.bits_per_sample, stats.bitrate)
end