Skip to content

Instantly share code, notes, and snippets.

@leonardofaria
Created January 26, 2016 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonardofaria/bae42992c4c0c522bcbb to your computer and use it in GitHub Desktop.
Save leonardofaria/bae42992c4c0c522bcbb to your computer and use it in GitHub Desktop.
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