ehbrs_ruby_utils 0.3.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8add7dac8ffbafbd80e94b7fe4646a995ba5d9c5d9333fabb6e7286b13be99c
4
- data.tar.gz: e354d52bd8717b180766dfb93204f599b2444c48aad6ff134f2de99d8b9f6288
3
+ metadata.gz: a2fd99658423c54235ee5e621107632c4ad9a0bc100a139511245865f491e4d3
4
+ data.tar.gz: 5bf38612a9edaec4c17250614de49e01abbd3daec0139f78a86c77233350b336
5
5
  SHA512:
6
- metadata.gz: 26d1cf45a73c8789e61566f18ff183cc15788865d347b57901e521baadc94a7919818b795d132d9a53fdb4efd3c2ab363171ffdf4477c2416f75ed7551fde906
7
- data.tar.gz: ea2f124e1923f2ef17b35e78b4b72a5ba6bef3715c9fca7ce547901f31fe8267d477cec229fcbc7cb8e293f88d64bfe393b177dd5d231fdccf66d39b82662505
6
+ metadata.gz: 952ba9525cf3e86b52ecfd4beee3446edde39415210a8e5b2fb673a147c9e069e6df75f2d1480fc978a4be889c9c7157949fdbca64e0d3fe347ff5a290128162
7
+ data.tar.gz: 98c3c31f33f94e0b3548ad37861e24885e073e2be6c9f91d14026464bc781208c6c10d1ef0ae81276d9ba2be3b63c03ee2c385d88ecba6092f16e636619cd5b7
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.3.0'
4
+ VERSION = '0.6.0'
5
5
  end
@@ -1,11 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/executables'
5
+ require 'ehbrs_ruby_utils/videos/stream'
6
+ require 'json'
4
7
 
5
8
  module EhbrsRubyUtils
6
9
  module Videos
7
- module Container
8
- require_sub __FILE__
10
+ class Container
11
+ enable_simple_cache
12
+ common_constructor :path do
13
+ self.path = path.to_pathname
14
+ end
15
+
16
+ ::EhbrsRubyUtils::Videos::Stream.lists.codec_type.each_value do |stream_type|
17
+ define_method stream_type.to_s.pluralize do
18
+ streams.select { |stream| stream.codec_type == stream_type }
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def probe_data_uncached
25
+ ::JSON.parse(
26
+ ::EhbrsRubyUtils::Executables.ffprobe.command(
27
+ '-hide_banner', '-print_format', 'json', '-show_format', '-show_streams', path
28
+ ).execute!
29
+ ).deep_symbolize_keys.freeze
30
+ end
31
+
32
+ def streams_uncached
33
+ probe_data.fetch(:streams).map do |stream_ffprobe_data|
34
+ ::EhbrsRubyUtils::Videos::Stream.new(stream_ffprobe_data)
35
+ end
36
+ end
9
37
  end
10
38
  end
11
39
  end
@@ -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_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,61 @@
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, :attachment
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].each do |method_name|
33
+ define_method method_name do
34
+ ffprobe_data.fetch(method_name)
35
+ end
36
+ end
37
+
38
+ %i[codec_name codec_long_name].each do |method_name|
39
+ define_method method_name do
40
+ ffprobe_data[method_name]
41
+ end
42
+ end
43
+
44
+ def codec_type
45
+ ffprobe_data.fetch(:codec_type).to_sym
46
+ end
47
+
48
+ def tags
49
+ ffprobe_data[:tags].if_present({}, &:symbolize_keys)
50
+ end
51
+
52
+ def language
53
+ tags[:language]
54
+ end
55
+
56
+ def title
57
+ tags[:title]
58
+ end
59
+ end
60
+ end
61
+ end
@@ -8,7 +8,7 @@ module EhbrsRubyUtils
8
8
  module WebUtils
9
9
  module Videos
10
10
  class FilesList
11
- enable_console_speaker
11
+ enable_speaker
12
12
  enable_simple_cache
13
13
 
14
14
  common_constructor :type_class, :root_path, :options do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehbrs_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-13 00:00:00.000000000 Z
11
+ date: 2021-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -16,34 +16,54 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.36'
19
+ version: '0.69'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.69.1
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: '0.36'
29
+ version: '0.69'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.69.1
27
33
  - !ruby/object:Gem::Dependency
28
- name: eac_ruby_gem_support
34
+ name: aranha-parsers
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '0.1'
39
+ version: '0.7'
34
40
  - - ">="
35
41
  - !ruby/object:Gem::Version
36
- version: 0.1.1
42
+ version: 0.7.2
37
43
  type: :development
38
44
  prerelease: false
39
45
  version_requirements: !ruby/object:Gem::Requirement
40
46
  requirements:
41
47
  - - "~>"
42
48
  - !ruby/object:Gem::Version
43
- version: '0.1'
49
+ version: '0.7'
44
50
  - - ">="
45
51
  - !ruby/object:Gem::Version
46
- version: 0.1.1
52
+ version: 0.7.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: eac_ruby_gem_support
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.2'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.2'
47
67
  description:
48
68
  email:
49
69
  executables: []
@@ -55,10 +75,10 @@ files:
55
75
  - lib/ehbrs_ruby_utils/version.rb
56
76
  - lib/ehbrs_ruby_utils/videos.rb
57
77
  - lib/ehbrs_ruby_utils/videos/container.rb
58
- - lib/ehbrs_ruby_utils/videos/container/file.rb
59
- - lib/ehbrs_ruby_utils/videos/container/info.rb
78
+ - lib/ehbrs_ruby_utils/videos/convert_job.rb
60
79
  - lib/ehbrs_ruby_utils/videos/quality.rb
61
80
  - lib/ehbrs_ruby_utils/videos/resolution.rb
81
+ - lib/ehbrs_ruby_utils/videos/stream.rb
62
82
  - lib/ehbrs_ruby_utils/web_utils.rb
63
83
  - lib/ehbrs_ruby_utils/web_utils/instance.rb
64
84
  - lib/ehbrs_ruby_utils/web_utils/videos.rb
@@ -82,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
102
  - !ruby/object:Gem::Version
83
103
  version: '0'
84
104
  requirements: []
85
- rubygems_version: 3.0.8
105
+ rubygems_version: 3.1.6
86
106
  signing_key:
87
107
  specification_version: 4
88
108
  summary: Utilities for EHB/RS's Ruby projects.
@@ -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
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
- require 'ehbrs_ruby_utils/videos/container/info'
5
-
6
- module EhbrsRubyUtils
7
- module Videos
8
- module Container
9
- class Info
10
- enable_simple_cache
11
- common_constructor :ffprobe_data do
12
- self.ffprobe_data = ffprobe_data.with_indifferent_access.freeze
13
- end
14
-
15
- def to_h
16
- ffprobe_data
17
- end
18
- end
19
- end
20
- end
21
- end