Prototype of thumbnail generation
This commit is contained in:
parent
bd85ecda47
commit
da3ec8aca1
29
app/workers/thumbnail_worker.rb
Normal file
29
app/workers/thumbnail_worker.rb
Normal file
@ -0,0 +1,29 @@
|
||||
require 'tempfile'
|
||||
|
||||
class ThumbnailWorker
|
||||
def self.perform(asciicast_id)
|
||||
asciicast = Asciicast.find(asciicast_id)
|
||||
|
||||
in_data_file = Tempfile.new('asciiio-data', :encoding => 'ascii-8bit')
|
||||
in_data_file.write(asciicast.stdout.read)
|
||||
in_data_file.close
|
||||
in_data_path = in_data_file.path
|
||||
|
||||
in_timing_file = Tempfile.new('asciiio-timing', :encoding => 'ascii-8bit')
|
||||
in_timing_file.write(asciicast.stdout_timing.read)
|
||||
in_timing_file.close
|
||||
in_timing_path = in_timing_file.path
|
||||
|
||||
out_data_path = in_data_path + '.ts'
|
||||
out_timing_path = in_timing_path + '.ts'
|
||||
|
||||
if system "bash -c './script/convert-to-typescript.sh #{in_data_path} #{in_timing_path} #{out_data_path} #{out_timing_path}'"
|
||||
delay = (asciicast.duration / 2).to_i
|
||||
command = "scriptreplay #{out_timing_path} #{out_data_path}; sleep 10"
|
||||
puts '-' * 80
|
||||
system "bash -c 'ASCIICAST_ID=#{asciicast_id} COLS=#{asciicast.terminal_columns} LINES=#{asciicast.terminal_lines} COMMAND=\"#{command}\" DELAY=#{delay} THUMB_LINES=10 THUMB_COLS=20 ./script/thumbnail.sh'"
|
||||
else
|
||||
puts "failed"
|
||||
end
|
||||
end
|
||||
end
|
12
script/convert-to-typescript.sh
Executable file
12
script/convert-to-typescript.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
in_data_file="$1"
|
||||
in_timing_file="$2"
|
||||
|
||||
out_data_file="$3"
|
||||
out_timing_file="$4"
|
||||
|
||||
echo '# Foo' >$out_data_file
|
||||
bzip2 -c -d $in_data_file >>$out_data_file
|
||||
|
||||
(echo 0.0; bzip2 -c -d $in_timing_file | awk '{ print $2; print $1 }' | head -n -1) | xargs -L 2 echo >$out_timing_file
|
@ -4,6 +4,8 @@
|
||||
# ASCIICAST_ID=666 COLS=80 LINES=20 COMMAND="df; df; df; sleep 10"
|
||||
# DELAY=1 THUMB_LINES=5 THUMB_COLS=10 ./tmux-save.sh
|
||||
|
||||
set -e
|
||||
|
||||
SESSION_NAME=asciiio-thumb-$ASCIICAST_ID
|
||||
|
||||
tmux new -s $SESSION_NAME -d -x $COLS -y $LINES "$COMMAND"
|
||||
|
Loading…
Reference in New Issue
Block a user