paulguy
Member
So I made this script that downloads videos from a certain site, for use on my desktop, and thought maybe it could be useful for people using a Pandora. It would also be interesting if other people could provide links or information on other such programs (I'd rather leave websites like keepvid out, since having a local script is much more convenient.), and maybe we could compile them on the wiki.
Code:
#!/bin/sh
VIDEO_PAGE_BASE="http://xtube.com/play_re.php?v=" #Video page base URL
FIND_VIDEO_URL="http://video2.xtube.com/find_video.php" #Find video script URL
VIDEO_SERVER_URL="http://cdns.xtube.com/s/e13" #Video file base URL
FIND_POST_PREFIX="video_id=" #String added to the POST request for the video URL
RESPONSE_PREFIX="&filename=" #String chopped off the server's response
OUTPUT_FILENAME="xt_video.flv" #Default output file name
#Use of sed later on requires this, I grabbed it off of stack overflow.
URL_ESCAPED=$(echo "$VIDEO_PAGE_BASE" | sed -e 's/(\.\|\/\|\*\|[\|]\|\\)/\\&/g')
if ! (wget --version 2>&1 >/dev/null); then
echo "This script requires wget."
exit
fi
if [ -z "$1" ]; then
echo "USAGE: ${0} ${VIDEO_PAGE_BASE}<video ID> [output file name]"
exit
fi
if [ -n "$2" ]; then
OUTPUT_FILENAME=${2}
fi
if ! $(echo "$1" | grep -q "^${VIDEO_PAGE_BASE}"); then
echo "This doesn't appear to be a valid URL."
exit
fi
#Chop the rest off, just leaving the ID.
VIDEO_ID=$(echo "$1" | sed -e "s/${URL_ESCAPED}//")
if [ -z "${VIDEO_ID}" ]; then
echo "This doesn't appear to be a valid URL."
exit
fi
echo "Video ID is ${VIDEO_ID}."
RESPONSE=$(wget -O - "--post-data=${FIND_POST_PREFIX}${VIDEO_ID}" "${FIND_VIDEO_URL}")
if ! $(echo "${RESPONSE}" | grep -q "^${RESPONSE_PREFIX}"); then
echo "Server didn't respond as expected, got ${RESPONSE}."
exit
fi
#Chop the beginning off and add it to the rest of the URL.
VIDEO_URL=${VIDEO_SERVER_URL}$(echo "${RESPONSE}" | sed -e "s/${RESPONSE_PREFIX}//")
echo "The URL to your video is: ${VIDEO_URL}"
read -p "Would you like it to be downloaded for you? It will be written to ${OUTPUT_FILENAME}. (y/n) >" -n 1 REPLY
echo
if [ $REPLY = "y" ] || [ $REPLY = "Y" ]; then
wget -O "${OUTPUT_FILENAME}" "${VIDEO_URL}"
fi
Last edited by a moderator: