ehbrs-tools 0.16.1 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/runner/videos/probe.rb +3 -3
  3. data/lib/ehbrs/tools/version.rb +1 -1
  4. data/lib/ehbrs/videos/file.rb +4 -8
  5. data/lib/ehbrs/videos/track.rb +20 -10
  6. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +2 -0
  7. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +2 -0
  8. data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +2 -0
  9. data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +2 -0
  10. data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
  11. data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +1 -1
  12. data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
  13. data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
  14. data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +10 -2
  15. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +1 -1
  16. data/vendor/eac_cli/lib/eac_cli/definition.rb +34 -39
  17. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
  18. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
  19. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
  20. data/vendor/eac_cli/lib/eac_cli/parser.rb +21 -3
  21. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +88 -0
  22. data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
  23. data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  24. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
  25. data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  26. data/vendor/eac_cli/lib/eac_cli/runner.rb +2 -2
  27. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +1 -1
  28. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
  29. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  30. data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
  31. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +10 -0
  32. data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
  33. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +14 -5
  34. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
  35. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
  36. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  37. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  38. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
  39. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  40. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
  41. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
  42. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
  43. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
  44. metadata +17 -7
  45. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +0 -68
  46. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -38
  47. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -77
  48. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
  49. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/executables'
5
+ require 'fileutils'
6
+
7
+ module EhbrsRubyUtils
8
+ module Videos
9
+ class ConvertJob
10
+ FORMATS_TO_EXTENSIONS = {
11
+ 'matroska' => '.mkv'
12
+ }.freeze
13
+
14
+ enable_console_speaker
15
+ enable_simple_cache
16
+ common_constructor :input, :ffmpeg_convert_args do
17
+ self.input = input.to_pathname.expand_path
18
+ raise "Input file \"#{input}\" does not exist or is not a file" unless input.file?
19
+ end
20
+
21
+ def run
22
+ if converted.exist?
23
+ warn("Converted file already exist: \"#{converted}\"")
24
+ else
25
+ convert
26
+ swap
27
+ end
28
+ end
29
+
30
+ def target
31
+ input.dirname.join("#{input.basename('.*')}#{target_extension}")
32
+ end
33
+
34
+ private
35
+
36
+ def command_args_uncached
37
+ r = ['-i', input] + ffmpeg_convert_args
38
+ r += ['-f', format_by_input] if format_by_args.blank?
39
+ r + [converting]
40
+ end
41
+
42
+ def convert
43
+ infov 'Input', input
44
+ infov 'Target', target
45
+ infov 'Convert args', command_args.shelljoin
46
+ ::Ehbrs::Executables.ffmpeg.command.append(command_args).system!
47
+ end
48
+
49
+ def format_by_args_uncached
50
+ ffmpeg_convert_args.rindex('-f').if_present do |option_index|
51
+ ffmpeg_convert_args[option_index + 1]
52
+ end
53
+ end
54
+
55
+ def format_by_input
56
+ FORMATS_TO_EXTENSIONS.invert[target_extension_by_input].if_present { |v| return v }
57
+
58
+ raise 'Unknonwn target format'
59
+ end
60
+
61
+ def format_to_extension(format)
62
+ FORMATS_TO_EXTENSIONS[format].if_present(".#{format}")
63
+ end
64
+
65
+ def swap
66
+ ::FileUtils.mv(input, converted)
67
+ ::FileUtils.mv(converting, target)
68
+ end
69
+
70
+ def converting
71
+ target.basename_sub { |b| "#{b}.converting" }
72
+ end
73
+
74
+ def converted
75
+ input.basename_sub { |b| "#{b}.converted" }
76
+ end
77
+
78
+ def target_extension
79
+ target_extension_by_args || target_extension_by_input
80
+ end
81
+
82
+ def target_extension_by_args
83
+ format_by_args.if_present { |v| format_to_extension(v) }
84
+ end
85
+
86
+ def target_extension_by_input
87
+ ::File.extname(input)
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Videos
7
+ class Stream
8
+ enable_simple_cache
9
+ enable_listable
10
+
11
+ lists.add_symbol :codec_type, :audio, :video, :subtitle, :data
12
+
13
+ common_constructor :ffprobe_data do
14
+ self.ffprobe_data = ffprobe_data.symbolize_keys.freeze
15
+ self.class.lists.codec_type.value_validate!(codec_type)
16
+ end
17
+
18
+ lists.codec_type.each_value do |v|
19
+ define_method "#{v}?" do
20
+ codec_type == v
21
+ end
22
+ end
23
+
24
+ def to_s
25
+ "#{index}|#{codec_type}|#{codec_name}|#{language}"
26
+ end
27
+
28
+ def to_h
29
+ ffprobe_data
30
+ end
31
+
32
+ %i[index codec_name codec_long_name].each do |method_name|
33
+ define_method method_name do
34
+ ffprobe_data.fetch(method_name)
35
+ end
36
+ end
37
+
38
+ def codec_type
39
+ ffprobe_data.fetch(:codec_type).to_sym
40
+ end
41
+
42
+ def tags
43
+ ffprobe_data[:tags].if_present({}, &:symbolize_keys)
44
+ end
45
+
46
+ def language
47
+ tags[:language]
48
+ end
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehbrs-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-28 00:00:00.000000000 Z
11
+ date: 2020-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm-tools
@@ -231,19 +231,23 @@ files:
231
231
  - vendor/eac_cli/lib/eac_cli/core_ext.rb
232
232
  - vendor/eac_cli/lib/eac_cli/default_runner.rb
233
233
  - vendor/eac_cli/lib/eac_cli/definition.rb
234
+ - vendor/eac_cli/lib/eac_cli/definition/alternative.rb
234
235
  - vendor/eac_cli/lib/eac_cli/definition/argument_option.rb
235
236
  - vendor/eac_cli/lib/eac_cli/definition/base_option.rb
236
237
  - vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb
237
238
  - vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb
238
239
  - vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
239
240
  - vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb
241
+ - vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb
240
242
  - vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb
241
243
  - vendor/eac_cli/lib/eac_cli/parser.rb
244
+ - vendor/eac_cli/lib/eac_cli/parser/alternative.rb
245
+ - vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb
246
+ - vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb
247
+ - vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb
248
+ - vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb
242
249
  - vendor/eac_cli/lib/eac_cli/parser/collector.rb
243
250
  - vendor/eac_cli/lib/eac_cli/parser/error.rb
244
- - vendor/eac_cli/lib/eac_cli/parser/options_collection.rb
245
- - vendor/eac_cli/lib/eac_cli/parser/parse_result.rb
246
- - vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb
247
251
  - vendor/eac_cli/lib/eac_cli/patches.rb
248
252
  - vendor/eac_cli/lib/eac_cli/patches/object.rb
249
253
  - vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb
@@ -254,8 +258,11 @@ files:
254
258
  - vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb
255
259
  - vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb
256
260
  - vendor/eac_cli/lib/eac_cli/version.rb
261
+ - vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb
257
262
  - vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb
263
+ - vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb
258
264
  - vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb
265
+ - vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb
259
266
  - vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb
260
267
  - vendor/eac_cli/spec/rubocop_spec.rb
261
268
  - vendor/eac_cli/spec/spec_helper.rb
@@ -277,6 +284,7 @@ files:
277
284
  - vendor/eac_ruby_utils/README.rdoc
278
285
  - vendor/eac_ruby_utils/eac_ruby_utils.gemspec
279
286
  - vendor/eac_ruby_utils/lib/eac_ruby_utils.rb
287
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb
280
288
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/arguments_consumer.rb
281
289
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb
282
290
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb
@@ -362,6 +370,7 @@ files:
362
370
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/options_consumer.rb
363
371
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
364
372
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module.rb
373
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb
365
374
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb
366
375
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/console_speaker.rb
367
376
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb
@@ -411,6 +420,7 @@ files:
411
420
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/hash.rb
412
421
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb
413
422
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb
423
+ - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb
414
424
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/arguments_consumer_spec.rb
415
425
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb
416
426
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb
@@ -467,10 +477,10 @@ files:
467
477
  - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb
468
478
  - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos.rb
469
479
  - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb
470
- - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb
471
- - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb
480
+ - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb
472
481
  - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/quality.rb
473
482
  - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/resolution.rb
483
+ - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb
474
484
  - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb
475
485
  - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb
476
486
  - vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
- require 'optparse'
5
-
6
- module EacCli
7
- class Parser
8
- class OptionsCollection
9
- enable_simple_cache
10
- common_constructor(:definition, :argv, :collector) { collect }
11
- attr_reader :arguments
12
-
13
- def options_first?
14
- definition.options_first? || definition.subcommands?
15
- end
16
-
17
- private
18
-
19
- def check_required_options
20
- definition.options.each do |option|
21
- next unless option.required?
22
- next if collector.supplied?(option)
23
-
24
- raise ::EacCli::Parser::Error.new(
25
- definition, argv, "Option \"#{option}\" is required and a value was not supplied"
26
- )
27
- end
28
- end
29
-
30
- def collect
31
- build_banner
32
- build_options
33
- parse_argv
34
- check_required_options
35
- end
36
-
37
- def option_parser_uncached
38
- ::OptionParser.new
39
- end
40
-
41
- def parse_argv
42
- @arguments = options_first? ? option_parser.order(argv) : option_parser.parse(argv)
43
- rescue ::OptionParser::InvalidOption => e
44
- raise ::EacCli::Parser::Error.new(definition, argv, e.message)
45
- end
46
-
47
- def build_banner
48
- option_parser.banner = definition.help_formatter.to_banner
49
- end
50
-
51
- def build_options
52
- definition.options.each do |option|
53
- build_option(option)
54
- end
55
- end
56
-
57
- def build_option(option)
58
- option_parser.on(
59
- *[::EacCli::Definition::HelpFormatter.option_short(option),
60
- ::EacCli::Definition::HelpFormatter.option_long(option),
61
- option.description].reject(&:blank?)
62
- ) do |value|
63
- collector.collect(option, value)
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_cli/parser/error'
4
- require 'eac_ruby_utils/core_ext'
5
-
6
- module EacCli
7
- class Parser
8
- class ParseResult
9
- common_constructor :definition, :argv
10
-
11
- def result
12
- result_or_error = parse(definition)
13
- return result_or_error unless result_or_error.is_a?(::Exception)
14
-
15
- definition.alternatives.each do |alternative|
16
- alt_result_or_error = parse(alternative)
17
- return alt_result_or_error unless alt_result_or_error.is_a?(::Exception)
18
- end
19
-
20
- raise result_or_error
21
- end
22
-
23
- private
24
-
25
- def parse(definition)
26
- ::EacCli::Parser::Collector.to_data(definition) do |collector|
27
- ::EacCli::Parser::PositionalCollection.new(
28
- definition,
29
- ::EacCli::Parser::OptionsCollection.new(definition, argv, collector).arguments,
30
- collector
31
- )
32
- end
33
- rescue ::EacCli::Parser::Error => e
34
- e
35
- end
36
- end
37
- end
38
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
- require 'eac_cli/parser/error'
5
-
6
- module EacCli
7
- class Parser
8
- class PositionalCollection
9
- common_constructor(:definition, :argv, :collector) { collect }
10
-
11
- private
12
-
13
- def argv_enum
14
- @argv_enum ||= argv.each
15
- end
16
-
17
- def argv_pending?
18
- argv_enum.ongoing?
19
- end
20
-
21
- def argv_pending_check
22
- return unless argv_pending?
23
- return unless positional_enum.stopped?
24
-
25
- raise ::EacCli::Parser::Error.new(
26
- definition, argv, "No positional left for argv \"#{argv_enum.current}\""
27
- )
28
- end
29
-
30
- def collected
31
- @collected ||= ::Set.new
32
- end
33
-
34
- def collect
35
- loop do
36
- break unless enums('pending?').any?
37
-
38
- enums('pending_check')
39
- collect_argv_value
40
- end
41
- end
42
-
43
- def collect_argv_value
44
- collector.collect(*enums('enum', &:peek))
45
- collected << positional_enum.peek
46
- positional_enum.next unless positional_enum.peek.repeat?
47
- argv_enum.next
48
- end
49
-
50
- def enums(method_suffix, &block)
51
- %w[positional argv].map do |method_prefix|
52
- v = send("#{method_prefix}_#{method_suffix}")
53
- block ? block.call(v) : v
54
- end
55
- end
56
-
57
- def positional_enum
58
- @positional_enum ||= definition.positional.each
59
- end
60
-
61
- def positional_pending?
62
- !(positional_enum.stopped? || positional_enum.current.optional? ||
63
- collected.include?(positional_enum.current))
64
- end
65
-
66
- def positional_pending_check
67
- return unless positional_pending?
68
- return unless argv_enum.stopped?
69
-
70
- raise ::EacCli::Parser::Error.new(
71
- definition, argv, 'No value for required positional ' \
72
- "\"#{positional_enum.current.identifier}\""
73
- )
74
- end
75
- end
76
- end
77
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
- require 'eac_ruby_utils/core_ext'
5
- require 'ehbrs_ruby_utils/executables'
6
- require 'ehbrs_ruby_utils/videos/container/info'
7
-
8
- module EhbrsRubyUtils
9
- module Videos
10
- module Container
11
- class File
12
- enable_simple_cache
13
- common_constructor :path do
14
- self.path = path.to_pathname
15
- end
16
-
17
- private
18
-
19
- def info_uncached
20
- ::EhbrsRubyUtils::Videos::Container::Info.new(
21
- ::JSON.parse(
22
- ::EhbrsRubyUtils::Executables.ffprobe.command(
23
- '-hide_banner', '-print_format', 'json', '-show_format', '-show_streams', path
24
- ).execute!
25
- )
26
- )
27
- end
28
- end
29
- end
30
- end
31
- end