Created
January 26, 2016 04:15
-
-
Save leonardofaria/bae42992c4c0c522bcbb to your computer and use it in GitHub Desktop.
livestreamer mp3 grabber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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