How do get the data stream link for any video of youtube?

Sridarshan picture Sridarshan · Dec 30, 2010 · Viewed 13.8k times · Source

I'm not sure if this is the right place to post this question,I googled a lot about this,but nothing turned up,. for a link of the form

http://www.youtube.com/watch?v=[video_id]

How do i get the link for the data stream?

Answer

cadejscroggins picture cadejscroggins · Nov 7, 2012

The following bash script will retrieve youtube streaming url's. I know this is outdated, but maybe this will help someone.

#!/bin/bash

[ -z "$1" ] && printf "usage: `basename $0` <youtube_url>\n" && exit 1

ID="$(echo "$1" | grep -o "v=[^\&]*" | sed 's|v=||')"
URL="$(curl -s "http://www.youtube.com/get_video_info?&video_id=$ID" | sed -e 's|%253A|:|g' -e 's|%252F|/|g' -e 's|%253F|?|g' -e 's|%253D|=|g' -e 's|%2525|%|g' -e 's|%2526|\&|g' -e 's|\%26|\&|g' -e 's|%3D|=|g' -e 's|type=video/[^/]*&sig|signature|g' | grep -o "http://o-o---preferred[^:]*signature=[^\&]*" | head -1)"

[ -z "$URL" ] && printf "Nothing was found...\n" && exit 2

echo "$URL"