ehbrs_ruby_utils 0.3.0 → 0.4.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: 1a5f85d8072d8f656d982d29d5b4267615628ef993347630ed4a796ea3f8937d
4
+ data.tar.gz: d3c379fc4d4054cd628ed56a7a1ae8647cccf249de77333762d5f2010405561c
5
5
  SHA512:
6
- metadata.gz: 26d1cf45a73c8789e61566f18ff183cc15788865d347b57901e521baadc94a7919818b795d132d9a53fdb4efd3c2ab363171ffdf4477c2416f75ed7551fde906
7
- data.tar.gz: ea2f124e1923f2ef17b35e78b4b72a5ba6bef3715c9fca7ce547901f31fe8267d477cec229fcbc7cb8e293f88d64bfe393b177dd5d231fdccf66d39b82662505
6
+ metadata.gz: 88c6613b66181f404d6530f2d43161e6a6e10bf70da7a96d43867c487066b7e26c2dd44e710775468b06bc612a5c2357463a0e3529a23bc976cf95f636796262
7
+ data.tar.gz: f99bfc207698e18dcc708b0522ca249eee46288950fe16fd0e5fd554d3537b2c2a431954cc4f0456d08081f5512469fbe4a460dc18313480ded6fc874cb0350c
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -4,6 +4,7 @@ require 'json'
4
4
  require 'eac_ruby_utils/core_ext'
5
5
  require 'ehbrs_ruby_utils/executables'
6
6
  require 'ehbrs_ruby_utils/videos/container/info'
7
+ require 'ehbrs_ruby_utils/videos/stream'
7
8
 
8
9
  module EhbrsRubyUtils
9
10
  module Videos
@@ -14,6 +15,12 @@ module EhbrsRubyUtils
14
15
  self.path = path.to_pathname
15
16
  end
16
17
 
18
+ ::EhbrsRubyUtils::Videos::Stream.lists.codec_type.each_value do |stream_type|
19
+ define_method stream_type.to_s.pluralize do
20
+ streams.select { |stream| stream.codec_type == stream_type }
21
+ end
22
+ end
23
+
17
24
  private
18
25
 
19
26
  def info_uncached
@@ -25,6 +32,12 @@ module EhbrsRubyUtils
25
32
  )
26
33
  )
27
34
  end
35
+
36
+ def streams_uncached
37
+ info.ffprobe_data.fetch(:streams).map do |stream_ffprobe_data|
38
+ ::EhbrsRubyUtils::Videos::Stream.new(stream_ffprobe_data)
39
+ end
40
+ end
28
41
  end
29
42
  end
30
43
  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_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,45 @@
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, :other
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
+ def to_s
19
+ "#{index}|#{codec_type}|#{codec_name}|#{language}"
20
+ end
21
+
22
+ def to_h
23
+ ffprobe_data
24
+ end
25
+
26
+ %i[index codec_name codec_long_name].each do |method_name|
27
+ define_method method_name do
28
+ ffprobe_data.fetch(method_name)
29
+ end
30
+ end
31
+
32
+ def codec_type
33
+ ffprobe_data.fetch(:codec_type).to_sym
34
+ end
35
+
36
+ def tags
37
+ ffprobe_data.fetch(:tags).symbolize_keys
38
+ end
39
+
40
+ def language
41
+ tags[:language]
42
+ end
43
+ end
44
+ end
45
+ end
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.4.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: 2020-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -57,8 +57,10 @@ files:
57
57
  - lib/ehbrs_ruby_utils/videos/container.rb
58
58
  - lib/ehbrs_ruby_utils/videos/container/file.rb
59
59
  - lib/ehbrs_ruby_utils/videos/container/info.rb
60
+ - lib/ehbrs_ruby_utils/videos/convert_job.rb
60
61
  - lib/ehbrs_ruby_utils/videos/quality.rb
61
62
  - lib/ehbrs_ruby_utils/videos/resolution.rb
63
+ - lib/ehbrs_ruby_utils/videos/stream.rb
62
64
  - lib/ehbrs_ruby_utils/web_utils.rb
63
65
  - lib/ehbrs_ruby_utils/web_utils/instance.rb
64
66
  - lib/ehbrs_ruby_utils/web_utils/videos.rb