Skip to content

Commit

Permalink
human-media-time: Recurse into directories
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorgalvao committed May 21, 2024
1 parent 4804dd3 commit 1df883f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions human-media-time
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'open3'
require 'optparse'
require 'pathname'

# Options
ARGV.push('--help') if ARGV.empty?
Expand Down Expand Up @@ -29,17 +30,26 @@ OptionParser.new do |parser|
)
end.parse!(into: options)

input_files = ARGV.map { |arg|
init_path = Pathname.new(arg)

next nil unless init_path.exist?
next init_path if init_path.file?
next init_path.glob('**/*').select(&:file?) if init_path.directory?
next nil
}.flatten.compact

# Parse time values
total_time = {} # Each unit has the total value of everything
split_time = {} # Each unit has its corresponding value with the others discounted

seconds_total = ARGV.map { |file|
seconds_total = input_files.map { |file|
Open3.capture2(
'ffprobe',
'-loglevel', 'quiet',
'-output_format', 'csv=p=0',
'-show_entries', 'format=duration',
file
file.to_path
).first.to_f
}.reduce(0, :+)

Expand Down

0 comments on commit 1df883f

Please sign in to comment.