mini_mediainfo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 816cdb2d585902ded6c9f53fdca680d401045c6f
4
+ data.tar.gz: 2ae6b4e586e26f8a73d6555d1461cf9a8a9dd27a
5
+ SHA512:
6
+ metadata.gz: 7eb28facd822f662ab267efe7b44d3f45788abc92d44c405ca71d7648cad932ce7a4128111e519e87ab847df41456051e598bfd07f1a29cd3d8e70275d92e387
7
+ data.tar.gz: 1c182010720b7b559efa77970ca7b657a14cf4cbcec6a85fe0277edb0866f8de0251df061af8e75d1578914e6ccd09d3d23daed757c3045a5a5b114c4d90fa73
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ .rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mini_mediainfo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Karl Forsman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # MiniMediainfo
2
+
3
+ A Ruby wrapper for mediainfo CLI.
4
+
5
+ ## Installation
6
+
7
+ As a prerequisite you will need to have the mediainfo binary installed on your system.
8
+ For example:
9
+
10
+ OS X:
11
+
12
+ brew install mediainfo
13
+
14
+ Ubuntu:
15
+
16
+ sudo add-apt-repository ppa:shiki/mediainfo
17
+ sudo apt-get update
18
+ sudo apt-get install mediainfo
19
+
20
+
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ gem 'mini_mediainfo'
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install mini_mediainfo
33
+
34
+ ## Usage
35
+
36
+ require 'mini_mediainfo'
37
+ media = MiniMediainfo::Media.new("http://techslides.com/demos/sample-videos/small.mp4")
38
+ media.introspect
39
+ media.meta['General']['Format'] # => "MPEG-4"
40
+ media.meta['General']['Duration'] # => "5s 568ms"
41
+ media.meta['Audio']['Compression mode'] # => "Lossy"
42
+
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task :default => :spec
@@ -0,0 +1,75 @@
1
+ require 'open3'
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module MiniMediainfo
6
+
7
+ class Media
8
+
9
+ attr_reader :uri
10
+
11
+ def initialize(uri, options={})
12
+ unless File.exists?(uri)
13
+ if uri =~ URI::regexp(["ftp", "http", "https"])
14
+ url = URI.parse(uri)
15
+ req = Net::HTTP.new(url.host, url.port)
16
+ res = req.request_head(url.path)
17
+ if res.code != "200"
18
+ raise "Error: #{uri} is not accessible"
19
+ end
20
+ else
21
+ raise "Error: the file '#{uri}' does not exist"
22
+ end
23
+ end
24
+ @uri = uri
25
+ @introspection_data = {}
26
+ end
27
+
28
+ def introspect()
29
+ cmd = "mediainfo \"#{@uri}\""
30
+ key = ''
31
+ lines = []
32
+ keys = []
33
+ entries = []
34
+
35
+ Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
36
+ while line = stdout_err.gets
37
+ lines << line
38
+ end
39
+
40
+ exit_status = wait_thr.value
41
+ unless exit_status.success?
42
+ abort "FAILED !!! #{cmd}"
43
+ end
44
+ end
45
+
46
+ key = ''
47
+ lines.each do |l|
48
+ if l.index(':').to_i > 0
49
+ media_attrs = [l.slice(0..l.index(':')-1), l.slice(l.index(':')+1..-1)].collect {|a| a.strip}
50
+ else
51
+ if l.strip.length > 0
52
+ key = l.strip
53
+ keys.push(key)
54
+ end
55
+ end
56
+
57
+ if (key && key.length > 0) && (media_attrs && media_attrs.length == 2)
58
+ entries.push([key, media_attrs[0], media_attrs[1]])
59
+ end
60
+ end
61
+
62
+ keys.each do |k|
63
+ per_key_entries = entries.select {|e| e[0] == k}
64
+ per_key_hash = Hash[per_key_entries.each {|e| e.shift}]
65
+ @introspection_data[k] = per_key_hash
66
+ end
67
+ end
68
+
69
+ def meta()
70
+ return @introspection_data
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,3 @@
1
+ module MiniMediainfo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ require "mini_mediainfo/version"
2
+ require "mini_mediainfo/media"
3
+ require 'open3'
4
+
5
+ module MiniMediainfo
6
+
7
+ def self.platform_supported?
8
+ /(darwin|linux|unix)/ =~ RUBY_PLATFORM
9
+ end
10
+
11
+ def self.mediainfo_version
12
+ cmd = "mediainfo --version"
13
+ out = Open3.popen3(cmd) { |stdin, stdout, stderr| stdout.read }
14
+ out.gsub("\n","")
15
+ end
16
+
17
+ def self.mediainfo_binary
18
+ cmd = "which mediainfo"
19
+ Open3.popen3(cmd) { |stdin, stdout, stderr| stdout.read }
20
+ end
21
+
22
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mini_mediainfo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mini_mediainfo"
8
+ spec.version = MiniMediainfo::VERSION
9
+ spec.authors = ["Karl Forsman"]
10
+ spec.email = ["ko.forsman@gmail.com"]
11
+ spec.description = %q{A Ruby wrapper for mediainfo CLI.}
12
+ spec.summary = %q{A minimalistic gem for wrapping mediainfo commands and parsing it's output.}
13
+ spec.homepage = "https://github.com/kforsman/mini_mediainfo"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "thin"
24
+ spec.add_development_dependency "sinatra"
25
+ end
Binary file
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'support/test_server'
3
+ require 'rspec'
4
+ require "mini_mediainfo/media"
5
+ require "net/http"
6
+
7
+
8
+ describe MiniMediainfo::Media do
9
+
10
+ context "when introspecting files" do
11
+
12
+ it "should introspect audio file" do
13
+ media = MiniMediainfo::Media.new("spec/fixtures/napoleon.mp3")
14
+ media.should_not be_nil
15
+ media.introspect
16
+ media.meta.is_a?(Hash).should be_true
17
+ ['General', 'Audio'].each do |k|
18
+ media.meta.has_key?(k).should be_true
19
+ media.meta[k].size.should > 0
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ context "when introspecting over http" do
26
+
27
+ before(:all) do
28
+ @server_thread = Thread.new {TestServer.run!}
29
+ sleep(1)
30
+ end
31
+
32
+ after(:all) do
33
+ @server_thread.kill
34
+ end
35
+
36
+ it "should introspect video url" do
37
+ res = Net::HTTP.start('localhost', 4567) { |http| http.get('/small.mp4') }
38
+ res.code.should == '200'
39
+
40
+ media = MiniMediainfo::Media.new("http://localhost:4567/small.mp4")
41
+ media.should_not be_nil
42
+ media.introspect
43
+ media.meta.is_a?(Hash).should be_true
44
+ ['General', 'Audio', 'Video'].each do |k|
45
+ media.meta.has_key?(k).should be_true
46
+ media.meta[k].size.should > 0
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe MiniMediainfo do
4
+
5
+ it "should determine if the platform is supported" do
6
+ subject.respond_to?(:platform_supported?).should be_true
7
+ subject.platform_supported?.should be_true
8
+ end
9
+
10
+ it "should get mediainfo version" do
11
+ version = subject.mediainfo_version
12
+ version.should_not be_nil
13
+ version.should match(/MediaInfoLib - v/)
14
+ end
15
+
16
+ it "should tell which mediainfo binary" do
17
+ subject.mediainfo_binary.should match /\/mediainfo/
18
+ end
19
+
20
+ end
@@ -0,0 +1,8 @@
1
+ require 'mini_mediainfo'
2
+
3
+ Dir["./spec/support/**/*.rb"].each {|f| require f}
4
+
5
+ RSpec.configure do |config|
6
+ # TODO:
7
+ end
8
+
@@ -0,0 +1,10 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+
7
+ <p>Hello MiniMediainfo</p>
8
+
9
+ </body>
10
+ </html>
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,22 @@
1
+ require 'rack'
2
+ require 'thin'
3
+ require 'sinatra'
4
+
5
+ class TestServer < Sinatra::Base
6
+
7
+ APP_ROOT = './spec/support'
8
+
9
+ get '*' do
10
+ rpath=File.join(APP_ROOT,params[:splat][0][1..-1])
11
+ mimetype = `file -Ib #{rpath}`.gsub(/\n/,"")
12
+ #puts "serving #{rpath} with mimetype #{mimetype}"
13
+ send_file rpath, :stream=>true, :type=>mimetype, :disposition=>:inline
14
+ end
15
+
16
+ end
17
+
18
+ #t = Thread.new {TestServer.run!}
19
+ #t.join
20
+
21
+
22
+
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mini_mediainfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Karl Forsman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A Ruby wrapper for mediainfo CLI.
84
+ email:
85
+ - ko.forsman@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/mini_mediainfo.rb
96
+ - lib/mini_mediainfo/media.rb
97
+ - lib/mini_mediainfo/version.rb
98
+ - mini_mediainfo.gemspec
99
+ - spec/fixtures/napoleon.mp3
100
+ - spec/media_spec.rb
101
+ - spec/mini_mediainfo_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/support/index.html
104
+ - spec/support/small.3gp
105
+ - spec/support/small.flv
106
+ - spec/support/small.mp4
107
+ - spec/support/small.ogv
108
+ - spec/support/small.webm
109
+ - spec/support/test_server.rb
110
+ homepage: https://github.com/kforsman/mini_mediainfo
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.0.3
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: A minimalistic gem for wrapping mediainfo commands and parsing it's output.
134
+ test_files:
135
+ - spec/fixtures/napoleon.mp3
136
+ - spec/media_spec.rb
137
+ - spec/mini_mediainfo_spec.rb
138
+ - spec/spec_helper.rb
139
+ - spec/support/index.html
140
+ - spec/support/small.3gp
141
+ - spec/support/small.flv
142
+ - spec/support/small.mp4
143
+ - spec/support/small.ogv
144
+ - spec/support/small.webm
145
+ - spec/support/test_server.rb