Direct Download Flash Videos


paulguy

Member
Joined
Sep 30, 2008
Messages
414
Age
35
Location
Buffalo, NY
Website
paulguy.co.uk
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:
Miro is a nice "internet tv" program that supports downloading of flash videos from a few places in order to watch them locally... would be nice to see a PND of that... since I mentioned it, I think I will go request it now...
 
Just a quick note, as these forums are frequented by youngsters, I think the use of that specific URL as an example is bad taste...

At least add a warning :)
 
@ Custom Processing Unlimite

CreatureXL and I tried to compile miro, but it uses the flashplayer to play the videos in the program. Also it has some weird dependencys. Not worth the hassle just for videodownloading.
Better choice would be to add a videodownloadingscript to minitube. (and have a look at the buffercode btw.)
 
Back
Top