video_conv 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9b891e178fef0b5388c833ff94110de42c2d0d2b675fcab2b2663a8ce2fc0e7
4
- data.tar.gz: aa6fd49d11cd6388eb92f085c5d9572d2fa89d2e4250d1362ab9515a888148c1
3
+ metadata.gz: 42af0e74253ab7f2408f5f100c029426c6d41d83fa1698dd2c65403e4486d9e8
4
+ data.tar.gz: 064f07c6d31f2fec3072e090a71414a50e98ebf883ad722380fe139364fc94e9
5
5
  SHA512:
6
- metadata.gz: 55bcfcb8ac12796160ede721ceb5c7f799d291ebbbefc2925c402c4f35aa968c9b56cff53875e05eb1b43b67493d4f463e021481933132fa62b6640501a97720
7
- data.tar.gz: 4465076aa69de6197b228931dcc8ad92021d7fe93a1eceda44c6884705507fca7848eba16e1980bf86b8ab9def33ccf8c78f9fbe6594d39d41859443f44aa8f6
6
+ metadata.gz: 36f32db10f200fb19fc778aa0ec678476b66544953ba38754e66489e7902a5b9b25a6dbef39ed50d96ba1712bf34311b6e79ff118709fda8babd9ef508cbc382
7
+ data.tar.gz: c9ed466220efa9f6090f2d8b97cd65f4d23812a7bd8a64ed4ebe5ac5d63656a32bc3a61d22d75bb782d655aea8faddd4d04f4faf35cc126454a8d37175091937
@@ -1,4 +1,4 @@
1
1
  module VideoConverter
2
- VERSION = '0.2.3'.freeze
3
- end
2
+ VERSION = '0.2.4'.freeze
3
+ end
4
4
 
@@ -1,6 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'streamio-ffmpeg'
3
- require 'thread'
3
+ require 'concurrent'
4
4
 
5
5
  module VideoConverter
6
6
  class Converter
@@ -18,48 +18,48 @@ module VideoConverter
18
18
  end
19
19
 
20
20
  def rename_and_convert_files(dir, source_ext, target_ext)
21
+ convert_files_in_batch(get_source_files_recursive(dir, source_ext), source_ext, target_ext)
22
+ end
23
+
24
+ def get_source_files_recursive(dir, source_ext)
21
25
  source_files = []
22
26
  Dir.foreach(dir) do |file|
23
27
  next if file == '.' || file == '..'
24
28
 
25
29
  current_path = File.join(dir, file)
26
30
  if File.directory?(current_path)
27
- rename_and_convert_files(current_path, source_ext, target_ext) # Recursively call for subdirectories
28
- else
29
- if file.end_with?(source_ext)
30
- source_files << current_path
31
- end
31
+ source_files.concat(get_source_files_recursive(current_path, source_ext)) # Recursively call for subdirectories
32
+ elsif file.end_with?(source_ext)
33
+ source_files << current_path
32
34
  end
33
35
  end
34
36
 
35
- source_files.each_slice(batch_size) do |file_batch|
36
- convert_files_in_batch(file_batch, source_ext, target_ext)
37
- sleep(conversion_delay)
38
- end
37
+ source_files
39
38
  end
40
39
 
41
40
  def convert_files_in_batch(files, source_ext, target_ext)
42
- threads = []
43
- queue = Queue.new
44
-
45
- files.each { |file| queue << file }
41
+ executor = Concurrent::ThreadPoolExecutor.new(
42
+ min_threads: 1,
43
+ max_threads: max_concurrency,
44
+ max_queue: files.size,
45
+ fallback_policy: :caller_runs
46
+ )
46
47
 
47
- [max_concurrency, files.size].min.times do
48
- threads << Thread.new do
49
- while (file = queue.pop(true) rescue nil)
50
- new_filename = file.gsub(source_ext, target_ext)
51
- if !File.exist?(new_filename)
52
- convert_file(file, new_filename)
53
- puts "Converted: #{file} -> #{new_filename}"
54
- FileUtils.rm(file) # Remove the original file after conversion
55
- else
56
- puts "Skipped conversion (already exists): #{file}"
57
- end
48
+ files.each do |file|
49
+ executor.post do
50
+ new_filename = file.gsub(source_ext, target_ext)
51
+ if !File.exist?(new_filename)
52
+ convert_file(file, new_filename)
53
+ puts "Converted: #{file} -> #{new_filename}"
54
+ FileUtils.rm(file) # Remove the original file after conversion
55
+ else
56
+ puts "Skipped conversion (already exists): #{file}"
58
57
  end
59
58
  end
60
59
  end
61
60
 
62
- threads.each(&:join)
61
+ executor.shutdown
62
+ executor.wait_for_termination
63
63
  end
64
64
 
65
65
  def convert_single_file(source_file, target_file = nil, target_format = nil)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: video_conv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Webster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-23 00:00:00.000000000 Z
11
+ date: 2023-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: streamio-ffmpeg
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: concurrent-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement