Repository navigation
Expand file tree
/
Copy pathroll
More file actions
executable file
·149 lines (126 loc) · 3.78 KB
/
Copy pathroll
File metadata and controls
executable file
·149 lines (126 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
68
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/bash
# rickroll.sh: Rick Astley in your terminal.
# Copyright (C) 2024 Serene and Justine Tunney
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# 4yman-0's fork
version='0.2'
rick='https://raw.githubusercontent.com/4yman-0/rickroll.sh/main/rick'
video="$rick/roll.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'
# helper functions
has (){ command -v $1 &> /dev/null; }
cleanup (){ (( audpid > 1 )) && kill $audpid &>/dev/null; }
quit (){ echo -e "\x1b[?1049l ${purp}<3 \x1b[?25h \x1b[m"; }
usage (){
echo -en "\
${green}Rick Astley performs ♪ Never Gonna Give You Up ♪ on STDOUT. $purp[v$version]
${yell}Usage: ./roll [OPTIONS...]
${purp}OPTIONS: $yell
help -h --help - Show this message.
inject --inject - Append to $purp$USER$yell's bashrc. (Recommended :D)
"
}
inject (){
local NEVER_GONNA='curl -s -L https://bit.ly/10hA8iC | bash'
local MAKE_YOU_CRY="$HOME/.bashrc"
echo -en "$red[Inject] "
echo $NEVER_GONNA >> $MAKE_YOU_CRY
echo -e "${green}Appended to $MAKE_YOU_CRY."
echo -en "${yell}If you've Astley overdosed, "
echo -e "delete the line $purp\"$NEVER_GONNA\"$yell."
}
case "$@" in
help|-h|--help)
usage
exit;;
inject|--inject)
inject
exit;;
esac
# agnostic to curl or wget availability.
grab (){
if has curl; then curl -s $1 -o $2
elif has wget; then wget -q $1 -O $2
else echo "Cannot has internets. :("; exit
fi
}
# gimme https://example.org /tmp/example
gimme (){
[ -f $2 ] || grab $1 $2
}
get_video (){
# echo -e "${yell}Give me video"
gimme $video /tmp/roll.bz2
}
get_audio (){
# echo -e "${yell}Give me audio"
if has afplay || has aplay; then
gimme $audio_raw /tmp/roll.s16
elif has play; then
gimme $audio_gsm /tmp/roll.gsm.wav
fi
}
play_audio (){
if has afplay; then
# On Mac OS, if `afplay` available, play compressed audio.
afplay /tmp/roll.s16 &>/dev/null &
elif has aplay; then
# On Linux, if `aplay` available, stream raw sound.
aplay -q -f S16_LE -r 16000 /tmp/roll.s16 &>/dev/null &
elif has play; then
# On Cygwin, if `play` is available (via sox), play compressed audio.
play -q /tmp/roll.gsm.wav &>/dev/null &
fi
audpid=$!
}
play_video (){
echo -en "\x1b[?25l \x1b[?1049h \x1b[H" # Hide cursor, clear screen.
echo -e "${yell}Rick Astley!"
# Sync FPS to REALITY as best as possible. MacOS's FreeBSD version of `date` dosen't
# have nanoseconds so inject python
PY=python; has python3 && PY=python3
$PY <(cat <<EOF
import sys
import time
fps = 25; time_per_frame = 1.0 / fps
buf = ''; frame = 0; next_frame = 0
begin = time.time()
try:
for i, line in enumerate(sys.stdin):
if i % 30== 0:
frame += 1
sys.stdout.write(buf); buf = '\x1b[H'
elapsed = time.time() - begin
repose = (frame * time_per_frame) - elapsed
if repose > 0.0:
time.sleep(repose)
next_frame = elapsed / time_per_frame
if frame >= next_frame:
buf += line
except KeyboardInterrupt:
pass
EOF
) < <(bunzip2 /tmp/roll.bz2 -dc -q 2)
}
# Run quit/cleanup after getting INT/EXIT
trap 'cleanup' INT
trap 'quit' EXIT
get_video
get_audio
play_audio
play_video