Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
livestreamer mp3 grabber
#!/bin/bash
# paths
LIVESTREAMER="livestreamer"
FFMPEG="ffmpeg"
#####
if [ $# -lt 1 ]; then
echo -n "Usage: $0 input [output]"
exit 0
fi
if [[ -z `which $LIVESTREAMER` ]]; then
echo "livestreamer not found" 1>&2
exit 1;
fi
if [[ -z `which $FFMPEG` ]]; then
echo "ffmpeg not found" 1>&2
exit 1;
fi
#####
IN=$1
OUT="${@:2}"
if [[ -z $OUT ]]; then OUT="output"; fi
OUT="$OUT.mp3"
if [[ -n `which mktemp` ]]; then
TMPFILE=$(mktemp)
else
TMPFILE="$(md5sum <<< "$$.$RANDOM" | cut -b -16).tmp"
fi
if [[ -e $TMPFILE ]]; then
echo "could not create temp file" 1>&2
exit 1;
fi
$LIVESTREAMER $1 best -o $TMPFILE \
&& $FFMPEG -y -i $TMPFILE -c:a libmp3lame -b:a 320k -joint_stereo 0 "$OUT" \
&& echo "$OUT successfully written";
if [[ -f $TMPFILE ]]; then
rm $TMPFILE;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment