mediainfo 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mediainfo.rb +38 -37
- data/lib/mediainfo/errors.rb +22 -9
- data/lib/mediainfo/tracks.rb +17 -20
- data/lib/mediainfo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1a7b21d5d2384c473c77455711cd555bd112093d87e8d122c262d3e7edc5a6c
|
4
|
+
data.tar.gz: 3802797902e9bfd0b4854a35066aa92b0bcc6d0b9f36f25687f1da9f82dc4e81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1d7dbaf1df40cb720c269740b1274badf728bf54cfc20b6818e7ae38b282c66af5065abd0d84456cd9c984b05b36571dac27227f7fa9586f5bd446114fc6f68
|
7
|
+
data.tar.gz: f12b2fd55f5de540d48d400b91ec0038a17f256c0c6b7d473367be983fe6769d8969bc3e519a80af4348b9b2728d69b0c5c70e9704e68474e12c765b1670d2e3
|
data/lib/mediainfo.rb
CHANGED
@@ -39,7 +39,6 @@ module MediaInfo
|
|
39
39
|
return xml_parser
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
42
|
def self.run(input = nil)
|
44
43
|
raise ArgumentError, 'Your input cannot be blank.' if input.nil?
|
45
44
|
command = "#{location} #{input} --Output=XML 2>&1"
|
@@ -51,44 +50,46 @@ module MediaInfo
|
|
51
50
|
end
|
52
51
|
|
53
52
|
def self.from(input)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
http = ::Net::HTTP.new(@uri.host,@uri.port)
|
65
|
-
request = Net::HTTP::Head.new(@uri.request_uri) # Only grab the Headers to be sure we don't try and download the whole file
|
66
|
-
response = http.request(request)
|
67
|
-
case response
|
68
|
-
when Net::HTTPOK
|
69
|
-
@escaped_input = URI.escape(@uri.to_s)
|
70
|
-
else
|
71
|
-
raise RemoteUrlError, "HTTP call to #{input} is not working!"
|
72
|
-
end
|
73
|
-
elsif input.include?('.xml')
|
74
|
-
return MediaInfo::Tracks.new(::File.open(input).read)
|
75
|
-
elsif !input.match(/[^\\]*\.\w+$/).nil? # A local file
|
76
|
-
@file = ::File.expand_path input # turns ~/path/to/file into /home/user/path/to/file
|
77
|
-
raise ArgumentError, 'You must include a file location.' if @file.nil?
|
78
|
-
raise ArgumentError, "need a path to a video file, #{@file} does not exist" unless ::File.exist? @file
|
79
|
-
@file_path = ::File.dirname @file
|
80
|
-
@filename = ::File.basename @file
|
81
|
-
@escaped_input = @file.shell_escape_double_quotes
|
82
|
-
# Set variable for returned XML
|
83
|
-
else
|
84
|
-
raise ArgumentError, input_guideline_message
|
85
|
-
end
|
86
|
-
return MediaInfo::Tracks.new(MediaInfo.run(@escaped_input))
|
87
|
-
else
|
88
|
-
raise ArgumentError, input_guideline_message
|
89
|
-
end
|
53
|
+
return from_uri(input) if input.is_a?(URI)
|
54
|
+
return from_string(input) if input.is_a?(String)
|
55
|
+
raise BadInputError
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.from_string(input)
|
59
|
+
return from_xml(input) if input.include?('<?xml')
|
60
|
+
return from_link(input) if input =~ URI::regexp
|
61
|
+
return from_local_file(input) if input.match(/[^\\]*\.\w+$/)
|
62
|
+
raise BadInputError
|
90
63
|
end
|
91
64
|
|
65
|
+
def self.from_xml(input)
|
66
|
+
MediaInfo::Tracks.new(input)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.from_local_file(input)
|
70
|
+
absolute_path = File.expand_path(input) # turns relative to absolute path
|
71
|
+
|
72
|
+
raise ArgumentError, 'You must include a file location.' if absolute_path.nil?
|
73
|
+
raise ArgumentError, "need a path to a video file, #{absolute_path} does not exist" unless File.exist?(absolute_path)
|
74
|
+
|
75
|
+
return from_xml(File.open(absolute_path).read) if absolute_path.match(/[^\\]*\.(xml)$/)
|
76
|
+
MediaInfo::Tracks.new(MediaInfo.run(absolute_path.shell_escape_double_quotes))
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.from_link(input)
|
80
|
+
from_uri(URI(input))
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.from_uri(input)
|
84
|
+
http = Net::HTTP.new(input.host, input.port) # Check if input is valid
|
85
|
+
request = Net::HTTP::Head.new(input.request_uri) # Only grab the Headers to be sure we don't try and download the whole file
|
86
|
+
|
87
|
+
http.use_ssl = true if input.is_a? URI::HTTPS # For https support
|
88
|
+
|
89
|
+
raise RemoteUrlError, "HTTP call to #{input} is not working!" unless http.request(request).is_a?(Net::HTTPOK)
|
90
|
+
|
91
|
+
MediaInfo::Tracks.new(MediaInfo.run(URI.escape(input.to_s)))
|
92
|
+
end
|
92
93
|
|
93
94
|
def self.set_singleton_method(object,name,parameters)
|
94
95
|
# Handle parameters with invalid characters (instance_variable_set throws error)
|
data/lib/mediainfo/errors.rb
CHANGED
@@ -1,14 +1,27 @@
|
|
1
1
|
module MediaInfo
|
2
|
+
|
2
3
|
# General
|
3
|
-
class
|
4
|
-
class
|
5
|
-
class
|
6
|
-
class
|
7
|
-
class
|
8
|
-
|
4
|
+
class EnvironmentError < StandardError; end
|
5
|
+
class ExecutionError < StandardError; end
|
6
|
+
class IncompatibleVersionError < StandardError; end
|
7
|
+
class UnknownVersionError < StandardError; end
|
8
|
+
class RemoteUrlError < StandardError; end
|
9
|
+
|
10
|
+
class BadInputError < ArgumentError
|
11
|
+
def initialize(msg=nil)
|
12
|
+
msg ||= "Input must be: \n"
|
13
|
+
+ "A video or xml file location."
|
14
|
+
+ "Example: '~/videos/test_video.mov' or '~/videos/test_video.xml' \n"
|
15
|
+
+ "A valid URL. Example: 'http://www.site.com/videofile.mov' \n"
|
16
|
+
+ "Or MediaInfo XML \n"
|
17
|
+
super(msg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
9
21
|
# Stream
|
22
|
+
class InvalidTrackType < StandardError; end
|
23
|
+
class InvalidTrackAttributeValue < StandardError; end
|
24
|
+
|
10
25
|
class SingleStreamAPIError < RuntimeError; end
|
11
26
|
class NoStreamsForProxyError < NoMethodError; end
|
12
|
-
|
13
|
-
class InvalidTrackAttributeValue < Error; end
|
14
|
-
end
|
27
|
+
end
|
data/lib/mediainfo/tracks.rb
CHANGED
@@ -97,25 +97,22 @@ module MediaInfo
|
|
97
97
|
def self.sanitize_element_value(param)
|
98
98
|
name = param[0]
|
99
99
|
value = param[1]
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
# Dates
|
114
|
-
## Be sure the name has "date" and it has an integer and a dash, like a normal date would
|
115
|
-
when name.downcase.include?('date') && !value.match(/\d-/).nil? then Time.parse(value)
|
116
|
-
else
|
117
|
-
return value
|
100
|
+
|
101
|
+
if ['Duration'].include?(name)
|
102
|
+
# Duration
|
103
|
+
return standardize_to_milliseconds(value)
|
104
|
+
elsif value.to_s == value.to_i.to_s then value.to_i
|
105
|
+
# Convert String with integer in it to Integer.
|
106
|
+
return value.to_i
|
107
|
+
elsif value.to_s == value.to_f.to_s then value.to_f
|
108
|
+
# Convert String with integer in it to Integer.
|
109
|
+
return value.to_f
|
110
|
+
elsif name.downcase.include?('date') && !value.match(/\d-/).nil?
|
111
|
+
# Dates
|
112
|
+
return Time.parse(value)
|
118
113
|
end
|
114
|
+
|
115
|
+
value
|
119
116
|
end
|
120
117
|
|
121
118
|
def self.standardize_to_milliseconds(value)
|
@@ -133,8 +130,8 @@ module MediaInfo
|
|
133
130
|
when /\d+\s?h(our)?/ then chunk.to_i * 60 * 60 * 1000
|
134
131
|
end.to_i
|
135
132
|
end
|
136
|
-
# We don't raise anymore. It's much better for the gem to
|
137
|
-
#
|
133
|
+
# We don't raise anymore. It's much better for the gem to
|
134
|
+
# return the original MediaInfo attribute, than raise.
|
138
135
|
base_msec == 0 ? v : base_msec
|
139
136
|
end
|
140
137
|
|
data/lib/mediainfo/version.rb
CHANGED
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.1.
|
4
|
+
version: 1.1.1
|
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-09-
|
11
|
+
date: 2018-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|