#!/bin/sh version='1.1' rick='https://f.freya.cat/rick' video="$rick/astley80.full.bz2" audio_gsm="$rick/roll.gsm" audio_raw="$rick/roll.s16" audpid=0 red='\x1b[38;5;9m' yell='\x1b[38;5;216m' green='\x1b[38;5;10m' purp='\x1b[38;5;171m' echo -en '\x1b[s' has() { hash $1 2>/dev/null; } cleanup() { (( audpid > 1 )) && kill $audpid 2>/dev/null; } quit() { echo -e "\x1b[2J \x1b[0H ${purp}<3 \x1b[?25h \x1b[u \x1b[m"; } trap "cleanup" INT trap "quit" EXIT obtainium() { if has curl; then curl -L -s "$1" elif has wget; then wget -q -O - "$1" else echo "Cannot has internets. :(" && exit fi } if ! has bunzip2; then echo "Cannot has decompression. :(" && exit fi echo -en "\x1b[?25l \x1b[2J \x1b[H" if has afplay; then # On Mac OS, if |afplay| available, pre-fetch compressed audio. [ -f /tmp/roll.s16 ] || obtainium "$audio_raw" >/tmp/roll.s16 afplay /tmp/roll.s16 & elif has aplay; then # On Linux, if |aplay| available, stream raw sound. obtainium "$audio_raw" | aplay -Dplug:default -q -f S16_LE -r 8000 & elif has play; then # On Cygwin, if |play| is available (via sox), pre-fetch compressed audio. obtainium "$audio_gsm" >/tmp/roll.gsm.wav play -q /tmp/roll.gsm.wav & fi audpid="$!" # Sync FPS to reality as best as possible. Mac's freebsd version of date cannot # has nanoseconds so inject python. :/ python <(cat < 0.0: time.sleep(repose) next_frame = elapsed / time_per_frame if frame >= next_frame: buf += line except KeyboardInterrupt: pass EOF ) < <(obtainium $video | bunzip2 -q 2> /dev/null)