Class: Hearken::Indexing::FfmpegFile

Inherits:
Object
  • Object
show all
Includes:
Executor
Defined in:
lib/hearken/indexing/ffmpeg_file.rb

Constant Summary

Constants included from Tagged

Tagged::FIELDS, Tagged::FILE_FIELDS, Tagged::TAG_FIELDS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Executor

#debug, #execute, #extract_file_attributes

Methods included from Tagged

#no_tag_fields?, #to_a

Constructor Details

#initialize(path) ⇒ FfmpegFile

Returns a new instance of FfmpegFile.



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
# File 'lib/hearken/indexing/ffmpeg_file.rb', line 14

def initialize path
  extract_file_attributes path
  content = execute "ffmpeg -i #{@path.escape_for_sh}"
  state = :draining
  @meta = {}
  content.each_line do |line|
    l = line.chomp
    case l
      when "  Metadata:"
        state = :metadata
      else
        if state == :metadata
          begin
            m = / *: */.match l
            add_meta m.pre_match.strip.downcase.to_sym, m.post_match.strip if m
          rescue ArgumentError => e
          end
        end
    end
  end

  @title = tag :title, :tit2
  @album = tag :album, :talb
  @artist = tag :artist, :tpe1, :tpe2
  @albumartist = tag :album_artist, :tso2
  @time = to_duration tag :duration
  @date = tag :date, :tdrc, :tyer
  @track = tag :track, :trck
  @puid = tag :"musicip puid"
  @mbartistid = tag :musicbrainz_artistid, :"musicbrainz artist id"
  @mbalbumid = tag :musicbrainz_albumid,:"musicbrainz album id"
  @mbalbumartistid = tag :musicbrainz_albumartistid, :"musicbrainz album artist id"
  @asin = tag :asin
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



58
59
60
# File 'lib/hearken/indexing/ffmpeg_file.rb', line 58

def method_missing method
  @meta[method.to_s]
end

Class Method Details

.from_file(path) ⇒ Object



9
10
11
12
# File 'lib/hearken/indexing/ffmpeg_file.rb', line 9

def self.from_file path
  file = Hearken::Indexing::File.new Pathname.new path
  Hearken::Indexing::FfmpegFile.new file
end

Instance Method Details

#add_meta(key, value) ⇒ Object



49
50
51
# File 'lib/hearken/indexing/ffmpeg_file.rb', line 49

def add_meta key, value
  @meta[key] ||= value
end

#tag(*names) ⇒ Object



53
54
55
56
# File 'lib/hearken/indexing/ffmpeg_file.rb', line 53

def tag *names
  names.each { |name| return @meta[name] if @meta[name] }
  nil
end