vidibus-fileinfo 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,23 +10,38 @@ module Vidibus
10
10
  end
11
11
 
12
12
  def format
13
- @format ||= Fileinfo.format(@path)
13
+ @format ||= Fileinfo.format(path)
14
14
  end
15
15
 
16
- def mime_type
17
- @mime_type ||= Mime::Type.lookup_by_extension(format)
16
+ # Return the mime type of the current instance.
17
+ # If a media_type is given, only a matching mime
18
+ # type will be returned.
19
+ def mime_type(media_type = nil)
20
+ types = MIME::Types.type_for(path)
21
+ return if types.empty?
22
+ if media_type
23
+ media_type = media_type.to_s
24
+ media_types = types.select { |m| m.media_type == media_type }
25
+ if media_types.length > 1
26
+ sub_types = media_types.select { |m| m.sub_type == format }
27
+ media_types = sub_types if sub_types.any?
28
+ end
29
+ types = media_types if media_types.any?
30
+ end
31
+ types.first.content_type if types.any?
18
32
  end
33
+ alias :content_type :mime_type
19
34
 
20
35
  def data
21
- raise PathError unless @path
36
+ raise PathError unless path
22
37
  @data ||= parse_metadata
23
38
  end
24
39
 
25
40
  protected
26
41
 
27
42
  def check_file
28
- raise FileAccessError unless File.exist?(@path)
29
- raise NoFileError unless File.file?(@path)
43
+ raise FileAccessError unless File.exist?(path)
44
+ raise NoFileError unless File.file?(path)
30
45
  end
31
46
 
32
47
  def load_processor
@@ -62,7 +77,7 @@ module Vidibus
62
77
 
63
78
  # The video/image file size in bytes.
64
79
  def size
65
- File.size(@path)
80
+ File.size(path)
66
81
  end
67
82
  end
68
83
  end
@@ -27,9 +27,7 @@ module Vidibus
27
27
  end
28
28
 
29
29
  def content_type
30
- if match = @raw_metadata[/^\s*Format:\s(\w+)/, 1]
31
- match.downcase
32
- end
30
+ super('image')
33
31
  end
34
32
 
35
33
  def height
@@ -2,9 +2,8 @@ module Vidibus
2
2
  module Fileinfo
3
3
  module Processor
4
4
  module Video
5
- FORMATS = %w[avi flv h261 h263 h264 ipod m4v mov mp4 mpeg mxf ogg]
6
- METADATA = %w[audio_codec audio_sample_rate bitrate duration fps height
7
- size video_codec width]
5
+ FORMATS = %w[3g2 3gp asf avi dv f4p f4v flv ivf m21 mj2 mjpg mkv mov mp4 mpeg mpg mxf ogg ogv rm ts webm wmv]
6
+ METADATA = %w[audio_codec audio_sample_rate content_type bitrate duration fps height size video_codec width]
8
7
 
9
8
  # FFmpeg command
10
9
  def cmd
@@ -22,7 +21,7 @@ module Vidibus
22
21
  protected
23
22
 
24
23
  def audio_codec
25
- @raw_metadata[/Audio:\s+([a-z]+),/, 1]
24
+ @raw_metadata[/Audio:\s+([a-z0-9_]+),.*\d+\sHz/, 1]
26
25
  end
27
26
 
28
27
  def audio_sample_rate
@@ -37,15 +36,22 @@ module Vidibus
37
36
  end
38
37
  end
39
38
 
39
+ def content_type
40
+ super('video')
41
+ end
42
+
40
43
  def duration
41
44
  if match = @raw_metadata[/Duration:\s+([0-9\:\.]+),/, 1]
42
45
  units = match.split(":").map(&:to_f)
43
- units[0]*3600 + units[1]*60 + units[2]
46
+ f = units[0]*3600 + units[1]*60 + units[2]
47
+ (f * 100).round.to_f / 100
44
48
  end
45
49
  end
46
50
 
47
51
  def fps
48
- if match = @raw_metadata[/([\d\.]+)\s+fps,/, 1]
52
+ match = @raw_metadata[/([\d\.]+)\s+fps,/, 1]
53
+ match ||= @raw_metadata[/([\d\.]+)\s+tbr,/, 1]
54
+ if match
49
55
  match.to_f
50
56
  end
51
57
  end
@@ -59,13 +65,15 @@ module Vidibus
59
65
  end
60
66
 
61
67
  def dimension
62
- if match = @raw_metadata[/^.*Video:.*?(\d+x\d+)/, 1]
68
+ if match = @raw_metadata[/^.*Video:.*?,.*?(\d+x\d+)/, 1]
63
69
  match.strip.split("x").map(&:to_i)
64
70
  end
65
71
  end
66
72
 
67
73
  def video_codec
68
- @raw_metadata[/Video:\s*([a-zA-Z0-9\s\(\)]*),/, 1]
74
+ if codec = @raw_metadata[/Video:\s*([a-zA-Z0-9\s\(\)]*)[\s\/,]+/, 1]
75
+ codec.strip
76
+ end
69
77
  end
70
78
  end
71
79
  end
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Fileinfo
3
- VERSION = "0.1.3"
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- require "action_dispatch/http/mime_type"
1
+ require "mime/types"
2
2
  require "posix/spawn"
3
3
  require "vidibus-core_extensions"
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-fileinfo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease:
4
+ hash: 23
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andre Pankratz
@@ -15,23 +15,21 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-10 00:00:00 +02:00
18
+ date: 2012-03-22 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: actionpack
22
+ name: mime-types
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 15
29
+ hash: 3
30
30
  segments:
31
- - 3
32
31
  - 0
33
- - 4
34
- version: 3.0.4
32
+ version: "0"
35
33
  type: :runtime
36
34
  version_requirements: *id001
37
35
  - !ruby/object:Gem::Dependency
@@ -198,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
196
  requirements: []
199
197
 
200
198
  rubyforge_project:
201
- rubygems_version: 1.6.2
199
+ rubygems_version: 1.3.7
202
200
  signing_key:
203
201
  specification_version: 3
204
202
  summary: Returns information about an image or video file.