Skip to content

Instantly share code, notes, and snippets.

@Deltachaos
Created March 11, 2012 19:09
Show Gist options
  • Save Deltachaos/2017704 to your computer and use it in GitHub Desktop.
Save Deltachaos/2017704 to your computer and use it in GitHub Desktop.
Mediathek download
#!/bin/sh
if [ ${#} -eq 0 ]; then
echo "Usage: ${0} URL [filename]"
exit
fi;
URL="${1}"
CONTENT=$(curl "${URL}")
MEDIAURLS=$(echo "${CONTENT}" | egrep '^[[:space:]]+mediaCollection\.addMediaStream\(0,[[:space:]]*2,[[:space:]]*' | sed -r 's/^[[:space:]]+mediaCollection\.addMediaStream\(0,[[:space:]]*2,[[:space:]]*"(.*)",[[:space:]]*"(.*)"\);/\1\n\2/')
MEDIAAPP=$(echo "${MEDIAURLS}" | head -n 1)
MEDIAPLAYPATH=$(echo "${MEDIAURLS}" | tail -n 1)
MEDIAURL="${MEDIAAPP}${MEDIAPLAYPATH}"
MAINTITLE=$(echo "${CONTENT}" | egrep '^[[:space:]]+<h1 class="boxTopHeadline">' | sed -r 's/^[[:space:]]+<h1 class="boxTopHeadline">(.*)<\/h1>/\1/' | w3m -T text/html -dump)
SUBTITLE=$(echo "${CONTENT}" | egrep '^[[:space:]]+<span class="boxHeadline">' | sed -r 's/^[[:space:]]+<span class="boxHeadline">(.*)<\/span>/\1/' | w3m -T text/html -dump)
ISLIVE=$(echo "${MEDIAPLAYPATH}" | egrep '^ard_fl_live')
FILENAME="${2}"
if [ -z "${FILENAME}" ]; then
FILENAME="${SUBTITLE}, ${MAINTITLE}.mp4"
fi;
echo "##################################"
echo " Store download to: ${FILENAME}"
echo "##################################"
EXIT=1
while [ "${EXIT}" -gt 0 -a "${EXIT}" -ne 2 ]; do
if [ "${ISLIVE}" ]; then
rtmpdump --live -r "${MEDIAURL}" -y "${MEDIAPLAYPATH}" -o "${FILENAME}"
else
rtmpdump --resume -r "${MEDIAURL}" -y "${MEDIAPLAYPATH}" -o "${FILENAME}"
fi;
EXIT=${?}
echo "Exitcode: ${EXIT}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment