vidibus-fileinfo 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -87,6 +87,25 @@ These video formats are currently supported:
87
87
  mpeg, mpg, mts, mxf, ogg, ogv, rm, ts, webm, wmv
88
88
  ```
89
89
 
90
+ ### Audio files
91
+
92
+ For audio files the dataset looks as follows:
93
+
94
+ ``` ruby
95
+ :size # file size in bytes, eg. 20883991
96
+ :duration # duration of video in seconds, e.g. 44.82
97
+ :content_type # content type of video, e.g. "audio/mpeg"
98
+ :bit_rate # bit rate in bit, e.g. 600000
99
+ :codec # codec of audio stream, e.g. "aac"
100
+ :sample_rate # sample rate of audio stream, e.g. 48000
101
+ ```
102
+
103
+ These audio formats are currently supported:
104
+
105
+ ```
106
+ mp3
107
+ ```
108
+
90
109
  ## Copyright
91
110
 
92
- Copyright (c) 2011-2012 Andre Pankratz. See LICENSE for details.
111
+ Copyright (c) 2011-2013 Andre Pankratz. See LICENSE for details.
@@ -1,6 +1,7 @@
1
1
  require "vidibus/fileinfo/base"
2
2
  require "vidibus/fileinfo/processor/image"
3
3
  require "vidibus/fileinfo/processor/video"
4
+ require "vidibus/fileinfo/processor/audio"
4
5
 
5
6
  module Vidibus
6
7
  module Fileinfo
@@ -19,7 +20,7 @@ module Vidibus
19
20
 
20
21
  # Returns a list of available processors.
21
22
  def processors
22
- @processors ||= [Processor::Image, Processor::Video]
23
+ @processors ||= [Processor::Image, Processor::Video, Processor::Audio]
23
24
  end
24
25
 
25
26
  # Returns a list of processable formats.
@@ -0,0 +1,62 @@
1
+ module Vidibus
2
+ module Fileinfo
3
+ module Processor
4
+ module Audio
5
+ FORMATS = %w[
6
+ mp3
7
+ ]
8
+ METADATA = %w[
9
+ codec sample_rate content_type bit_rate duration
10
+ ]
11
+
12
+ # FFmpeg command
13
+ def cmd
14
+ %Q(ffmpeg -i "#{@path}")
15
+ end
16
+
17
+ def output
18
+ 'stderr'
19
+ end
20
+
21
+ def validate
22
+ %w[duration]
23
+ end
24
+
25
+ protected
26
+
27
+ def codec
28
+ @raw_metadata[/Audio:\s+([a-z0-9_]+).*,.*\d+\sHz/, 1]
29
+ end
30
+
31
+ def sample_rate
32
+ if match = @raw_metadata[/(\d+)\sHz/, 1]
33
+ match.to_i
34
+ end
35
+ end
36
+
37
+ # Return the bit rate defined as "bitrate". Calculate it from
38
+ # file size and duration otherwise.
39
+ # 1 kilobit == 1000 bit
40
+ def bit_rate
41
+ if match = @raw_metadata[/bitrate:\s(\d+)\skb\/s/, 1]
42
+ match.to_i * 1000
43
+ elsif duration && duration > 0
44
+ (size.to_f/1.024/duration*8).round
45
+ end
46
+ end
47
+
48
+ def content_type
49
+ super('audio')
50
+ end
51
+
52
+ def duration
53
+ if match = @raw_metadata[/Duration:\s+([0-9\:\.]+),/, 1]
54
+ units = match.split(":").map(&:to_f)
55
+ f = units[0]*3600 + units[1]*60 + units[2]
56
+ (f * 100).round.to_f / 100
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Fileinfo
3
- VERSION = '1.1.1'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-fileinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-18 00:00:00.000000000 Z
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types
@@ -155,14 +155,15 @@ dependencies:
155
155
  - - ! '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
- description: Returns information like the width, height and bits about an image or
159
- video file.
158
+ description: Returns information like the width, height and bits about an image, video
159
+ or audio file.
160
160
  email: andre@vidibus.com
161
161
  executables: []
162
162
  extensions: []
163
163
  extra_rdoc_files: []
164
164
  files:
165
165
  - lib/vidibus/fileinfo/base.rb
166
+ - lib/vidibus/fileinfo/processor/audio.rb
166
167
  - lib/vidibus/fileinfo/processor/image.rb
167
168
  - lib/vidibus/fileinfo/processor/video.rb
168
169
  - lib/vidibus/fileinfo/version.rb
@@ -183,9 +184,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
184
  - - ! '>='
184
185
  - !ruby/object:Gem::Version
185
186
  version: '0'
186
- segments:
187
- - 0
188
- hash: -2292526863933311751
189
187
  required_rubygems_version: !ruby/object:Gem::Requirement
190
188
  none: false
191
189
  requirements:
@@ -197,5 +195,5 @@ rubyforge_project:
197
195
  rubygems_version: 1.8.24
198
196
  signing_key:
199
197
  specification_version: 3
200
- summary: Returns information about an image or video file.
198
+ summary: Returns information about an image, video or audio file.
201
199
  test_files: []