#!/bin/bash # Joe Gillotti - 3/26/2012 # Save *all* videos from red tube # Our user agent, so it doesn't look like we're curl agent="Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" # The first page to start at page="http://www.redtube.com/" # Go forever.. while :; do # Get all video id links on this page nums=`curl -s --user-agent "$agent" "$page" | egrep 'href="\/[0-9]+"' | grep -v class | sed 's/^[\t]*|//g' | cut -d\" -f2 | sed 's/\///'` # Go through all of them for i in $nums; do # URL to .mp4 file with the special session key at the end vid=`curl -s --user-agent "$agent" http://www.redtube.com/$i | grep videos.mp4.redtubefiles.com | grep -v param | cut -d\' -f2 | grep -v src` # Name of video name=`curl -s --user-agent "$agent" http://www.redtube.com/$i | grep '' | cut -d\> -f2 | cut -d\| -f 1` # Path to save it to fn=vids/`echo "$name" | sed 's/^[\t]*//g' | sed 's/[\t]*$//g' | sed 's/ /_/g'`.mp4 # Do we already have it? if [ -f "$fn" ]; then echo Skipping $fn # No; save it! else echo Saving... "$name" curl --stderr - -s --user-agent "$agent" --referer http://www.redtube.com/$i "$vid" -o "$fn" fi done # Get URL of next page so we can do all their pages! page=`curl -s --user-agent "$agent" "$page" | sed 's/<a/\n<a/g' | grep 'Next Page' | cut -d\" -f8` if [ -z "$page" ]; then echo Out of pages? exit 1 fi sleep 1 echo Next page is $page done