Class: MediaInformationGatherer
- Inherits:
-
Object
- Object
- MediaInformationGatherer
- Defined in:
- lib/mig.rb,
lib/mig/http.rb,
lib/mig/modules/common.rb,
lib/mig/modules/ffmpeg.rb,
lib/mig/modules/exiftool.rb,
lib/mig/modules/mediainfo.rb,
lib/mig/modules/media_type.rb
Defined Under Namespace
Classes: Common, ExifTool, FFMPEG, HTTP, MediaType, Mediainfo
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#get_media_type_using_exiftool ⇒ Object
run_modules.
- #get_media_type_using_filemagic ⇒ Object
-
#initialize(_options = { }) ⇒ MediaInformationGatherer
constructor
A new instance of MediaInformationGatherer.
-
#media_type ⇒ Object
initialize.
- #metadata_sources ⇒ Object
- #run(file_path, options = { }) ⇒ Object
- #run_modules(file_path, options = { }) ⇒ Hash
- #set_media_type ⇒ Object
Constructor Details
#initialize(_options = { }) ⇒ MediaInformationGatherer
Returns a new instance of MediaInformationGatherer.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mig.rb', line 41 def initialize( = { }) = { } .merge!() @log = [:logger] || $log || Logger.new(STDOUT) log.debug { "#{self.class.name} - Options loaded. #{options}" } [:logger] ||= log params = .dup @exiftool = ExifTool.new( params ) @ffmpeg = FFMPEG.new( params ) @mediainfo = Mediainfo.new( params ) @media_typer = MediaType.new @default_run_file_stat = .fetch(:run_file_stat, true) @default_run_file_magic = .fetch(:run_filemagic, true) @default_run_mediainfo = .fetch(:run_mediainfo, true) @default_run_ffmpeg = .fetch(:run_ffmpeg, true) @default_run_exiftool = .fetch(:run_exiftool, true) @default_run_common = .fetch(:run_common, true) end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
35 36 37 |
# File 'lib/mig.rb', line 35 def log @log end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
35 36 37 |
# File 'lib/mig.rb', line 35 def end |
Instance Method Details
#get_media_type_using_exiftool ⇒ Object
run_modules
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/mig.rb', line 133 def get_media_type_using_exiftool exiftool_md = [:exiftool] return unless exiftool_md.is_a?(Hash) mime_type = exiftool_md['MIMEType'] return unless mime_type.is_a?(String) type, sub_type = mime_type.split('/') return unless type { :type => type, :subtype => sub_type } end |
#get_media_type_using_filemagic ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/mig.rb', line 146 def get_media_type_using_filemagic filemagic_md = [:filemagic] return unless filemagic_md.is_a?(Hash) return unless filemagic_md[:type] filemagic_md end |
#media_type ⇒ Object
initialize
66 |
# File 'lib/mig.rb', line 66 def media_type; @media_type ||= { } end |
#metadata_sources ⇒ Object
67 |
# File 'lib/mig.rb', line 67 def ; ||= { } end |
#run(file_path, options = { }) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mig.rb', line 70 def run(file_path, = { }) @media_type = { } = { } raise Errno::ENOENT, "File Not Found. File Path: '#{file_path}'" unless File.exist?(file_path) gathering_start = Time.now log.debug { "Gathering metadata for file: #{file_path}"} = run_modules(file_path, ) log.debug { "Metadata gathering completed. Took: #{Time.now - gathering_start} seconds" } end |
#run_modules(file_path, options = { }) ⇒ Hash
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/mig.rb', line 87 def run_modules(file_path, = { }) run_file_stat = .fetch(:run_file_stat, @default_run_file_stat) run_filemagic = .fetch(:run_filemagic, @default_run_filemagic) run_mediainfo = .fetch(:run_mediainfo, @default_run_mediainfo) run_ffmpeg = .fetch(:run_ffmpeg, @default_run_ffmpeg) run_exiftool = .fetch(:run_exiftool, @default_run_exiftool) run_common = .fetch(:run_common, @default_run_common) if run_file_stat log.debug { 'Running File Stat.' } start = Time.now and [:stat] = File.stat(file_path).to_hash rescue { :error => { :message => $!., :backtrace => $!.backtrace } } log.debug { "File Stat took #{Time.now - start}" } end if run_filemagic log.debug { 'Running Filemagic.' } start = Time.now and [:filemagic] = @media_typer.run(file_path, ) rescue { :error => { :message => $!., :backtrace => $!.backtrace } } log.debug { "Filemagic took #{Time.now - start}" } end if run_mediainfo log.debug { 'Running MediaInfo.' } start = Time.now and [:mediainfo] = @mediainfo.run(file_path, ) rescue { :error => { :message => $!., :backtrace => $!.backtrace } } log.debug { "MediaInfo took #{Time.now - start}" } end if run_ffmpeg log.debug { 'Running FFMPEG.' } start = Time.now and [:ffmpeg] = @ffmpeg.run(file_path, ) rescue { :error => { :message => $!., :backtrace => $!.backtrace } } log.debug { "FFMpeg took #{Time.now - start}" } end if run_exiftool log.debug { 'Running ExifTool.' } start = Time.now and [:exiftool] = @exiftool.run(file_path) rescue { :error => { :message => $!., :backtrace => $!.backtrace } } log.debug { "ExifTool took #{Time.now - start}" } end set_media_type [:media_type] = media_type [:common] = Common.common_variables() if run_common end |
#set_media_type ⇒ Object
154 155 156 |
# File 'lib/mig.rb', line 154 def set_media_type @media_type = get_media_type_using_filemagic || get_media_type_using_exiftool end |