vidibus-fileinfo 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -52,6 +52,8 @@ For images, a hash with following data will be returned:
52
52
  :size # file size in bytes
53
53
  :bit # depth in bit
54
54
  :content_type # content type of image, e.g. "jpeg"
55
+ :orientation # visual position e.g. 6 (right top). See "Exif orientation" for more
56
+ :quality # quality of image
55
57
  ```
56
58
 
57
59
  This gem currently support these image formats:
@@ -39,26 +39,27 @@ module Vidibus
39
39
 
40
40
  metadata = {}
41
41
  @processor::METADATA.each do |attribute|
42
- begin
43
- metadata[attribute.to_sym] = send(attribute)
44
- rescue
45
- raise DataError, "#{attribute}"
42
+ if data = send(attribute)
43
+ metadata[attribute.to_sym] = data
46
44
  end
47
45
  end
48
46
 
49
- validate(metadata)
47
+ raise DataError unless valid?(metadata)
50
48
  metadata
51
49
  end
52
50
 
53
51
  def process_cmd
54
52
  pid, stdin, stdout, stderr = POSIX::Spawn::popen4(cmd)
55
- raw_metadata = eval("#{output}.read")
53
+ raw_metadata = eval(output).read
56
54
  Process::waitpid(pid)
57
55
  raw_metadata
58
56
  end
59
57
 
60
- def validate(metadata)
61
- raise DataError unless valid?(metadata)
58
+ # Important attributes must be present and valid
59
+ def valid?(metadata)
60
+ validate.each do |attr|
61
+ return false if metadata[attr.to_sym].nil? || metadata[attr.to_sym].zero?
62
+ end
62
63
  end
63
64
 
64
65
  # The video/image file size in bytes.
@@ -5,47 +5,57 @@ module Vidibus
5
5
  FORMATS = %w[jpg jpeg png gif]
6
6
  METADATA = %w[bit content_type height orientation quality size width]
7
7
 
8
+ # ImageMagick command
8
9
  def cmd
9
10
  "identify -verbose #{@path}"
10
11
  end
11
12
 
12
13
  def output
13
- :stdout
14
+ "stdout"
14
15
  end
15
16
 
16
- def valid?(metadata)
17
- !(metadata[:width].zero? || metadata[:height].zero?)
17
+ def validate
18
+ %w[height width]
18
19
  end
19
20
 
20
21
  protected
21
22
 
22
23
  def bit
23
- /^\s*Depth:\s(\w+)-bit/.match(@raw_metadata)[1].presence.to_i
24
+ if match = @raw_metadata[/^\s*Depth:\s(\w+)-bit/, 1]
25
+ match.to_i
26
+ end
24
27
  end
25
28
 
26
29
  def content_type
27
- /^\s*Format:\s(\w+)/.match(@raw_metadata)[1].presence.downcase
30
+ if match = @raw_metadata[/^\s*Format:\s(\w+)/, 1]
31
+ match.downcase
32
+ end
28
33
  end
29
34
 
30
35
  def height
31
- dimension[1]
36
+ dimension[1] if dimension
32
37
  end
33
38
 
34
39
  def width
35
- dimension[0]
40
+ dimension[0] if dimension
36
41
  end
37
42
 
38
43
  def dimension
39
- str = /^\s*Geometry: (\w+)/.match(@raw_metadata)[1].presence
40
- str.split("x").map(&:to_i)
44
+ if match = @raw_metadata[/^\s*Geometry:\s(\w+)/, 1]
45
+ match.split("x").map(&:to_i)
46
+ end
41
47
  end
42
48
 
43
49
  def orientation
44
- /^\s*exif:Orientation:\s(\d+)/.match(@raw_metadata)[1].presence.to_i
50
+ if match = @raw_metadata[/^\s*exif:Orientation:\s(\d+)/, 1]
51
+ match.to_i
52
+ end
45
53
  end
46
54
 
47
55
  def quality
48
- /^\s*Quality: (\d+)/.match(@raw_metadata)[1].presence.to_i
56
+ if match = @raw_metadata[/^\s*Quality:\s(\d+)/, 1]
57
+ match.to_i
58
+ end
49
59
  end
50
60
  end
51
61
  end
@@ -6,57 +6,66 @@ module Vidibus
6
6
  METADATA = %w[audio_codec audio_sample_rate bitrate duration fps height
7
7
  size video_codec width]
8
8
 
9
+ # FFmpeg command
9
10
  def cmd
10
11
  "ffmpeg -i #{@path}"
11
12
  end
12
13
 
13
14
  def output
14
- :stderr
15
+ "stderr"
15
16
  end
16
17
 
17
- def valid?(metadata)
18
- !(metadata[:width].zero? || metadata[:height].zero? || metadata[:duration].zero?)
18
+ def validate
19
+ %w[duration height width]
19
20
  end
20
21
 
21
22
  protected
22
23
 
23
24
  def audio_codec
24
- /Audio:\s+([a-z]+),/.match(@raw_metadata)[1].presence
25
+ @raw_metadata[/Audio:\s+([a-z]+),/, 1]
25
26
  end
26
27
 
27
28
  def audio_sample_rate
28
- /(\d+)\sHz/.match(@raw_metadata)[1].presence.to_i
29
+ if match = @raw_metadata[/(\d+)\sHz/, 1]
30
+ match.to_i
31
+ end
29
32
  end
30
33
 
31
34
  def bitrate
32
- /bitrate:\s(\d+)\skb\/s/.match(@raw_metadata)[1].presence.to_i
35
+ if match = @raw_metadata[/bitrate:\s(\d+)\skb\/s/, 1]
36
+ match.to_i
37
+ end
33
38
  end
34
39
 
35
40
  def duration
36
- str = /Duration:\s+([0-9\:\.]+),/.match(@raw_metadata)[1].presence
37
- units = str.split(":").map(&:to_f)
38
- (units[0] * 60 * 60 * 1000) + (units[1] * 60 * 1000) + (units[2] * 1000) / 1000
41
+ if match = @raw_metadata[/Duration:\s+([0-9\:\.]+),/, 1]
42
+ units = match.split(":").map(&:to_f)
43
+ (units[0] * 60 * 60 * 1000) + (units[1] * 60 * 1000) + (units[2] * 1000) / 1000
44
+ end
39
45
  end
40
46
 
41
47
  def fps
42
- /(\d+)\s+fps,/.match(@raw_metadata)[1].presence.to_f
48
+ if match = @raw_metadata[/([\d\.]+)\s+fps,/, 1]
49
+ match.to_f
50
+ end
43
51
  end
44
52
 
45
53
  def height
46
- dimension[1]
54
+ dimension[1] if dimension
47
55
  end
48
56
 
49
57
  def width
50
- dimension[0]
58
+ dimension[0] if dimension
51
59
  end
52
60
 
53
61
  def dimension
54
- str = /^.*Video:.*( \d+x\d+ ).*$/.match(@raw_metadata)[1].strip.presence
55
- str.split("x").map(&:to_i)
62
+ if match = @raw_metadata[/^.*Video:.*(\s\d+x\d+\s).*$/, 1]
63
+ match.strip.split("x").map(&:to_i)
64
+ end
56
65
  end
57
66
 
58
67
  def video_codec
59
- /Video:\s+([a-z0-9]+),/.match(@raw_metadata).presence[1]
68
+ @raw_metadata[/Video:\s*([a-zA-Z0-9\s\(\)]*),/, 1]
60
69
  end
61
70
  end
62
71
  end
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Fileinfo
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andre Pankratz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-07 00:00:00 +02:00
18
+ date: 2011-09-08 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency