diff --git a/.gitignore b/.gitignore index cf2e725..fe841ea 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ pkg !/spec/fixtures/video/.keep /tmp/ .idea - +.vscode # rspec failure tracking .rspec_status diff --git a/.travis.yml b/.travis.yml index 4733eaa..77ca2f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,13 @@ language: ruby rvm: - - 2.5.3 + - 2.6.1 before_install: - sudo apt-get install -y mediainfo env: - MEDIAINFO_PATH=/usr/bin/mediainfo +install: + # Install bundler 2 + - gem update --no-document --system + - gem install bundler --no-document + # Install gems + - bundle install \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..57213e7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "search.location": "panel" +} \ No newline at end of file diff --git a/Gemfile b/Gemfile index 1bfcf5b..b8e1012 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' git_source(:github) {|repo_name| "https://github.com/greatseth/#{repo_name}" } - +gem 'pry' gemspec \ No newline at end of file diff --git a/README.md b/README.md index d2c6f6e..e576bb0 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ MediaInfo is a class wrapping [the mediainfo CLI](http://mediainfo.sourceforge.n #### Handling a URL media_info = MediaInfo.from('http://techslides.com/demos/sample-videos/small.mp4') -You can specify an alternate path for the MediaInfo Binary: +Ensure mediainfo is installed and within your PATH. You can specify an alternate path for the mediainfo binary if needed: - ENV['MEDIAINFO_PATH'] = "/opt/local/bin/mediainfo" + ENV['MEDIAINFO_PATH'] = "/usr/bin/mediainfo" Once you have an MediaInfo object, you can start inspecting tracks: diff --git a/lib/mediainfo.rb b/lib/mediainfo.rb index 9f9d5ac..d576b6b 100644 --- a/lib/mediainfo.rb +++ b/lib/mediainfo.rb @@ -6,9 +6,24 @@ module MediaInfo + def self.which(cmd) + exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] + ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| + exts.each { |ext| + exe = File.join(path, "#{cmd}#{ext}") + return exe if File.executable?(exe) && !File.directory?(exe) + } + end + return nil + end + # Allow user to set custom mediainfo_path with ENV['MEDIAINFO_PATH'] def self.location - ENV['MEDIAINFO_PATH'].nil? ? mediainfo_location = '/usr/local/bin/mediainfo' : mediainfo_location = ENV['MEDIAINFO_PATH'] + if ENV['MEDIAINFO_PATH'].nil? + mediainfo_location = which('mediainfo') + else + mediainfo_location = ENV['MEDIAINFO_PATH'] + end raise EnvironmentError, "#{mediainfo_location} cannot be found. Are you sure mediainfo is installed?" unless ::File.exist? mediainfo_location return mediainfo_location end @@ -57,7 +72,7 @@ def self.from(input) def self.from_string(input) return from_xml(input) if input.include?(' 1.16' + s.add_development_dependency 'bundler', '~> 2' s.add_development_dependency 'rake', '~> 12.3' s.add_development_dependency 'rspec', '~> 3.0' - s.add_development_dependency 'nokogiri', '~> 1.8' # Ability to parse XML response # Optional and should be included by user in their own gemfile + s.add_development_dependency 'nokogiri', '>= 1.8', '< 2.0' # Ability to parse XML response # Optional and should be included by user in their own gemfile if s.respond_to? :specification_version then current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION diff --git a/spec/fixtures/xml/multiple_streams_with:id-2.xml b/spec/fixtures/xml/multiple_streams_with:id-2.xml new file mode 100644 index 0000000..1d43790 --- /dev/null +++ b/spec/fixtures/xml/multiple_streams_with:id-2.xml @@ -0,0 +1,117 @@ + + + + + /Users/seth/diversion/hdcloud/test/videos/brightcove/VzbWkxMTrgYv8UoOiXZrbzowe0CV8wIr-me2-grunt.mov + MPEG-4 + QuickTime + qt + 101 MiB + 1mn 25s + 9 872 Kbps + UTC 2009-08-18 16:42:50 + UTC 2009-08-18 16:42:55 + Sorenson Squeeze 5.0 + Apple QuickTime + (Binary) + + + 2 + AVC + Advanced Video Codec + Baseline@L3.2 + No + 4 frames + avc1 + Advanced Video Coding + 1mn 25s + Variable + 9 392 Kbps + 1 280 pixels + 720 pixels + 16:9 + Variable + 29.970 fps + 29.940 fps + 29.970 fps + NTSC + 24 bits + 4:2:0 + Progressive + 0.340 + 95.6 MiB (95%) + UTC 2009-08-17 05:05:13 + UTC 2009-08-18 16:42:55 + + + 6 + AVC + Advanced Video Codec + Baseline@L3.2 + No + 4 frames + avc1 + Advanced Video Coding + 4s 170ms + Variable + 656 Kbps + 1 280 pixels + 720 pixels + 16:9 + Constant + 29.970 fps + NTSC + 24 bits + 4:2:0 + Progressive + 0.024 + 334 KiB (0%) + UTC 2009-08-18 16:42:20 + UTC 2009-08-18 16:42:56 + + + 1 + AAC + Advanced Audio Codec + Version 4 + LC + No + 40 + 1mn 25s + Variable + 256 Kbps + 2 channels + L R + 48.0 KHz + 16 bits + 2.61 MiB (3%) + UTC 2009-08-17 05:05:13 + UTC 2009-08-18 16:42:55 + + + 5 + AAC + Advanced Audio Codec + Version 4 + LC + No + 40 + 4s 156ms + Constant + 256 Kbps + 2 channels + L R + 44.1 KHz + 16 bits + 130 KiB (0%) + UTC 2009-08-18 16:42:20 + UTC 2009-08-18 16:42:56 + + + 3 + UTC 2009-08-18 16:42:20 + UTC 2009-08-18 16:42:56 + 3733 + + + diff --git a/spec/mediainfo_spec.rb b/spec/mediainfo_spec.rb index 297550c..5654c6b 100644 --- a/spec/mediainfo_spec.rb +++ b/spec/mediainfo_spec.rb @@ -3,7 +3,6 @@ describe 'location class method' do context 'when the mediainfo bin path (MEDIAINFO_PATH) is valid' do - include_context 'sets MEDIAINFO_PATH to default value' it 'does not raise an error' do expect{MediaInfo.location}.not_to raise_error @@ -29,7 +28,6 @@ describe 'version class method' do context 'when the mediainfo bin path (MEDIAINFO_PATH) is valid' do - include_context 'sets MEDIAINFO_PATH to default value' it 'does not raise an error' do expect{MediaInfo.version}.to_not raise_error @@ -48,7 +46,6 @@ describe 'xml_parser class method' do context 'when the chosen parser (MEDIAINFO_XML_PARSER) is the default one' do - include_context 'sets MEDIAINFO_XML_PARSER to default value' it 'does not raise an error' do expect{MediaInfo.version}.to_not raise_error @@ -78,7 +75,6 @@ describe 'from class method' do context 'when the chosen parser (MEDIAINFO_XML_PARSER) is the default one' do - include_context 'sets MEDIAINFO_XML_PARSER to default value' it_behaves_like 'expected from class method for a file' it_behaves_like 'expected from class method for a url' diff --git a/spec/mediainfo_tracks_attributes_spec.rb b/spec/mediainfo_tracks_attributes_spec.rb index eae88ba..6545a4a 100644 --- a/spec/mediainfo_tracks_attributes_spec.rb +++ b/spec/mediainfo_tracks_attributes_spec.rb @@ -5,7 +5,6 @@ describe '.sanitize_element_value class method' do context 'when the chosen parser (MEDIAINFO_XML_PARSER) is the default one' do - include_context 'sets MEDIAINFO_XML_PARSER to default value' it 'standardizes the names correctly' do expect(MediaInfo.from(xml_files_content[:sample_mov]).video.bit_rate).to be(nil) diff --git a/spec/mediainfo_tracks_spec.rb b/spec/mediainfo_tracks_spec.rb index 8c2cdd9..c44e43b 100644 --- a/spec/mediainfo_tracks_spec.rb +++ b/spec/mediainfo_tracks_spec.rb @@ -3,7 +3,6 @@ describe '*? for each types instance methods' do context 'when the chosen parser (MEDIAINFO_XML_PARSER) is the default one' do - include_context 'sets MEDIAINFO_XML_PARSER to default value' it_behaves_like 'for a valid collection of file path of videos' do let(:videos) { videos_xml_files_content } @@ -57,7 +56,6 @@ describe '.count for each types instance method' do context 'when the chosen parser (MEDIAINFO_XML_PARSER) is the default one' do - include_context 'sets MEDIAINFO_XML_PARSER to default value' context 'when the specified type is included in these Tracks' do it 'returns the number of occurrences of this type' do @@ -87,7 +85,6 @@ describe '.extra method for \'general\' type' do context 'when the chosen parser (MEDIAINFO_XML_PARSER) is the default one' do - include_context 'sets MEDIAINFO_XML_PARSER to default value' context 'when the submitted file has been generated by an Apple device' do it 'does not return nil' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0053e9d..ec6d38e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ require 'mediainfo' require 'spec_shared_contexts' require 'spec_shared_examples' +require 'pry' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure diff --git a/spec/spec_shared_contexts.rb b/spec/spec_shared_contexts.rb index 8484bd8..aa0eb5d 100644 --- a/spec/spec_shared_contexts.rb +++ b/spec/spec_shared_contexts.rb @@ -1,10 +1,6 @@ # Shared variables RSpec.shared_context 'Shared variables' do - # Set ENVs back to default - ENV['MEDIAINFO_PATH'] = nil - ENV['MEDIAINFO_XML_PARSER'] = nil - # Listing of files path base_local_path = './spec/fixtures/' @@ -64,30 +60,19 @@ # MEDIAINFO_PATH -RSpec.shared_context 'sets MEDIAINFO_PATH to default value' do - before(:all) do - ENV['MEDIAINFO_PATH'] = nil - end -end - RSpec.shared_context 'sets MEDIAINFO_PATH to invalid value' do + mip = ENV['MEDIAINFO_PATH'] # Allows us to set MEDIAINFO_PATH back to what the user/env set it as before(:all) do ENV['MEDIAINFO_PATH'] = '/invalid/path/to/mediablinfo' end after(:all) do - ENV['MEDIAINFO_PATH'] = nil + ENV['MEDIAINFO_PATH'] = mip end end # MEDIAINFO_XML_PARSER -RSpec.shared_context 'sets MEDIAINFO_XML_PARSER to default value' do - before(:all) do - ENV['MEDIAINFO_XML_PARSER'] = nil - end -end - RSpec.shared_context 'sets MEDIAINFO_XML_PARSER to nokogiri' do before(:all) do ENV['MEDIAINFO_XML_PARSER'] = 'nokogiri' diff --git a/spec/spec_shared_examples.rb b/spec/spec_shared_examples.rb index c175b6d..3df42b0 100644 --- a/spec/spec_shared_examples.rb +++ b/spec/spec_shared_examples.rb @@ -8,6 +8,10 @@ expect{MediaInfo.from(input)}.not_to raise_error end + it 'colon in path does not raise an error' do + expect{MediaInfo.from('./spec/fixtures/xml/multiple_streams_with:id-2.xml')}.not_to raise_error + end + it 'returns an instance of MediaInfo::Tracks' do expect(MediaInfo.from(input)).to be_an_instance_of(MediaInfo::Tracks) end @@ -15,6 +19,7 @@ it 'returns an object with a valid xml output' do expect(MediaInfo.from(input).xml.include?('?xml')).to be true end + end context 'when submitted an invalid file path' do