mediainfo 1.0.3 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '047490deb49a33dd0202ae748bbadfc8fb210e95424b6384c6c8e30613ad85fa'
4
- data.tar.gz: f9a1f6334a0eb23cce8f6745193acf70b82db80637f9c2a43f1bb2d37f8ddbd7
3
+ metadata.gz: 6f79256366c735ce9879c75236dfbf2d1c1e8a97ba4fb2e2b0f2b06b260c5392
4
+ data.tar.gz: 1df3a885f1a7ae5165fb57615c950327fa4847d9b06bdaff072ab97f986632e9
5
5
  SHA512:
6
- metadata.gz: f338c14ae90ef808b2396d8335d0bc0da14fcfdce957fe62e8a8b2bc69395356b408b992618d90409e765fdf0cbe747d375a949938ce031faa9c99e8e6c72242
7
- data.tar.gz: 314d421a1cf9d1259e698f8e996f7c90d6f6fd1fb2db3dc6a3e66dd3e15e404c3fc225c69bc8bc347d6f0c135bf91122b0b79774febba7eaf3583004991793d7
6
+ metadata.gz: 677175108b077cc7f1d421e062cf56498e26d8d48fd1201c5313d76dd2c48ca77b626af1d3a6c7f06ac8a5e37a464d09ee34032409d925b80faff1d0fbd220da
7
+ data.tar.gz: a582fb423b5585d8611af76742e676d2bfbd214e82559e79bad899b7752cbfec81207137864aca7b8695671e61b6e683090ce6edee912ca7934506ba7ad24954
data/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  MediaInfo is a class wrapping [the mediainfo CLI](http://mediainfo.sourceforge.net).
4
4
 
5
5
  ## Installation
6
-
6
+
7
7
  $ gem install mediainfo
8
-
8
+
9
9
  ## Usage
10
10
 
11
11
  #### Parsing raw XML
@@ -16,28 +16,28 @@ MediaInfo is a class wrapping [the mediainfo CLI](http://mediainfo.sourceforge.n
16
16
  media_info = MediaInfo.from('http://techslides.com/demos/sample-videos/small.mp4')
17
17
 
18
18
  You can specify an alternate path for the MediaInfo Binary:
19
-
19
+
20
20
  ENV['MEDIAINFO_PATH'] = "/opt/local/bin/mediainfo"
21
-
21
+
22
22
  Once you have an MediaInfo object, you can start inspecting tracks:
23
-
23
+
24
24
  media_info.track_types => ['general','video','audio']
25
25
  media_info.track_types.count => 3
26
26
  media_info.video? => true
27
27
  media_info.image? => nil
28
28
  media_info.image.filesize => MethodNotFound exception
29
-
30
- When inspecting specific types of tracks, you have a couple general API options. The
31
- first approach assumes one track of a given type, a common scenario in many video files,
29
+
30
+ When inspecting specific types of tracks, you have a couple general API options. The
31
+ first approach assumes one track of a given type, a common scenario in many video files,
32
32
  for example:
33
-
33
+
34
34
  media_info.video.count => 1
35
35
  media_info.video.duration => 120 (seconds)
36
-
36
+
37
37
  Sometimes you'll have more than one track of a given type:
38
38
  - The first track type name, or any track type with <ID>1</ID> will not contain '1'
39
-
40
-
39
+
40
+
41
41
  media_info.track_types => ['general','video','video2','audio','other','other2']
42
42
  media_info.track_types.count => 5
43
43
  media_info.video? => true
@@ -54,14 +54,14 @@ Sometimes you'll have more than one track of a given type:
54
54
  media_info.video.encoded_date.class => Time
55
55
  media_info.video2.duration.class => Integer
56
56
  media_info.video.display_aspect_ratio.class => Float
57
-
57
+
58
58
  - Any track attribute name with "date" and matching /\d-/ will be converted using Time.parse:
59
59
 
60
-
60
+
61
61
  media_info.video.encoded_date => 2018-03-30 12:12:08 -0400
62
62
  media_info.video.customdate => 2016-02-10 01:00:00 -0600
63
-
64
- - .duration and .overall_duration will be returned as milliseconds AS LONG AS the Duration and Overall_Duration match one of the expected units:
63
+
64
+ - .duration and .overall_duration will be returned as milliseconds AS LONG AS the Duration and Overall_Duration match one of the expected units (each separated by a space or not):
65
65
  - h (\<Duration>15h\</Duration>) (hour)
66
66
  - hour (\<Duration>15hour\</Duration>)
67
67
  - mn (\<Duration>15hour 6mn\</Duration>) (minute)
@@ -70,25 +70,27 @@ Sometimes you'll have more than one track of a given type:
70
70
  - s (\<Duration>15hour 6min 59s\</Duration>) (second)
71
71
  - sec (\<Duration>15hour 6min 59sec\</Duration>) (second)
72
72
  - ms (\<Duration>15hour 6min 59sec 301ms\</Duration>) (milliseconds)
73
+ - in the form of a Float (as for iphone mov files)
73
74
  - [Submit an issue to add more!](https://github.com/greatseth/mediainfo/issues)
74
-
75
-
76
- media_info.video.duration => 9855000 (\<Duration>15s 164ms\</Duration>)
77
- media_info.video.duration => 17196000 (\<Duration>36s 286ms\</Duration>)
75
+
76
+
77
+ media_info.video.duration => 15164 (\<Duration>15s 164ms\</Duration>)
78
+ media_info.video.duration => 36286 (\<Duration>36s 286ms\</Duration>)
79
+ media_info.video.duration => 123456 (\<Duration>123.456\</Duration>)
78
80
 
79
81
  - We standardize the naming of several Attributes:
80
82
  - You can review lib/attribute_standardization_rules.yml to see them all
81
-
83
+
82
84
 
83
85
  media_info.video.bit_rate => nil (\<Bit_rate>41.2 Mbps\</Bit_rate>)
84
86
  media_info.video.bitrate => "41.2 Mbps" (\<Bit_rate>41.2 Mbps\</Bit_rate>)
85
87
  media_info.general.filesize => "11.5 MiB" (\<File_size>11.5 MiB\</File_size>
86
88
 
87
-
89
+
88
90
  In order to support all possible MediaInfo variations, you may see the following situation:
89
91
 
90
92
  media_info.track_types => ['general','video','video5','audio','other','other2']
91
-
93
+
92
94
  The track type media_info.video5 is available, but no video2, 3, and 4. This is because the MediaInfo from the video has:
93
95
 
94
96
  <track type="Video">
@@ -99,7 +101,7 @@ The track type media_info.video5 is available, but no video2, 3, and 4. This is
99
101
  ...
100
102
 
101
103
  *The ID will take priority for labeling.* Else if no ID exists, you'll see consecutive numbering for duplicate tracks in the Media.
102
-
104
+
103
105
  Any second level attributes are also available:
104
106
 
105
107
  MediaInfo.from('~/Desktop/test.mov').general.extra
@@ -110,17 +112,17 @@ Any second level attributes are also available:
110
112
  @com_apple_quicktime_model=0,
111
113
  @com_apple_quicktime_software=11.2>
112
114
 
113
- REXML is used as the XML parser by default. If you'd like, you can
115
+ REXML is used as the XML parser by default. If you'd like, you can
114
116
  configure Mediainfo to use Nokogiri instead:
115
117
 
116
- * define the `MEDIAINFO_XML_PARSER` environment variable to be the
117
- name of the parser as you'd pass to a :gem or :require call.
118
-
118
+ * define the `MEDIAINFO_XML_PARSER` environment variable to be the
119
+ name of the parser as you'd pass to a :gem or :require call.
120
+
119
121
  e.g. `export MEDIAINFO_XML_PARSER=nokogiri`
120
-
121
- Once you've got an instance setup, you can call numerous methods to get
122
- a variety of information about a file. Some attributes may be present
123
- for some files where others are not, but any supported attribute
122
+
123
+ Once you've got an instance setup, you can call numerous methods to get
124
+ a variety of information about a file. Some attributes may be present
125
+ for some files where others are not, but any supported attribute
124
126
  should at least return `nil`.
125
127
 
126
128
  ## Requirements
@@ -136,4 +138,4 @@ should at least return `nil`.
136
138
  * Ned Campion - [http://github.com/nedcampion](http://github.com/nedcampion)
137
139
  * Daniel Jagszent - [http://github.com/d--j](http://github.com/d--j)
138
140
  * Robert Mrasek - [http://github.com/derobo](http://github.com/derobo)
139
- * Nathan Pierce - [http://github.com/NorseGaud](http://github.com/NorseGaud)
141
+ * Nathan Pierce - [http://github.com/NorseGaud](http://github.com/NorseGaud)
@@ -119,23 +119,27 @@ module MediaInfo
119
119
  end
120
120
 
121
121
  def self.standardize_to_milliseconds(value)
122
- # TODO iphone video has a float as the duration
123
- # UPDATE THE README IF YOU'RE CHANGING THIS
124
- milliseconds = 0
125
- value.scan(/\d+\s?\w+/).each do |chunk|
126
- case chunk
127
- when /\d+\s?h/ then milliseconds += chunk.to_i * 60 * 60 * 1000
128
- when /\d+\s?hour/ then milliseconds += chunk.to_i * 60 * 60 * 1000
129
- when /\d+\s?m/ then milliseconds += chunk.to_i * 60 * 1000
130
- when /\d+\s?mn/ then milliseconds += chunk.to_i * 60 * 1000
131
- when /\d+\s?min/ then milliseconds += chunk.to_i * 60 * 1000
132
- when /\d+\s?s/ then milliseconds += chunk.to_i * 1000
133
- when /\d+\s?sec/ then milliseconds += chunk.to_i * 1000
134
- when /\d+\s?ms/ then milliseconds += chunk.to_i
135
- end
122
+ return standardize_float_to_milliseconds(value.to_f) if value.to_f.to_s == value.to_s
123
+ return standardize_string_to_milliseconds(value)
124
+ value
125
+ end
126
+
127
+ def self.standardize_string_to_milliseconds(v, base_msec = 0)
128
+ v.scan(/\d+\s?\D+/).each do |chunk|
129
+ base_msec += case chunk
130
+ when /\d+\s?ms/ then chunk.to_i
131
+ when /\d+\s?s(ec)?/ then chunk.to_i * 1000
132
+ when /\d+\s?m(i?n)?/ then chunk.to_i * 60 * 1000
133
+ when /\d+\s?h(our)?/ then chunk.to_i * 60 * 60 * 1000
134
+ end.to_i
136
135
  end
137
- milliseconds = value if milliseconds == 0 # We don't raise anymore. It's much better for the gem to work, returning the original MediaInfo attribute, than raise.
138
- return milliseconds
136
+ # We don't raise anymore. It's much better for the gem to work,
137
+ # returning the original MediaInfo attribute, than raise.
138
+ base_msec == 0 ? v : base_msec
139
+ end
140
+
141
+ def self.standardize_float_to_milliseconds(v)
142
+ (v*1000).to_i
139
143
  end
140
144
 
141
145
  end
@@ -1,3 +1,3 @@
1
1
  module MediaInfo
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediainfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Thomas Rasmussen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-31 00:00:00.000000000 Z
11
+ date: 2018-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler