Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle invalid dates #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions lib/mediainfo/tracks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,25 @@ def self.sanitize_element_value(param)
name = param[0]
value = param[1]

if ['Duration'].include?(name)
case
when name == 'Duration'
# Duration
return standardize_to_milliseconds(value)
elsif value.to_s == value.to_i.to_s then value.to_i
standardize_to_milliseconds(value)
when value.to_s == value.to_i.to_s
# Convert String with integer in it to Integer.
return value.to_i
elsif value.to_s == value.to_f.to_s then value.to_f
# Convert String with integer in it to Integer.
return value.to_f
elsif name.downcase.include?('date') && !value.match(/\d-/).nil?
value.to_i
when value.to_s == value.to_f.to_s
# Convert String with float in it to Float.
value.to_f
when name.downcase.include?('date') && value.match?(/\d-/)
# Dates
return Time.parse(value.sub(/^UTC\s+(.*)$/, '\1 UTC'))
begin
Time.parse(value.sub(/^UTC\s+(.*)$/, '\1 UTC'))
rescue ArgumentError
end
else
value
end

value
end

def self.standardize_to_milliseconds(value)
Expand Down