class EncoderTools::CLI::Subtitles::FixLengths
Constants
- DEFAULT_THRESHOLD
Public Instance Methods
run()
click to toggle source
# File lib/encoder-tools/cli/subtitles/fix_lengths.rb, line 7 def run begin if long_subtitles? && fix_subtitles? write fix_subtitles end return nil rescue Interrupt # just return on ^C end end
Private Instance Methods
fix_subtitle(subtitle)
click to toggle source
# File lib/encoder-tools/cli/subtitles/fix_lengths.rb, line 38 def fix_subtitle(subtitle) range = "%s (%s)" % [subtitle.range_string, subtitle.timestamp(subtitle.duration)] shell.say([range, subtitle.text, '', ''].join("\n")) subtitle.duration = BigDecimal(shell.ask("How long should it be?")) end
fix_subtitles()
click to toggle source
# File lib/encoder-tools/cli/subtitles/fix_lengths.rb, line 31 def fix_subtitles long_subtitles.each do |subtitle| fix_subtitle(subtitle) end return list end
fix_subtitles?()
click to toggle source
# File lib/encoder-tools/cli/subtitles/fix_lengths.rb, line 27 def fix_subtitles? shell.yes?("Found #{long_subtitles.size} long subtitles. Would you like to fix them?") end
list()
click to toggle source
# File lib/encoder-tools/cli/subtitles/fix_lengths.rb, line 50 def list @list ||= read end
long_subtitles()
click to toggle source
# File lib/encoder-tools/cli/subtitles/fix_lengths.rb, line 44 def long_subtitles @long_subtitles ||= list.entries.select do |subtitle| subtitle.duration > threshold end end
long_subtitles?()
click to toggle source
# File lib/encoder-tools/cli/subtitles/fix_lengths.rb, line 20 def long_subtitles? return true if long_subtitles.any? shell.say "No subtitles found over #{threshold}s" return false end
threshold()
click to toggle source
# File lib/encoder-tools/cli/subtitles/fix_lengths.rb, line 54 def threshold options[:threshold] || DEFAULT_THRESHOLD end