Last active
January 5, 2017 03:35
-
-
Save nobrowser/ad0a92a11ccc912c792806c8ead05707 to your computer and use it in GitHub Desktop.
A script to rip a web audio stream and save it to a file.
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/sh -Cefu | |
. /usr/local/bin/fortify.sh | |
. /usr/local/bin/mashlib.sh | |
MYLOGIN=$(id -un) | |
HOME=$(conc /home/ $MYLOGIN) | |
# defaults possibly overriden by config file | |
DESTDIR=$(conc $HOME /music/streams/croddur) | |
FORMAT=ogg | |
URL=http://some.stream.com:8000/stream.ogg | |
LOCALTZ=America/Los_Angeles | |
. $(conc $HOME /.savestream) || true | |
usage() | |
{ | |
echo 'usage: savestream START_DATE START_TIME END_DATE END_TIME' >&2 | |
echo ' savestream START_DATE START_TIME END_TIME' >&2 | |
echo ' savestream START_TIME END_TIME' >&2 | |
exit 2 | |
} | |
prtime() | |
{ | |
local date=$1 | |
local time=$2 | |
local format=$3 | |
date -d $(conc TZ= '"' $LOCALTZ '"' ' ' $date ' ' $time) +$format | |
} | |
case $# in | |
(4) | |
START_DATE=$1 ; START_TIME=$2 ; END_DATE=$3 ; END_TIME=$4 | |
;; | |
(3) | |
START_DATE=$1 ; START_TIME=$2 ; END_DATE=$START_DATE ; END_TIME=$3 | |
;; | |
(2) | |
START_DATE=$(prtime tomorrow 12:00 %Y-%m-%d) ; START_TIME=$1 ; END_DATE=$START_DATE ; END_TIME=$2 | |
;; | |
(*) | |
usage | |
;; | |
esac | |
START_TIMESTAMP=$(prtime $START_DATE $START_TIME %s) | |
END_TIMESTAMP=$(prtime $END_DATE $END_TIME %s) | |
LENGTH=$(( END_TIMESTAMP - START_TIMESTAMP )) | |
ATSPEC=$(prtime $START_DATE $START_TIME '%H%M %m/%d/%Y') | |
REALDIR=$(mktemp -d -p $DESTDIR $(conc $END_DATE .XXXXXXXXXXXX)) | |
printf 'REALDIR=%s\n' $REALDIR | |
DESTFILE=$(conc $REALDIR /savestream. $FORMAT) | |
LOG=$(conc $REALDIR /savestream.log) | |
LOGFMT='%FT%H:%M:%S' | |
printf '/usr/bin/timeout %s ffmpeg -i %s -codec: copy -loglevel warning %s 2>&1 | ts "%s" >%s\n' \ | |
$LENGTH $URL $DESTFILE $LOGFMT $LOG | at $ATSPEC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment