ffprober 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Changes.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.4.3 / 2015-06-22
2
+ ===================
3
+
4
+ * add support for ffmpeg 2.6.3
5
+
1
6
  0.4.2 / 2015-03-27
2
7
  ===================
3
8
 
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- gem 'pry'
3
+ gem "pry"
4
+ gem "rubocop"
4
5
  gem "codeclimate-test-reporter", require: nil
5
6
 
6
7
  # Specify your gem's dependencies in ffprober.gemspec
@@ -0,0 +1,4 @@
1
+ require_relative "../lib/ffprober"
2
+
3
+ parser = Ffprober::Parser.from_file("../spec/assets/sample video.m4v")
4
+ puts parser.video_streams.inspect
@@ -0,0 +1,5 @@
1
+ module Ffprober
2
+ module Errors
3
+ class InvalidInputFileError < ::StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ module Ffprober
2
+ module Ffmpeg
3
+ class Finder
4
+ def self.path
5
+ @path ||= begin
6
+ path = ENV["PATH"].split(File::PATH_SEPARATOR).detect do |path_to_check|
7
+ File.executable?(File.join(path_to_check, executable_name))
8
+ end
9
+
10
+ path && File.expand_path(executable_name, path)
11
+ end
12
+ end
13
+
14
+ def self.executable_name
15
+ @executable_name ||= self.windows? ? "ffprobe.exe" : "ffprobe"
16
+ end
17
+
18
+ def self.windows?
19
+ !!(RUBY_PLATFORM =~ /(mingw|mswin)/)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ module Ffprober
2
+ module Ffmpeg
3
+ class Version
4
+ VERSION_REGEX = /^(ffprobe|avprobe|ffmpeg) version (\d+)\.?(\d+)\.?(\d+)*/
5
+ NIGHTLY_REGEX = /^(ffprobe|avprobe|ffmpeg) version (N|git)-/
6
+
7
+ def version
8
+ @version ||= Gem::Version.new(parse_version.join("."))
9
+ end
10
+
11
+ def nightly?
12
+ !!(ffprobe_version_output =~ NIGHTLY_REGEX)
13
+ end
14
+
15
+ private
16
+
17
+ def parse_version
18
+ @parse_version ||= begin
19
+ ffprobe_version_output.match(VERSION_REGEX) do |match|
20
+ [match[2].to_i, match[3].to_i, match[4].to_i]
21
+ end || [0, 0, 0]
22
+ end
23
+ end
24
+
25
+ def ffprobe_version_output
26
+ @ffprobe_version_output ||= ffprobe_finder.path.nil? ? "" : `#{ffprobe_finder.path} -version`
27
+ end
28
+
29
+ def ffprobe_finder
30
+ Ffprober::Ffmpeg::Finder
31
+ end
32
+
33
+ def to_s
34
+ parse_version.join(".")
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ module Ffprober
2
+ module Ffmpeg
3
+ class VersionValidator
4
+ MIN_VERSION = Gem::Version.new("0.9.0")
5
+ MAX_VERSION = Gem::Version.new("2.6.3")
6
+
7
+ def initialize(ffmpeg_version)
8
+ @ffmpeg_version = ffmpeg_version
9
+ end
10
+
11
+ def valid?
12
+ ffmpeg_version.nightly? || version_requirement_statisfied?
13
+ end
14
+
15
+ private
16
+
17
+ def version_requirement_statisfied?
18
+ version = ffmpeg_version.version
19
+ (MIN_VERSION <= version && version <= MAX_VERSION)
20
+ end
21
+
22
+ def ffmpeg_version
23
+ @ffmpeg_version
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,41 +1,21 @@
1
1
  module Ffprober
2
2
  class FfprobeVersion
3
- VERSION_REGEX = /^(ffprobe|avprobe|ffmpeg) version (\d+)\.?(\d+)\.?(\d+)*/
4
- NIGHTLY_REGEX = /^(ffprobe|avprobe|ffmpeg) version (N|git)-/
5
-
6
- MIN_VERSION = Gem::Version.new('0.9.0')
7
- MAX_VERSION = Gem::Version.new('2.5.4')
8
-
9
3
  def self.valid?
10
4
  new.valid?
11
5
  end
12
6
 
13
- def self.version
14
- new.version
15
- end
16
-
17
7
  def valid?
18
- nightly? || (MIN_VERSION <= version && version <= MAX_VERSION)
8
+ validator.valid?
19
9
  end
20
10
 
21
- def parse_version
22
- @parse_version ||= begin
23
- ffprobe_version_output.match(VERSION_REGEX) do |match|
24
- [match[2].to_i, match[3].to_i, match[4].to_i]
25
- end || [0, 0, 0]
26
- end
27
- end
11
+ private
28
12
 
29
- def version
30
- @version ||= Gem::Version.new(parse_version.join('.'))
31
- end
32
-
33
- def nightly?
34
- !!(ffprobe_version_output =~ NIGHTLY_REGEX)
13
+ def validator
14
+ Ffprober::Ffmpeg::VersionValidator.new(version)
35
15
  end
36
16
 
37
- def ffprobe_version_output
38
- @ffprobe_version_output ||= Ffprober.path.nil? ? '' : `#{Ffprober.path} -version`
17
+ def version
18
+ Ffprober::Ffmpeg::Version.new
39
19
  end
40
20
  end
41
21
  end
@@ -1,66 +1,20 @@
1
- require 'shellwords'
1
+ require "shellwords"
2
2
 
3
3
  module Ffprober
4
4
  class Parser
5
5
  def self.from_file(file_to_parse)
6
6
  unless FfprobeVersion.valid?
7
- fail ArgumentError.new("no or unsupported ffprobe version found.\
8
- (version: #{FfprobeVersion.new.version})")
7
+ fail ArgumentError.new("no or unsupported ffprobe version found. (version: #{Ffprober::Ffmpeg::Version.new})")
9
8
  end
10
9
 
11
- unless File.exist?(file_to_parse)
12
- fail ArgumentError.new("File not found #{file_to_parse}")
13
- end
14
-
15
- json_output = `#{Ffprober.path} #{options} #{Shellwords.escape(file_to_parse)}`
16
- from_json(json_output)
10
+ file_parser = Ffprober::Parsers::File.new(file_to_parse)
11
+ json_parser = file_parser.load
12
+ Ffprober::Wrapper.new(json_parser.json)
17
13
  end
18
14
 
19
15
  def self.from_json(json_to_parse)
20
- parser = new
21
- parser.parse(json_to_parse)
22
- parser
23
- end
24
-
25
- def parse(json_to_parse)
26
- fail ArgumentError.new('No JSON input data') if json_to_parse.nil?
27
- @json = JSON.parse(json_to_parse, symbolize_names: true)
28
- end
29
-
30
- def format
31
- @format ||= Ffprober::Format.new(@json[:format])
32
- end
33
-
34
- def video_streams
35
- @video_streams ||= stream_by_codec('video').map { |stream| Ffprober::VideoStream.new(stream) }
36
- end
37
-
38
- def audio_streams
39
- @audio_streams ||= stream_by_codec('audio').map { |stream| Ffprober::AudioStream.new(stream) }
40
- end
41
-
42
- def subtitle_streams
43
- @subtitle_streams ||= stream_by_codec('subtitle').map { |stream| Ffprober::SubtitleStream.new(stream) }
44
- end
45
-
46
- def chapters
47
- @chapters ||= @json[:chapters].map { |chapter| Ffprober::Chapter.new(chapter) }
48
- end
49
-
50
- private
51
-
52
- def self.options
53
- options = '-v quiet -print_format json -show_format -show_streams'
54
- options << ' -show_chapters' if FfprobeVersion.version >= Gem::Version.new('2.0.0')
55
- options
56
- end
57
-
58
- def stream_by_codec(codec_type)
59
- streams.select { |stream| stream[:codec_type] == codec_type }
60
- end
61
-
62
- def streams
63
- @json[:streams]
16
+ json_parser = Ffprober::Parsers::Json.new(json_to_parse)
17
+ Ffprober::Wrapper.new(json_parser.json)
64
18
  end
65
19
  end
66
20
  end
@@ -0,0 +1,34 @@
1
+ module Ffprober
2
+ module Parsers
3
+ class File
4
+ def initialize(file_to_parse)
5
+ unless ::File.exist?(file_to_parse)
6
+ fail ArgumentError.new("File not found #{file_to_parse}")
7
+ end
8
+
9
+ @file_to_parse = file_to_parse
10
+ end
11
+
12
+ def load
13
+ json_output = `#{ffprobe_finder.path} #{options} '#{@file_to_parse}'`
14
+ Ffprober::Parsers::Json.new(json_output)
15
+ end
16
+
17
+ private
18
+
19
+ def options
20
+ options = "-v quiet -print_format json -show_format -show_streams"
21
+ options << " -show_chapters" if ffprobe_version.version >= Gem::Version.new("2.0.0")
22
+ options
23
+ end
24
+
25
+ def ffprobe_version
26
+ Ffprober::Ffmpeg::Version.new
27
+ end
28
+
29
+ def ffprobe_finder
30
+ Ffprober::Ffmpeg::Finder
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ module Ffprober
2
+ module Parsers
3
+ class Json
4
+ def initialize(json_to_parse)
5
+ fail ArgumentError.new("No JSON input data") if json_to_parse.nil?
6
+ @json_to_parse = json_to_parse
7
+ end
8
+
9
+ def json
10
+ @json ||= JSON.parse(@json_to_parse, symbolize_names: true)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,4 +1,4 @@
1
1
  module Ffprober
2
2
  class SubtitleStream < Stream
3
3
  end
4
- end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module Ffprober
2
- VERSION = '0.4.2'
2
+ VERSION = "0.4.3"
3
3
  end
@@ -0,0 +1,41 @@
1
+ module Ffprober
2
+ class Wrapper
3
+ def initialize(json)
4
+ @json = json
5
+ end
6
+
7
+ def format
8
+ @format ||= Ffprober::Format.new(json[:format])
9
+ end
10
+
11
+ def video_streams
12
+ @video_streams ||= stream_by_codec("video").map { |data| Ffprober::VideoStream.new(data) }
13
+ end
14
+
15
+ def audio_streams
16
+ @audio_streams ||= stream_by_codec("audio").map { |data| Ffprober::AudioStream.new(data) }
17
+ end
18
+
19
+ def chapters
20
+ @chapters ||= json[:chapters].map { |chapter| Ffprober::Chapter.new(chapter) }
21
+ end
22
+
23
+ def subtitle_streams
24
+ @subtitle_streams ||= stream_by_codec("subtitle").map { |stream| Ffprober::SubtitleStream.new(stream) }
25
+ end
26
+
27
+ private
28
+
29
+ def stream_by_codec(codec_type)
30
+ streams.select { |stream| stream[:codec_type] == codec_type }
31
+ end
32
+
33
+ def streams
34
+ json[:streams]
35
+ end
36
+
37
+ def json
38
+ @json
39
+ end
40
+ end
41
+ end
data/lib/ffprober.rb CHANGED
@@ -1,33 +1,22 @@
1
- require_relative 'ffprober/version'
2
- require_relative 'ffprober/dynamic_initializer'
3
- require_relative 'ffprober/parser'
4
- require_relative 'ffprober/format'
5
- require_relative 'ffprober/stream'
6
- require_relative 'ffprober/audio_stream'
7
- require_relative 'ffprober/video_stream'
8
- require_relative 'ffprober/subtitle_stream'
9
- require_relative 'ffprober/chapter'
10
- require_relative 'ffprober/ffprobe_version'
11
- require 'json'
1
+ require_relative "ffprober/version"
2
+ require_relative "ffprober/dynamic_initializer"
3
+ require_relative "ffprober/parser"
4
+ require_relative "ffprober/format"
5
+ require_relative "ffprober/stream"
6
+ require_relative "ffprober/audio_stream"
7
+ require_relative "ffprober/video_stream"
8
+ require_relative "ffprober/subtitle_stream"
9
+ require_relative "ffprober/chapter"
10
+ require_relative "ffprober/ffprobe_version"
11
+ require_relative "ffprober/wrapper"
12
+ require_relative "ffprober/errors"
12
13
 
13
- module Ffprober
14
- def self.path
15
- @path ||= begin
16
- path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |path_to_check|
17
- File.executable?(File.join(path_to_check, executable_name))
18
- end
19
-
20
- path && File.expand_path(executable_name, path)
21
- end
22
- end
23
-
24
- def self.executable_name
25
- @executable_name ||= self.windows? ? 'ffprobe.exe' : 'ffprobe'
26
- end
14
+ require_relative "ffprober/ffmpeg/finder"
15
+ require_relative "ffprober/ffmpeg/version"
16
+ require_relative "ffprober/ffmpeg/version_validator"
17
+ require_relative "ffprober/parsers/file"
18
+ require_relative "ffprober/parsers/json"
19
+ require "json"
27
20
 
28
- def self.windows?
29
- !!(RUBY_PLATFORM =~ /(mingw|mswin)/)
30
- end
31
-
32
- class InvalidInputFileError < ::StandardError; end
21
+ module Ffprober
33
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffprober
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - beanieboi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-27 00:00:00.000000000 Z
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -47,26 +47,36 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
49
  - ".rspec"
50
+ - ".rubocop.yml"
50
51
  - ".ruby-version"
51
52
  - ".travis.yml"
53
+ - CODE_OF_CONDUCT.md
52
54
  - CONTRIBUTING.md
53
55
  - Changes.md
54
56
  - Gemfile
55
57
  - LICENSE
56
58
  - README.md
57
59
  - Rakefile
60
+ - examples/from_file.rb
58
61
  - ffprober.gemspec
59
62
  - lib/ffprober.rb
60
63
  - lib/ffprober/audio_stream.rb
61
64
  - lib/ffprober/chapter.rb
62
65
  - lib/ffprober/dynamic_initializer.rb
66
+ - lib/ffprober/errors.rb
67
+ - lib/ffprober/ffmpeg/finder.rb
68
+ - lib/ffprober/ffmpeg/version.rb
69
+ - lib/ffprober/ffmpeg/version_validator.rb
63
70
  - lib/ffprober/ffprobe_version.rb
64
71
  - lib/ffprober/format.rb
65
72
  - lib/ffprober/parser.rb
73
+ - lib/ffprober/parsers/file.rb
74
+ - lib/ffprober/parsers/json.rb
66
75
  - lib/ffprober/stream.rb
67
76
  - lib/ffprober/subtitle_stream.rb
68
77
  - lib/ffprober/version.rb
69
78
  - lib/ffprober/video_stream.rb
79
+ - lib/ffprober/wrapper.rb
70
80
  homepage: https://github.com/beanieboi/ffprober
71
81
  licenses:
72
82
  - MIT
@@ -92,3 +102,4 @@ signing_key:
92
102
  specification_version: 4
93
103
  summary: a Ruby wrapper for ffprobe (part of ffmpeg)
94
104
  test_files: []
105
+ has_rdoc: