Constructing YouTube FLV URL on client-side without any server-side script

It seems, there is a easier way of constructing YouTube! FLV URL on client-side without using any server-side script.

We need get the YouTube video_id from any of following places:-

Then, construct a URL like this:

Above URL is used in YouTube embed-code. It is basically a server-side redirection that points to YouTube Player (.swf). Above redirects (server-side) to following URL:-

As you can see in above URL, it contains “t” param (in red), which is what we need along with video_id to construct YouTube video (FLV) URL, YouTube FLV URL would look like this:-

You can check out code below to figure out things your own. You can also check out the example-app.

Flex 2.0/ActionScript 3.0 example:-

<mx:Application xmlns:mx=""
creationComplete="onAppCreationComplete ()"
import flash.display.*;
private var loader:Loader;
private var abortId:uint;
private function onAppCreationComplete ():void
loader = new Loader ();
private function startLoading ():void
var req:URLRequest = new URLRequest ("");
loader.contentLoaderInfo.addEventListener(Event.INIT, handlerLoaderInit);
logMessage ("Loading YouTube URL..");
private function handlerLoaderInit (event:Event):void
logMessage ("Loaded, processing: " + loader.contentLoaderInfo.url);
var urlVars:URLVariables = new URLVariables ();
urlVars.decode (loader.contentLoaderInfo.url.split("?")[1]);
logMessage ("Processed:-");
logMessage ("\t\t video_id:" + urlVars.video_id);
logMessage ("\t\t t param:" + urlVars.t);
logMessage ("\t\t thumbnail-url:" + urlVars.iurl);
var flvURL:String = constructFLVURL (urlVars.video_id, urlVars.t);
logMessage ("YouTube FLV URL: " + flvURL);
playVideo (flvURL);
logMessage ("Started Playing Video...");
private function constructFLVURL (video_id:String, t:String):String
var str:String = "";
str += "video_id=" + video_id;
str += "&t=" + t;
return str;
private function playVideo (url:String):void
player.source = url;;
private function logMessage (message:String):void
outputText.text += message + "\n";
trace (message);
<mx:HBox width="100%">
<mx:Label text="YouTube Video URL:"/>
<mx:TextInput id="urlText" width="300"/>
<mx:Button label="Submit" click="startLoading ()" id="submitButton"/>
<mx:HBox width="100%">
<mx:VBox height="100%">
<mx:Label text="VideoDisplay:"/>
<mx:VideoDisplay width="320" height="240" id="player"/>
<mx:VBox height="100%" width="100%">
<mx:Label text="Output:-"/>
<mx:TextArea id="outputText" width="100%" height="100%"/>

ActionScript 2.0 code-snippet:-

createEmptyMovieClip ("mc", getNextHighestDepth ());
var _mcl:MovieClipLoader = new MovieClipLoader ();
_mclListener = new Object ();
_mclListener.onLoadStart = function (target:MovieClip)
trace ("The URL is: " + target._url);
var _lv:LoadVars = new LoadVars ();
_lv.decode (target._url.split ("?")[1]);
trace ("t param: " + _lv.t);
trace ("video_id: " + _lv.video_id);
trace ("thumbnail: " + _lv.iurl);
trace ("flv url: " + constructFLVURL (_lv.video_id, _lv.t));
_mcl.unloadClip (target);
function constructFLVURL (videoId:String, t:String):String
var str:String = "";
str += "video_id=" + videoId;
str += "&t=" + t;
return str;
_mcl.addListener (_mclListener);
_mcl.loadClip ("", mc);

 [1] Flash clients would require server-side proxy because YouTube changed crossdomain.xml sometimes back.