-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrec
executable file
·61 lines (57 loc) · 2.03 KB
/
rec
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
#!/usr/bin/env bash
###########################################################################
# Made by : Ewoud Dronkert
# Licence : GNU GPL v3
# Platform : Raspberry Pi, Raspbian
# Requires : bash, streamripper, mpd, mpc
# Location : /usr/local/bin, ~/bin
# Name : rec
# Version : 1.0.0
# Date : 2017-01-01
# Purpose : Record audio streams playing with mpd ("radio recorder").
# How to use : Call script to start recording the currently playing stream.
# Call again to stop recording and get a list of files.
# Probably only works cleanly when called as user pi from
# homedir of user pi, because of check for existing nohup.out
# and .cue files. I guess I should fix that..
# Output : Status message on stdout, .mp3 file saved in /home/pi
###########################################################################
# Get homedir of user pi
DIR=$(cat /etc/passwd | grep -e '^pi:' | cut -d':' -f6)
# Check for streamripper executable, used to record audio stream
RIP=streamripper
EXE=$(which $RIP)
[ -z "$EXE" ] && echo "Install $RIP: sudo apt-get update && sudo apt-get install $RIP" && exit 1
# Check for mpc executable, used to get stream URL from mpd
EXE=$(which mpc)
[ -z "$EXE" ] && echo "Install mpc: sudo apt-get update && sudo apt-get install mpc" && exit 2
# Check if streamripper already running
PID=$(pgrep $RIP)
if [ -z "$PID" ]; then
# Not running. Check if mpd is playing
URL="$(mpc --format %file% | grep http)"
if [ -n "$URL" ]; then
# Record audio stream to .mp3 file
REC="$(date '+%Y%m%d%H%M%S').mp3"
nohup $RIP "$URL" -d "$DIR" -s -a "$REC" -A -T --quiet &
echo
echo " Now recording $URL ..."
echo
else
echo
echo " No stream found, not recording."
echo
fi
else
# Already recording, now stopping
killall $RIP
# Clean up output and .cue files
rm -f "$DIR/nohup.out" 2>/dev/null
rm -f "$DIR"/*.cue 2>/dev/null
# Overview
echo
echo " Recording stopped. Today's recordings:"
echo
ls -l "$DIR/$(date '+%Y%m%d')"*.mp3
echo
fi