Commit 9fdfc6c3 authored by Julian Trischler's avatar Julian Trischler

Added boydl bash script in version 1.0

parent 892c9f39
#!/bin/bash
# Lysander Trischler <software@lyse.isobeef.org>
# Published under WTF PL
# configure your youtube-dl.py command here
YOUTUBE_DL_PY_COMMAND="youtube-dl -wo $HOME/Desktop/%(stitle)s-%(id)s.%(ext)s"
# the URL of the RSS feed to download and parse
RSS_URL='http://bestofyoutube.com/rss.php'
# the index file for successfully downloaded videos and error log
# index file contains HTML URLs from the RSS feed, error log has
# timestamp, HTML URL and video URL
INDEX_FILE="$(dirname $0)/boydl.index"
ERROR_FILE="$(dirname $0)/boydl.error"
# match strings for finding the video URL
VIDEO_URL_START_MATCHER='http://www.youtube.com/v/'
VIDEO_URL_END_MATCHER='&fs=1'
__PROGRAM__='boydl'
__VERSION__='1.0'
__RELEASE__='2011-07-17'
__AUTHOR__='Lysander Trischler <software@lyse.isobeef.org>'
__LICENSE__='WTF PL'
function version {
echo "$__PROGRAM__ Version $__VERSION__ ($__RELEASE__)"
}
function usage {
echo "Usage: $0 [ --html-urls | --version | --help ]"
}
function help {
version
echo
echo "Written by $__AUTHOR__."
echo "Published under terms of $__LICENSE__."
echo
usage
echo
echo "Options:"
echo " --html-urls Only print HTML URLs, do not download them."
echo " --version Display $__PROGRAM__ version and exit."
echo " --help Display this $__PROGRAM__ help and exit."
}
# command line option parsing
HTML_URLS=false
while [ $# -gt 0 ]
do
case $1 in
--html-urls) HTML_URLS=true;;
--version) version; exit;;
--help) help; exit;;
*) echo "$0: Error: Unknown option \`$1'!"
usage
exit 2
esac
shift
done
# the interesting work begins here
# download the RSS feed and parse the HTML page URLs
wget -qO - "$RSS_URL" | grep '<link>' | while read LINE
do
HTML_URL=${LINE/<link>/}
HTML_URL=${HTML_URL/<\/link>/}
# ignore global RSS description part
[ "$HTML_URL" == "http://bestofyoutube.com" ] && continue
# check if only HTML URLs are requested
$HTML_URLS && {
echo "$HTML_URL"
continue
}
# ignore already downloaded videos
[ -e "$INDEX_FILE" ] && grep -q "$HTML_URL" "$INDEX_FILE" && continue
# download HTML page to extract video URL
echo -n "Obtaining video URL for '$HTML_URL'... "
VIDEO_URL=$(wget -qO - "$HTML_URL" | grep "$VIDEO_URL_START_MATCHER" | grep "$VIDEO_URL_END_MATCHER") # NOTE: second grep unnecessary
VIDEO_URL=$(python -c "print '$VIDEO_URL'['$VIDEO_URL'.index('$VIDEO_URL_START_MATCHER'):'$VIDEO_URL'.index('$VIDEO_URL_END_MATCHER')]")
echo "$VIDEO_URL"
# download video using youtube-dl.py script and finally add it to
# downloaded videos list if downloading was sucessfull, to failed
# list otherwise
$YOUTUBE_DL_PY_COMMAND "$VIDEO_URL" \
&& echo "$HTML_URL" >> "$INDEX_FILE" \
|| echo "$(date "+%Y-%m-%d %H:%M:%S") - $HTML_URL - $VIDEO_URL" >> "$ERROR_FILE"
done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment