Sha256: abf01def1ebe6d3408a9852b1fbe4469aa893395f1f9adaa5819aa6caa1d451c

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

module UnitF
  module Tag
    class FLAC < UnitF::Tag::File
      def initialize(file_path)
        super(file_path)
        @file = TagLib::FLAC::File.new(file_path)
      end

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

      def 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.open(file_path, 'rb') { |f| f.read }
        @file.add_picture(pic)
      end

      def delete_cover!
        @file.remove_pictures
      end

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

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

      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
unitf-tag-0.1.4 lib/unitf/tag/flac.rb
unitf-tag-0.1.3 lib/unitf/tag/flac.rb
unitf-tag-0.1.2 lib/unitf/tag/flac.rb
unitf-tag-0.1.0 lib/unitf/tag/flac.rb