ffprober 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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("0.9.0")
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
- def ffmpeg_version
21
- @ffmpeg_version
22
- end
22
+ attr_reader :ffmpeg_version
23
23
  end
24
24
  end
25
25
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ffprober
2
4
  class FfprobeVersion
3
5
  def self.invalid?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ffprober
2
4
  class Format
3
5
  include Ffprober::DynamicInitializer
@@ -1,24 +1,33 @@
1
- require "shellwords"
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
- if FfprobeVersion.invalid?
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 = Ffprober::Parsers::File.new(file_to_parse)
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 = Ffprober::Parsers::Json.new(json_to_parse)
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 File
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
- fail ArgumentError.new("File not found #{file_to_parse}")
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
- Ffprober::Parsers::Json.new(@exec.json_output(@file_to_parse))
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 Json
5
+ class JsonParser
4
6
  def initialize(json_to_parse)
5
- fail ArgumentError.new("No JSON input data") if json_to_parse.nil?
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ffprober
2
4
  class Stream
3
5
  include Ffprober::DynamicInitializer
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ffprober
2
4
  class SubtitleStream < Stream
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ffprober
2
- VERSION = "0.5.1"
4
+ VERSION = '0.5.2'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ffprober
2
4
  class VideoStream < Stream
3
5
  end
@@ -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 ||= Ffprober::Format.new(json[:format])
13
+ @format ||= Format.new(json[:format])
11
14
  end
12
15
 
13
16
  def video_streams
14
- @video_streams ||= stream_by_codec("video").map { |data| Ffprober::VideoStream.new(data) }
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("audio").map { |data| Ffprober::AudioStream.new(data) }
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("data").map { |data| Ffprober::DataStream.new(data) }
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| Ffprober::Chapter.new(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("subtitle").map { |stream| Ffprober::SubtitleStream.new(stream) }
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.1
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: 2016-02-08 00:00:00.000000000 Z
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.5.1
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: