Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Last active May 2, 2017 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save yitsushi/6643609 to your computer and use it in GitHub Desktop.
Save yitsushi/6643609 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
# If DEBUG environment variable is not defined set as false
if [[ "x${DEBUG}" == "x" ]]
then
DEBUG=false
fi
# Logger function. Display a message if DEBUG is true
logMessage() {
if [[ $DEBUG == "true" ]]
then
echo $1
fi
}
# Configuration
FEED_URL="http://teamtreehouse.com/library/the-treehouse-show.rss?feed_token=********-****-****-****-***********"
DRIVE_MOUNT_POINT="/Volumes/Samsung"
TARGET_DIRECTORY="${DRIVE_MOUNT_POINT}/Plex/Series/Treehouse"
# Applications
CURL=`which curl`
# Check required applications
if [[ -z $CURL ]]
then
logMessage "cURL command line tool is not installed."
exit -1
fi
# Check external drive
# Remove this section if you do not need to check the mount point
if [[ -n `mount | grep "${DRIVE_MOUNT_POINT}"` ]]
then
logMessage "External drive is mounted."
else
logMessage "External drive is not mounted."
exit -1
fi
# If the target directory does not exist
if [[ ! -d $TARGET_DIRECTORY ]]
then
logMessage "Target directory does not exist. (${TARGET_DIRECTORY})"
logMessage "Create ${TARGET_DIRECTORY}"
# Create
mkdir -p $TARGET_DIRECTORY
fi
# Download the feed
logMessage "Download Feed..."
target_name=`basename $0`
curl -o /tmp/${target_name}.feed -s $FEED_URL
logMessage "Feed downloaded."
# Build an array of urls
logMessage "Parse video URIs."
videos=`grep -e "enclosure" /tmp/${target_name}.feed | grep -o 'http://[^"]\+' | sed -e 's/\.mp4.*/?hd=yes/g'`
for uri in $videos
do
# Fetch the direct link
target=`$CURL -s "${uri}" | grep -o 'http://[^"]\+'`
# Get the filename of the video
filename=`basename "$target" | sed -e "s/\?.*//"`
# If current video file exists then I got this episode
# and possible all others after that (feed order: publishedAt desc)
if [[ -f $TARGET_DIRECTORY"/"$filename ]]
then
logMessage "Done."
exit -1
fi
# Download the video to the target directory
logMessage "Download ${filename}..."
$CURL -s -o $TARGET_DIRECTORY"/"$filename "${target}"
logMessage "Downloaded."
done
@tewodroswondimu
Copy link

Keep getting "You do not have access to feeds of our content, please signup for a full Treehouse account". How do I get past authentication?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment