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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f79256366c735ce9879c75236dfbf2d1c1e8a97ba4fb2e2b0f2b06b260c5392
4
- data.tar.gz: 1df3a885f1a7ae5165fb57615c950327fa4847d9b06bdaff072ab97f986632e9
3
+ metadata.gz: d1a7b21d5d2384c473c77455711cd555bd112093d87e8d122c262d3e7edc5a6c
4
+ data.tar.gz: 3802797902e9bfd0b4854a35066aa92b0bcc6d0b9f36f25687f1da9f82dc4e81
5
5
  SHA512:
6
- metadata.gz: 677175108b077cc7f1d421e062cf56498e26d8d48fd1201c5313d76dd2c48ca77b626af1d3a6c7f06ac8a5e37a464d09ee34032409d925b80faff1d0fbd220da
7
- data.tar.gz: a582fb423b5585d8611af76742e676d2bfbd214e82559e79bad899b7752cbfec81207137864aca7b8695671e61b6e683090ce6edee912ca7934506ba7ad24954
6
+ metadata.gz: b1d7dbaf1df40cb720c269740b1274badf728bf54cfc20b6818e7ae38b282c66af5065abd0d84456cd9c984b05b36571dac27227f7fa9586f5bd446114fc6f68
7
+ data.tar.gz: f12b2fd55f5de540d48d400b91ec0038a17f256c0c6b7d473367be983fe6769d8969bc3e519a80af4348b9b2728d69b0c5c70e9704e68474e12c765b1670d2e3
@@ -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
- input_guideline_message = 'Bad Input' + "\n" + "Input must be: \n" +
55
- "A video or xml file location. Example: '~/videos/test_video.mov' or '~/videos/test_video.xml' \n" +
56
- "A valid URL. Example: 'http://www.site.com/videofile.mov' \n" +
57
- "Or MediaInfo XML \n"
58
- if input # User must specify file
59
- if input.include?('<?xml') # Must be first, else we could parse input (raw xml) with a URL in it and think it's a URL
60
- return MediaInfo::Tracks.new(input)
61
- elsif input.downcase.include?('http') || input.downcase.include?('www') # Handle Url Parsing
62
- @uri = URI(input)
63
- # Check if URL is valid
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)
@@ -1,14 +1,27 @@
1
1
  module MediaInfo
2
+
2
3
  # General
3
- class Error < StandardError; end
4
- class EnvironmentError < Error; end
5
- class ExecutionError < Error; end
6
- class IncompatibleVersionError < Error; end
7
- class UnknownVersionError < Error; end
8
- class RemoteUrlError < Error; end
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
- class InvalidTrackType < Error; end
13
- class InvalidTrackAttributeValue < Error; end
14
- end
27
+ end
@@ -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
- case
101
- # Convert String with integer in it to Integer.
102
- ## Don't to_f anything with 2 or more dots (versions,etc)
103
- when value.match(/(?!\.)\D+/).nil? then
104
- if value.scan(/\./).any? && value.scan(/\./).count > 1
105
- value
106
- elsif value.scan(/\./).any?
107
- value.to_f
108
- else # Prevent float if it's just a normal integer
109
- value.to_i
110
- end
111
- # Duration
112
- when ['Duration'].include?(name) then standardize_to_milliseconds(value)
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 work,
137
- # returning the original MediaInfo attribute, than raise.
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
 
@@ -1,3 +1,3 @@
1
1
  module MediaInfo
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
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.1.0
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-04 00:00:00.000000000 Z
11
+ date: 2018-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler