#!/bin/sh

# Downloads a video stream from Yle Areena to stdout using yle-dl
# script. The first parameter is the video page URL. Second parameter
# is the output file (optional).

YLEDL=yle-dl

which $YLEDL > /dev/null 2>&1
if [ $? != 0 ]; then
    echo "ERROR: $YLEDL is not on \$PATH" 1>&2
    echo "Install yle-dl from https://github.com/aajanki/yle-dl" 1>&2
    exit 1
fi

if [ "x$1" = "x" ]; then
    echo "Expected Areena URL as parameter" 1>&2
    exit 1
fi

OUTFILE="$2"
if [ "x$OUTFILE" = "x" ]; then
    OUTFILE=-
fi

$YLEDL $1 -q -o "$OUTFILE"

exit $?
