Class: Thwomp::Renderers::SWF

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/thwomp/renderers/swf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#frame_number, #sort

Constructor Details

#initialize(url, options = {}) ⇒ SWF

Returns a new instance of SWF.



14
15
16
17
18
19
# File 'lib/thwomp/renderers/swf.rb', line 14

def initialize(url, options={})
  @filename = Downloader.new(url).filename
  @frame_count = options.fetch(:frame_count) { 10 }
  @width = options.fetch(:width) { 500 }
  @height = options.fetch(:height) { 500 }
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



12
13
14
# File 'lib/thwomp/renderers/swf.rb', line 12

def filename
  @filename
end

#frame_countObject (readonly)

Returns the value of attribute frame_count.



12
13
14
# File 'lib/thwomp/renderers/swf.rb', line 12

def frame_count
  @frame_count
end

#heightObject (readonly)

Returns the value of attribute height.



12
13
14
# File 'lib/thwomp/renderers/swf.rb', line 12

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



12
13
14
# File 'lib/thwomp/renderers/swf.rb', line 12

def width
  @width
end

Instance Method Details

#executableObject



56
57
58
# File 'lib/thwomp/renderers/swf.rb', line 56

def executable
  Thwomp.gnash_path || "gnash-dump"
end

#frame(number) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/thwomp/renderers/swf.rb', line 34

def frame(number)
  timestamp = Time.now.to_i

  Command.exec(
    "#{executable} -s1 --screenshot=#{number}" \
    " --screenshot-file=#{output_file(timestamp)}" \
    " -1 -r1 --timeout 200 #{filename} -j #{width}" \
    " -k #{height} > /dev/null 2>&1"
  )

  "#{Dir.tmpdir}/frame_#{timestamp}_#{number}.png"
end

#frame_batchObject



47
48
49
50
# File 'lib/thwomp/renderers/swf.rb', line 47

def frame_batch
  batch = ['last'] + (0..frame_count).to_a.reverse
  batch.join(',')
end

#framesObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/thwomp/renderers/swf.rb', line 21

def frames
  timestamp = Time.now.to_i

  Command.exec(
    "#{executable} -s1 --screenshot=#{frame_batch}" \
    " --screenshot-file=#{output_file(timestamp)}" \
    " -1 -r1 --timeout 200 #{filename} -j #{width}" \
    " -k #{height} > /dev/null 2>&1"
  )

  sort Dir.glob("#{Dir.tmpdir}/frame_#{timestamp}_*.png")
end

#output_file(timestamp) ⇒ Object



52
53
54
# File 'lib/thwomp/renderers/swf.rb', line 52

def output_file(timestamp)
  "#{Dir.tmpdir}/frame_#{timestamp}_%f.png"
end