Class: Mts::Autojoin::Runner
- Inherits:
-
Object
- Object
- Mts::Autojoin::Runner
- Defined in:
- lib/mts/autojoin.rb
Constant Summary collapse
- TWO_GIGABYTES =
2040000000
- FOUR_GIGABYTES =
4172000000
Instance Attribute Summary collapse
-
#full_path ⇒ Object
Returns the value of attribute full_path.
-
#grouped_video_files ⇒ Object
Returns the value of attribute grouped_video_files.
-
#max_file_size ⇒ Object
readonly
Returns the value of attribute max_file_size.
-
#video_files ⇒ Object
Returns the value of attribute video_files.
Instance Method Summary collapse
- #check_folder ⇒ Object
- #check_video_files ⇒ Object
- #create_file_list_and_execute ⇒ Object
- #delete_metafiles ⇒ Object
- #execute_concat_command(file, number) ⇒ Object
- #group_video_files ⇒ Object
-
#initialize(path) ⇒ Runner
constructor
A new instance of Runner.
- #run! ⇒ Object
-
#set_max_file_size ⇒ Object
Update max_file_size to FOUR_GIGABYTES if there is at least one file equal or greather than 4 gigabytes.
Constructor Details
#initialize(path) ⇒ Runner
Returns a new instance of Runner.
14 15 16 17 18 19 |
# File 'lib/mts/autojoin.rb', line 14 def initialize(path) @full_path = File.(path || '/') @video_files = [] @max_file_size = TWO_GIGABYTES @grouped_video_files = Hash.new { |h,k| h[k] = [] } end |
Instance Attribute Details
#full_path ⇒ Object
Returns the value of attribute full_path.
11 12 13 |
# File 'lib/mts/autojoin.rb', line 11 def full_path @full_path end |
#grouped_video_files ⇒ Object
Returns the value of attribute grouped_video_files.
11 12 13 |
# File 'lib/mts/autojoin.rb', line 11 def grouped_video_files @grouped_video_files end |
#max_file_size ⇒ Object (readonly)
Returns the value of attribute max_file_size.
12 13 14 |
# File 'lib/mts/autojoin.rb', line 12 def max_file_size @max_file_size end |
#video_files ⇒ Object
Returns the value of attribute video_files.
11 12 13 |
# File 'lib/mts/autojoin.rb', line 11 def video_files @video_files end |
Instance Method Details
#check_folder ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/mts/autojoin.rb', line 21 def check_folder if File.directory?(full_path) puts "MTS files will be checked at '#{full_path}'" else abort 'You did not provide a valid folder' end end |
#check_video_files ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/mts/autojoin.rb', line 29 def check_video_files Dir.entries(full_path).sort.each do |file| next if (file == '.' || file == '..' || !['.mts','.MTS'].include?(File.extname(file))) @video_files << [file, File.size(File.(file, full_path))] end abort "No MTS files found at '#{full_path}'" if @video_files.empty? end |
#create_file_list_and_execute ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mts/autojoin.rb', line 62 def create_file_list_and_execute @grouped_video_files.each do |group_number, filenames| File.open("file-list-#{group_number}.meta","w") do |tmpfile| filenames.each do |filename| tmpfile.puts("file '" + File.(filename, full_path) + "'") end end execute_concat_command("file-list-#{group_number}.meta", group_number) end end |
#delete_metafiles ⇒ Object
77 78 79 |
# File 'lib/mts/autojoin.rb', line 77 def Dir.glob('*.meta').each { |f| File.delete(f) } end |
#execute_concat_command(file, number) ⇒ Object
73 74 75 |
# File 'lib/mts/autojoin.rb', line 73 def execute_concat_command(file, number) Kernel.system "ffmpeg -f concat -safe 0 -i #{file} -c copy video-output-#{number}.mts" end |
#group_video_files ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mts/autojoin.rb', line 48 def group_video_files current_filegroup = 1 @video_files.each do |file, size| @grouped_video_files[current_filegroup] += [file] if size < max_file_size current_filegroup += 1 end end @grouped_video_files end |
#run! ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/mts/autojoin.rb', line 81 def run! check_folder check_video_files set_max_file_size group_video_files create_file_list_and_execute end |
#set_max_file_size ⇒ Object
Update max_file_size to FOUR_GIGABYTES if there is at least one file equal or greather than 4 gigabytes
39 40 41 42 43 44 45 46 |
# File 'lib/mts/autojoin.rb', line 39 def set_max_file_size @video_files.each do |file, size| if size >= FOUR_GIGABYTES @max_file_size = FOUR_GIGABYTES break end end end |