View Single Post
  #7   Report Post  
Posted to comp.os.linux.misc,comp.unix.questions,rec.arts.anime.misc,comp.lang.perl.misc,rec.audio.pro
Ansgar -59cobalt- Wiechers Ansgar -59cobalt- Wiechers is offline
external usenet poster
 
Posts: 1
Default google and youtube script ( auto resume auto filename )

In rec.arts.anime.misc wrote:
I see people asking for google and youtube video download scripts.
Here they are, with auto resume, auto filename. Great for downloading a
lot of videos.
youtube script is not entirely foolproof, since youtube servers are
flaky.
If you make improvement, please post.

Simply give a bunch of links as arguments.
USAGE:
youtube.sh 'http://www.youtube.com/watch?v=B4Ztn24AFrg'
'http://www.youtube.com/watch?v=mP91qkZFYqY'
google.sh
'http://video.google.com/videoplay?docid=-7837509539130010782'
'http://video.google.com/videoplay?docid=6855624764467039569'

#!/bin/bash -x
# youtube.sh
for arg in $@
do
rrr=`date +%s`
baseurl="http://youtube.com/get_video.php?"
wget $arg -O $rrr.urlsource.txt
fname=`grep 'title' $rrr.urlsource.txt | sed "s/.*YouTube...//" \
| sed "s/.*//"| sed "s/ /_/g" | sed "s/\//of/g" | sed "s/\~/_/g" \
| sed "s/(/_/g" | sed "s/)/_/g" | sed "s/__/_/g" `.flv
grep "player2.swf" $rrr.urlsource.txt $rrr.url.info
cut -d? -f2 $rrr.url.info $rrr.url
cut -d\" -f1 $rrr.url $rrr.videoid
videourl=`cat $rrr.videoid`
fullurl=${baseurl}${videourl}
curl -I -L ${fullurl} $rrr.txt
loc=`grep Location $rrr.txt | sed "s/Location: //"`
wget --read-timeout 3 -O $fname -t 0 -w 1 --waitretry=1 $loc
rm $rrr.urlsource.txt $rrr.url.info $rrr.url $rrr.videoid $rrr.txt
done


Ouch. This is wrong in so many ways that I can't even begin to describe
it.

----8----
#!/bin/bash
# youtube.sh

tmpfile="$(date +%s).urlsource.txt"
baseurl="http://youtube.com/get_video.php?"

CURLOPTS="-s -S"
max_retries=3

umask 077

for url in "$@"; do
curl ${CURLOPTS} -o "${tmpfile}" "${url}"
outputfile="$(awk '/title/ {
gsub(".*YouTube...|.*|", "", $0);
gsub("/", "of", $0);
gsub("[ ~()]", "_", $0);
gsub("__*", "_", $0);
print $0
}' "${tmpfile}").flv"
videoid="$(awk '/player2\.swf/ {gsub("^.*\\?|\\\".*$", "", $0); print $0}' "${tmpfile}")"
location="$(curl ${CURLOPTS} -I -L "${baseurl}${videoid}" | awk '/Location: / {sub("\r", "", $2); print $2}')"
curl ${CURLOPTS} --retry ${max_retries} -o "${outputfile}" "${location}"
done

rm -f "${tmpfile}"

exit 0
----8----

The other script is even worse.

F'up2colm

cu
59cobalt
--
"My surname is Li and my personal name is Kao, and there is a slight
flaw in my character."
--Li Kao (Barry Hughart: Bridge of Birds)