Last active
February 19, 2018 02:30
-
-
Save petrsnd/b690bad92e97c6b0b1f8aab64675f417 to your computer and use it in GitHub Desktop.
Download all LDS Bible Videos chronologically
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 | |
# petrsnd | |
# Download all LDS Bible Videos chronologically | |
# Be sure to select your desired resolution by changing the variable below: | |
RES="1080p" | |
#RES="720p" | |
# As of 2017-05-08 this script was able to download all of the Bible Videos from the | |
# LDS media library. There are a few pages that for whatever reason don't follow the | |
# same format. These downloads will fail and whil be listed in errors.txt in the | |
# output directory. | |
OUT_DIR="$HOME/bible-videos-$RES/" | |
INDEX_URL="https://www.lds.org/bible-videos/videos?lang=eng&sort=chronological" | |
i=1 | |
if [ -z "`which pup`" ]; then | |
2<&1 echo "pup is not in your PATH!" | |
2<&1 echo "You need to install pup for command line parsing of HTML." | |
2<&1 echo "OPTIONS:" | |
2<&1 echo " go -> go get github.com/ericchiang/pup" | |
2<&1 echo " macOs -> brew install pup" | |
2<&1 echo " linux -> https://github.com/ericchiang/pup" | |
exit 1 | |
fi | |
if [ ! -d "$OUT_DIR" ]; then | |
mkdir -p "$OUT_DIR" | |
fi | |
echo -e "\nDownloading Bible Videos in $RES resolution to $OUT_DIR..." | |
for video_url in $(curl -s $INDEX_URL | pup '#videos ul li a' | grep href | sed -e 's,<a href=\"\(.*\)\">,\1#d,'); do | |
echo "$video_url" | grep -q trailer | |
if [ $? -eq 0 ]; then | |
continue | |
fi | |
download_url=$(curl -s $video_url | pup '.video-options' | grep href | grep $RES | sed -e 's,<a href=\"\(.*true\)\" .*>,\1,' -e 's,\&,\&,g' | tr -d ' ') | |
temp=$(echo $download_url | sed -e "s,http://[a-zA-Z0-9\.]\+\(.*\)-$RES-eng.mp4.*,\1,") | |
name="$(printf "%03d" $i)$(echo ${temp##*/} | sed -e "s,[0-9-]\+\(.*\),-\1.mp4,")" | |
len=${#name} | |
echo -e "\nDownloading $name" | |
if [ $len -eq 3 ]; then | |
echo "Download failed: $name" >> $OUT_DIR/errors.txt | |
echo ">> $video_url" | tee -a $OUT_DIR/errors.txt | |
echo ">> $download_url" | tee -a $OUT_DIR/errors.txt | |
echo ">> $temp" | tee -a $OUT_DIR/errors.txt | |
else | |
curl -o "$OUT_DIR$name" $download_url | |
fi | |
i=$(($i + 1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nicely done! I've been mulling over how to do this same thing but with all of the general conference talks that are available :P