-
Notifications
You must be signed in to change notification settings - Fork 3
/
relax.sh
123 lines (93 loc) · 2.43 KB
/
relax.sh
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
#!/bin/bash
# Script que ejecuta música de fondo, utilizando mplayer.
# Para descargar la música es requerido:
# * youtube-dl
# * wget
# Parámetros
# download:
# Descarga la música y la aloja en ~/Music/
# pause:
# Si no se esta ejecutando: lo ejecuta
# Si se ejecuta lo pausa
# Si esta pausado lo reanuda
# stop:
# Para la ejecución
# start:
# Inicia la música
PIPE_JAZZ="/tmp/relax_jazz"
PIPE_FIRE="/tmp/relax_fireplace"
PIPE_RAIN="/tmp/relax_rain"
MUSIC_HOME=~/Music
function is_running () {
if [ -p "$PIPE_JAZZ" ]; then
return 0
fi
return 1
}
function create_pipe () {
if [ ! -p "$1" ]; then
echo "Creating pipe"
rm -f "$1"
mkfifo "$1"
else
echo "Pipe already created $1"
fi
}
function to_pipe() {
echo "Broadcasting $1"
echo "$1" > "$PIPE_JAZZ"
echo "$1" > "$PIPE_FIRE"
echo "$1" > "$PIPE_RAIN"
}
function start() {
if is_running; then
echo "Already running, starting anyway"
fi
create_pipe "$PIPE_JAZZ"
create_pipe "$PIPE_FIRE"
create_pipe "$PIPE_RAIN"
mplayer "$MUSIC_HOME/jazz.mp3" -slave -input file="$PIPE_JAZZ" -loop 0 -volume 50 < /dev/null >/dev/null 2>&1 &
mplayer "$MUSIC_HOME/fireplace.mp3" -slave -input file="$PIPE_FIRE" -loop 0 < /dev/null >/dev/null 2>&1 &
mplayer "$MUSIC_HOME/rain.m4a" -slave -input file="$PIPE_RAIN" -loop 0 < /dev/null >/dev/null 2>&1 &
}
function stop() {
rm "$PIPE_JAZZ"
rm "$PIPE_FIRE"
rm "$PIPE_RAIN"
if [ ! is_running ]; then
echo "Not running"
else
to_pipe "quit"
fi
}
function pause() {
if is_running; then
to_pipe "pause"
else
start
fi
}
function usage() {
echo "Usage sh relax.sh start|stop|pause"
}
function download() {
echo "Downloading rain"
wget -O "$MUSIC_HOME/rain.m4a" "http://174.36.223.28/audio1110/0.m4a"
echo "Downloading fireplace"
youtube-dl --audio-quality 0 -x --audio-format mp3 "https://www.youtube.com/watch?v=DIx3aMRDUL4" -o "$MUSIC_HOME/fireplace.mp3"
echo "Downloading jazz"
youtube-dl --audio-quality 0 -x --audio-format mp3 "https://www.youtube.com/watch?v=HMnrl0tmd3k" -o "$MUSIC_HOME/jazz.mp3"
echo "Download complete, run sh relax.sh start"
}
case "$1" in
"start")
start;;
"stop")
stop;;
"pause")
pause;;
"download")
download;;
*)
usage;;
esac