From da3ec8aca100f6cfb796f94bafe4d1444e604056 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Tue, 3 Apr 2012 18:54:56 +0200 Subject: [PATCH] Prototype of thumbnail generation --- app/workers/thumbnail_worker.rb | 29 +++++++++++++++++++++++++++++ script/convert-to-typescript.sh | 12 ++++++++++++ script/thumbnail.sh | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 app/workers/thumbnail_worker.rb create mode 100755 script/convert-to-typescript.sh diff --git a/app/workers/thumbnail_worker.rb b/app/workers/thumbnail_worker.rb new file mode 100644 index 0000000..d5624ba --- /dev/null +++ b/app/workers/thumbnail_worker.rb @@ -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 diff --git a/script/convert-to-typescript.sh b/script/convert-to-typescript.sh new file mode 100755 index 0000000..b634314 --- /dev/null +++ b/script/convert-to-typescript.sh @@ -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 diff --git a/script/thumbnail.sh b/script/thumbnail.sh index 07e4589..e9207d0 100755 --- a/script/thumbnail.sh +++ b/script/thumbnail.sh @@ -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"