vidibus-fileinfo 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -0
- data/lib/vidibus/fileinfo/base.rb +9 -8
- data/lib/vidibus/fileinfo/processor/image.rb +21 -11
- data/lib/vidibus/fileinfo/processor/video.rb +24 -15
- data/lib/vidibus/fileinfo/version.rb +1 -1
- metadata +4 -4
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
|
-
|
|
43
|
-
metadata[attribute.to_sym] =
|
|
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
|
-
|
|
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(
|
|
53
|
+
raw_metadata = eval(output).read
|
|
56
54
|
Process::waitpid(pid)
|
|
57
55
|
raw_metadata
|
|
58
56
|
end
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
14
|
+
"stdout"
|
|
14
15
|
end
|
|
15
16
|
|
|
16
|
-
def
|
|
17
|
-
|
|
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
|
|
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+)
|
|
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
|
-
|
|
40
|
-
|
|
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+)
|
|
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
|
|
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
|
-
|
|
15
|
+
"stderr"
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
def
|
|
18
|
-
|
|
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]+)
|
|
25
|
+
@raw_metadata[/Audio:\s+([a-z]+),/, 1]
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
def audio_sample_rate
|
|
28
|
-
/(\d+)\sHz
|
|
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
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
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
|
-
|
|
55
|
-
|
|
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
|
|
68
|
+
@raw_metadata[/Video:\s*([a-zA-Z0-9\s\(\)]*),/, 1]
|
|
60
69
|
end
|
|
61
70
|
end
|
|
62
71
|
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:
|
|
4
|
+
hash: 25
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 1
|
|
9
|
-
-
|
|
10
|
-
version: 0.1.
|
|
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-
|
|
18
|
+
date: 2011-09-08 00:00:00 +02:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|