ffprober 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +3 -1060
- data/.ruby-version +1 -1
- data/.travis.yml +5 -10
- data/CODE_OF_CONDUCT.md +67 -7
- data/Changes.md +7 -0
- data/Gemfile +7 -5
- data/README.md +2 -2
- data/Rakefile +6 -4
- data/bin/console +4 -3
- data/circle.yml +5 -0
- data/examples/from_file.rb +4 -2
- data/ffprober.gemspec +15 -13
- data/lib/ffprober.rb +27 -19
- data/lib/ffprober/audio_stream.rb +2 -0
- data/lib/ffprober/chapter.rb +2 -0
- data/lib/ffprober/data_stream.rb +2 -0
- data/lib/ffprober/dynamic_initializer.rb +5 -4
- data/lib/ffprober/ffmpeg/exec.rb +19 -10
- data/lib/ffprober/ffmpeg/finder.rb +7 -5
- data/lib/ffprober/ffmpeg/version.rb +7 -5
- data/lib/ffprober/ffmpeg/version_validator.rb +4 -4
- data/lib/ffprober/ffprobe_version.rb +2 -0
- data/lib/ffprober/format.rb +2 -0
- data/lib/ffprober/parser.rb +18 -9
- data/lib/ffprober/parsers/file.rb +6 -4
- data/lib/ffprober/parsers/json.rb +4 -2
- data/lib/ffprober/parsers/url.rb +30 -0
- data/lib/ffprober/stream.rb +2 -0
- data/lib/ffprober/subtitle_stream.rb +2 -0
- data/lib/ffprober/version.rb +3 -1
- data/lib/ffprober/video_stream.rb +2 -0
- data/lib/ffprober/wrapper.rb +17 -6
- metadata +19 -4
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ffprober
|
2
4
|
module Ffmpeg
|
3
5
|
class VersionValidator
|
4
|
-
MIN_VERSION = Gem::Version.new(
|
6
|
+
MIN_VERSION = Gem::Version.new('0.9.0')
|
5
7
|
|
6
8
|
def initialize(ffmpeg_version)
|
7
9
|
@ffmpeg_version = ffmpeg_version
|
@@ -17,9 +19,7 @@ module Ffprober
|
|
17
19
|
MIN_VERSION <= ffmpeg_version.version
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
@ffmpeg_version
|
22
|
-
end
|
22
|
+
attr_reader :ffmpeg_version
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/ffprober/format.rb
CHANGED
data/lib/ffprober/parser.rb
CHANGED
@@ -1,24 +1,33 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Ffprober
|
4
4
|
class Parser
|
5
5
|
def self.from_file(file_to_parse)
|
6
|
-
|
7
|
-
fail UnsupportedVersion, "found version: #{FfprobeVersion.version}"
|
8
|
-
end
|
6
|
+
check_version
|
9
7
|
|
10
|
-
if File.zero?(file_to_parse)
|
11
|
-
fail EmptyInput, file_to_parse
|
12
|
-
end
|
8
|
+
raise EmptyInput, file_to_parse if File.zero?(file_to_parse)
|
13
9
|
|
14
|
-
file_parser =
|
10
|
+
file_parser = Parsers::FileParser.new(file_to_parse)
|
15
11
|
json_parser = file_parser.load
|
16
12
|
Ffprober::Wrapper.new(json_parser.json)
|
17
13
|
end
|
18
14
|
|
15
|
+
def self.from_url(url_to_parse)
|
16
|
+
check_version
|
17
|
+
|
18
|
+
url_parser = Parsers::UrlParser.new(url_to_parse)
|
19
|
+
json_parser = url_parser.load
|
20
|
+
Ffprober::Wrapper.new(json_parser.json)
|
21
|
+
end
|
22
|
+
|
19
23
|
def self.from_json(json_to_parse)
|
20
|
-
json_parser =
|
24
|
+
json_parser = Parsers::JsonParser.new(json_to_parse)
|
21
25
|
Ffprober::Wrapper.new(json_parser.json)
|
22
26
|
end
|
27
|
+
|
28
|
+
def self.check_version
|
29
|
+
msg = "found version: #{FfprobeVersion.version}"
|
30
|
+
raise UnsupportedVersion, msg if FfprobeVersion.invalid?
|
31
|
+
end
|
23
32
|
end
|
24
33
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ffprober
|
2
4
|
module Parsers
|
3
|
-
class
|
4
|
-
def initialize(file_to_parse, exec=Ffprober::Ffmpeg::Exec.new)
|
5
|
+
class FileParser
|
6
|
+
def initialize(file_to_parse, exec = Ffprober::Ffmpeg::Exec.new)
|
5
7
|
unless ::File.exist?(file_to_parse)
|
6
|
-
|
8
|
+
raise ArgumentError, "File not found #{file_to_parse}"
|
7
9
|
end
|
8
10
|
|
9
11
|
@file_to_parse = file_to_parse
|
@@ -11,7 +13,7 @@ module Ffprober
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def load
|
14
|
-
|
16
|
+
JsonParser.new(@exec.json_output(@file_to_parse))
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ffprober
|
2
4
|
module Parsers
|
3
|
-
class
|
5
|
+
class JsonParser
|
4
6
|
def initialize(json_to_parse)
|
5
|
-
|
7
|
+
raise ArgumentError, 'No JSON input data' if json_to_parse.nil?
|
6
8
|
@json_to_parse = json_to_parse
|
7
9
|
end
|
8
10
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Ffprober
|
6
|
+
module Parsers
|
7
|
+
class UrlParser
|
8
|
+
VALID_URI_REGEX = /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
|
9
|
+
|
10
|
+
def initialize(url_to_parse, exec = Ffprober::Ffmpeg::Exec.new)
|
11
|
+
unless valid_url?(url_to_parse)
|
12
|
+
raise ArgumentError, "#{url_to_parse} is not a valid URL"
|
13
|
+
end
|
14
|
+
|
15
|
+
@url_to_parse = url_to_parse
|
16
|
+
@exec = exec
|
17
|
+
end
|
18
|
+
|
19
|
+
def load
|
20
|
+
JsonParser.new(@exec.json_output(@url_to_parse))
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def valid_url?(url)
|
26
|
+
URI.escape(url) =~ VALID_URI_REGEX
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/ffprober/stream.rb
CHANGED
data/lib/ffprober/version.rb
CHANGED
data/lib/ffprober/wrapper.rb
CHANGED
@@ -1,33 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ffprober
|
2
4
|
class Wrapper
|
3
5
|
attr_reader :json
|
4
6
|
|
5
7
|
def initialize(json)
|
8
|
+
raise FfprobeError, json[:error] if json[:error]
|
6
9
|
@json = json
|
7
10
|
end
|
8
11
|
|
9
12
|
def format
|
10
|
-
@format ||=
|
13
|
+
@format ||= Format.new(json[:format])
|
11
14
|
end
|
12
15
|
|
13
16
|
def video_streams
|
14
|
-
@video_streams ||= stream_by_codec(
|
17
|
+
@video_streams ||= stream_by_codec('video').map do |data|
|
18
|
+
VideoStream.new(data)
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def audio_streams
|
18
|
-
@audio_streams ||= stream_by_codec(
|
23
|
+
@audio_streams ||= stream_by_codec('audio').map do |data|
|
24
|
+
AudioStream.new(data)
|
25
|
+
end
|
19
26
|
end
|
20
27
|
|
21
28
|
def data_streams
|
22
|
-
@data_streams ||= stream_by_codec(
|
29
|
+
@data_streams ||= stream_by_codec('data').map do |data|
|
30
|
+
DataStream.new(data)
|
31
|
+
end
|
23
32
|
end
|
24
33
|
|
25
34
|
def chapters
|
26
|
-
@chapters ||= json[:chapters].map { |chapter|
|
35
|
+
@chapters ||= json[:chapters].map { |chapter| Chapter.new(chapter) }
|
27
36
|
end
|
28
37
|
|
29
38
|
def subtitle_streams
|
30
|
-
@subtitle_streams ||= stream_by_codec(
|
39
|
+
@subtitle_streams ||= stream_by_codec('subtitle').map do |stream|
|
40
|
+
SubtitleStream.new(stream)
|
41
|
+
end
|
31
42
|
end
|
32
43
|
|
33
44
|
private
|
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.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- beanieboi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
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'
|
41
55
|
description: a Ruby wrapper for ffprobe
|
42
56
|
email:
|
43
57
|
- beanie@benle.de
|
@@ -59,6 +73,7 @@ files:
|
|
59
73
|
- Rakefile
|
60
74
|
- bin/console
|
61
75
|
- bin/setup
|
76
|
+
- circle.yml
|
62
77
|
- examples/from_file.rb
|
63
78
|
- ffprober.gemspec
|
64
79
|
- lib/ffprober.rb
|
@@ -75,6 +90,7 @@ files:
|
|
75
90
|
- lib/ffprober/parser.rb
|
76
91
|
- lib/ffprober/parsers/file.rb
|
77
92
|
- lib/ffprober/parsers/json.rb
|
93
|
+
- lib/ffprober/parsers/url.rb
|
78
94
|
- lib/ffprober/stream.rb
|
79
95
|
- lib/ffprober/subtitle_stream.rb
|
80
96
|
- lib/ffprober/version.rb
|
@@ -100,9 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
116
|
version: '0'
|
101
117
|
requirements: []
|
102
118
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.7.3
|
104
120
|
signing_key:
|
105
121
|
specification_version: 4
|
106
122
|
summary: a Ruby wrapper for ffprobe (part of ffmpeg)
|
107
123
|
test_files: []
|
108
|
-
has_rdoc:
|