Class: Gifboard

Inherits:
Storyboard show all
Defined in:
lib/gifboard.rb

Constant Summary

Constants inherited from Storyboard

Storyboard::VERSION

Instance Attribute Summary collapse

Attributes inherited from Storyboard

#encoding, #needs_KFhimaji

Instance Method Summary collapse

Methods inherited from Storyboard

#check_video, #cleanup, #consolidate_frames, current_encoding, current_encoding=, encode_regexp, encode_string, #extract_frames, ffprobe_installed?, #get_subtitles, magick_installed?, #mkv?, mkvtools_installed?, mp4box_insatlled?, needs_KFhimaji, path, #render_output, #run_scene_detection, #setup, #video_file?

Constructor Details

#initialize(o) ⇒ Gifboard

Returns a new instance of Gifboard.



24
25
26
# File 'lib/gifboard.rb', line 24

def initialize(o)
  super
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



22
23
24
# File 'lib/gifboard.rb', line 22

def cache
  @cache
end

#capture_pointsObject

Returns the value of attribute capture_points.



21
22
23
# File 'lib/gifboard.rb', line 21

def capture_points
  @capture_points
end

#lengthObject

Returns the value of attribute length.



22
23
24
# File 'lib/gifboard.rb', line 22

def length
  @length
end

#mimeObject

Returns the value of attribute mime.



22
23
24
# File 'lib/gifboard.rb', line 22

def mime
  @mime
end

#optionsObject

Returns the value of attribute options.



21
22
23
# File 'lib/gifboard.rb', line 21

def options
  @options
end

#renderersObject

Returns the value of attribute renderers.



22
23
24
# File 'lib/gifboard.rb', line 22

def renderers
  @renderers
end

#subtitlesObject

Returns the value of attribute subtitles.



21
22
23
# File 'lib/gifboard.rb', line 21

def subtitles
  @subtitles
end

#timingsObject

Returns the value of attribute timings.



21
22
23
# File 'lib/gifboard.rb', line 21

def timings
  @timings
end

Instance Method Details

#choose_textObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/gifboard.rb', line 69

def choose_text
  matches = []
  @subtitles.pages.each {|x|
    found = !x.lines.select {|l|
      l.downcase.match(options[:text].downcase)
    }.empty?
    matches << x if found
  }

  match = nil
  if matches.count == 0
    raise "No matches found"
  elsif matches.count == 1
    puts "Just one match found. Using it."
    match = matches.first
  else
    puts "Multiple matches found.. pick one!"
    matches.each_with_index {|m,i|
      print "#{i+1}:\t"
      m.lines.each_with_index{|l,j|
        print "\t" if j > 0
        puts l
      }
    }
    while !match
      print "choice (default 1): "
      input = gets.chomp
      number = input.empty? ? 1 : input.to_i
      if number > matches.count || number < 1
        puts "Try again. Choose a subtitle between 1 and #{matches.count}"
      else
        match = matches[number-1]
      end
    end
  end
  match
end

#runObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gifboard.rb', line 28

def run
  LOG.info("Processing #{options[:file]}")
  setup

  @cache = Cache.new(Suby::MovieHasher.compute_hash(Path.new(options[:file])))

  LOG.debug(options) if options[:verbose]

  @subtitles = SRT.new(options[:subs] ? File.read(options[:subs]) : get_subtitles, options)
  # bit of a temp hack so I don't have to wait all the time.
  @subtitles.save if options[:verbose]

  @cache.save

  if @options[:text]
    @renderers << Storyboard::GifRenderer.new(self)

    selected = choose_text
    @capture_points << selected.start_time
    (0.1).step(selected.end_time.value - selected.start_time.value, 0.1) {|i|
      @capture_points << selected.start_time + i
    }
    # @capture_points << selected.end_time not sure if it's better or worse to leave this yet

    @stop_frame = @capture_points.count
    extract_frames

    render_output
  else
    @subtitles.pages.each {|x|
      print "[#{x.start_time.to_srt}]\t"
      x.lines.each_with_index{|l,i|
        print "\t\t" if i > 0
        puts l
      }
    }
    puts "\n\nYou need to specify what text to look for with the -t option. Listing all subtitles instead."
    puts "ex: gifboard -t 'a funny joke ha. ha' video.mkv"
  end
end