Created
March 30, 2016 03:55
-
-
Save tjluoma/b432bca708e7ab5984a2da7532029de0 to your computer and use it in GitHub Desktop.
If you act before April 14th, 2016, you should be able to download all 9 parts of the BBC's “I Am Legend”. Part 1 is here: http://www.bbc.co.uk/programmes/b007k0s3 and the subsequent parts are linked thereafter.
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/zsh -f | |
# Purpose: Download the BBC production of “I Am Legend” | |
# | |
# From: Timothy J. Luoma | |
# Mail: luomat at gmail dot com | |
# Date: 2016-03-24 | |
# Gist: https://gist.github.com/tjluoma/b432bca708e7ab5984a2da7532029de0 | |
## You can change this to whatever you want | |
## The directory will be created if it does not exist | |
DIR="$HOME/Desktop/BBC-I-Am-Legend" | |
# 1 http://www.bbc.co.uk/programmes/b007k0s3 (expires around 14 April 2016) | |
# 2 http://www.bbc.co.uk/programmes/b007k0tb (expires around 15 April 2016) | |
# 3 http://www.bbc.co.uk/programmes/b007k0wz (expires around 19 April 2016) | |
# 4 http://www.bbc.co.uk/programmes/b007k0y9 (expires around 20 April 2016) | |
# 5 http://www.bbc.co.uk/programmes/b00cfzw4 (expires around 21 April 2016) | |
# 6 http://www.bbc.co.uk/programmes/b007k10v (expires around 22 April 2016) | |
# 7 http://www.bbc.co.uk/programmes/b007k125 (expires around 23 April 2016) | |
# 8 http://www.bbc.co.uk/programmes/b007k14x (expires around 26 April 2016) | |
# 9 http://www.bbc.co.uk/programmes/b007k167 (expires around 27 April 2016) | |
NAME="$0:t:r" | |
if [ -e "$HOME/.path" ] | |
then | |
source "$HOME/.path" | |
else | |
PATH='/usr/local/scripts:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin' | |
fi | |
if ((! $+commands[youtube-dl] )) | |
then | |
# note: if youtube-dl is a function or alias, it will come back not found | |
echo "$NAME: youtube-dl is required but not found in $PATH" | |
if (( $+commands[brew] )) | |
then | |
echo "$NAME: You can install youtube-dl with 'brew install youtube-dl'" | |
echo " To use post-processing options (which are needed for this, use 'brew install ffmpeg' or 'brew install libav'." | |
fi | |
exit 1 | |
fi | |
if ((! $+commands[ffmpeg] )) | |
then | |
if ((! $+commands[libav] )) | |
then | |
# note: if libav is a function or alias, it will come back not found | |
echo "$NAME: either libav or ffmpeg is required but neither are found in $PATH" | |
exit 1 | |
fi | |
fi | |
## Make sure the directory we want to use actually exists | |
[[ ! -d "$DIR" ]] && mkdir -p "$DIR" | |
## If it still doesn't exist, give up | |
[[ ! -d "$DIR" ]] && echo "$NAME: Failed to create $DIR" && exit 2 | |
## go into that dir as PWD | |
cd "$DIR" | |
COUNT='0' | |
## for each of the 9 episodes, use the URL for that episode | |
for URL in \ | |
http://www.bbc.co.uk/programmes/b007k0s3 \ | |
http://www.bbc.co.uk/programmes/b007k0tb \ | |
http://www.bbc.co.uk/programmes/b007k0wz \ | |
http://www.bbc.co.uk/programmes/b007k0y9 \ | |
http://www.bbc.co.uk/programmes/b00cfzw4 \ | |
http://www.bbc.co.uk/programmes/b007k10v \ | |
http://www.bbc.co.uk/programmes/b007k125 \ | |
http://www.bbc.co.uk/programmes/b007k14x \ | |
http://www.bbc.co.uk/programmes/b007k167 | |
do | |
## Download the “video“ (FLV) and extract it into m4a audio | |
youtube-dl --keep-video --extract-audio --audio-format m4a "$URL" | |
## Did that work? If not, is it after the date(s) above? | |
EXIT="$?" | |
if [ "$EXIT" = "0" ] | |
then | |
echo "$NAME: Downloaded $URL" | tee -a downloaded.log | |
else | |
echo "$NAME: $URL failed (\$EXIT = $EXIT)"| tee -a downloaded.log | |
((COUNT++)) | |
fi | |
done | |
## Did we get any errors during our attempts? If so, report at end | |
if [[ "$COUNT" == "0" ]] | |
then | |
echo "$NAME: Finished with NO errors" | |
elif [ "$COUNT" -gt "0" ] | |
then | |
echo "$NAME: Finished with $COUNT errors" | |
else | |
echo "$NAME: Finished with ONE error" | |
fi | |
## show $DIR in finder | |
open -R "$DIR" | |
exit 0 | |
#EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment