YouTube video url protocol

I was in search of a way to get good 'ole fashioned YouTube Video URLs into my experimental Flash/AIR video player because I don't always want to use YouTube's player in my Flash/AIR applications. But the method of fetching a YouTube video has changed over time, and it's not as easy as it used to be. Actually, it seems as though there are some who are stuck on this problem. So I went ahead and looked at the protocol that the YouTube flash player uses, and reverse-engineered the protocol. Here it is: First, the YouTube "embed" syntax for any YouTube video is:

http://www.youtube.com/watch?v=[id of the youtube video]

e.g., http://www.youtube.com/watch?v=DFNb1MNFhQg

The "v=DFNb1MNFhQg" is the part that we are interested in. The YouTube flash video player takes this id and sends a get_video_info message to YouTube. The message has the following syntax:

http://www.youtube.com/get_video_info?&video_id=DFNb1MNFhQg&eurl=http%3A%2F%2Feduviews%2Ecom%2Fportal%2Fnode%2F74

where video_id = DFNb1MNFhQg and
where eurl = http%3A%2F%2Feduviews%2Ecom%2Fportal%2Fnode%2F74

Obviously, the eurl parameter is the escaped page address of the page containing the YouTube player, and we should use some good manners by appending the proper referring url whenever we request a YouTube video.

Anyway, upon receiving a get_video_info request, the YouTube website responds to the request (if the video is indeed available) with something that looks like the following:

status=ok&title=TIMSS+1999+Math+-+Australia+Public+Release+Lesson+4&muted=0&avg_rating=0.0&creator=paulgrudnitski&length_seconds=85&fmt_map=&token=OEgsToPDskIHld_uhCmeK1KjI6Dp0PPG&thumbnail_url=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FDFNb1MNFhQg%2Fdefault.jpg&allow_ratings=False&track_embed=0

This response contains all kinds of useful/interesting metadata about the video, and I'll leave it up to you to dissect each parameter's meaning.

The part we are most interested in is the dynamically-generated "token=" part. In the above example, this is:

token=OEgsToPDskIHld_uhCmeK1KjI6Dp0PPG

I think this token is what gets people hung up because it must be included in subsequent requests to YouTube. In turn, the YouTube video player takes the Video ID, the Token, and the Referring URL, and sends a get_video message to YouTube. This looks like the following:

http://www.youtube.com/get_video?video_id=DFNb1MNFhQg&t=OEgsToPDskIVpT7H5xtpR1kfvoixGXpu&eurl=http%3A%2F%2Feduviews%2Ecom%2Fportal%2Fnode%2F74

YouTube will respond with a redirect to the actual video address. In this case, the response is:

http://chi-v152.chi.youtube.com/get_video?video_id=DFNb1MNFhQg&signature=3BB3288DBEE10F1EAE1C4D2846670B4B05963ABA.8F8F76B88706247FDF158C2EFAAF27AA744873F2&ip=24.24.255.17&ipbits=2&expire=1222652846&key=yt4&sver=2

All we need to do is feed the get_video request to any Flash Video Player's source property before the token expires and you've got a valid handle to the YouTube video with video id of DFNb1MNFhQg.

Here's the Flex Source for such a player, plus the php code you need on your server for the proxy.

Back to top