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.

  • Hey guys! i just found this website and it seems to be the best and simple youtube flash video player /ripper so far. You can even put your own logo in the videos.
    enjoy guys

  • abdulla

    how to play yahoo video url in flash (actionscript). i got the example for loading you tube plz help me

  • maloola

    what about using the youtube flvs for capturing the bitmap (bitmap.draw()) ? is this allowed without a proxy? don’t want to use one..

  • Mincheol Lee

    I just started to learn flex, and I am working on developing YouTubeWidget. and It looks like this converting feature would be great help to me.
    However, it doesn’t work to me. The link generated from here doesn’t work with VideoDisplay. Also, your sample also doesn’t work.
    Is this out of date formula for converting URL to Flv URL?
    Thank you!

  • rony

    Suddenly we don’t get the ‘t’ in the urlVars. does someone know what is the new way to retrieve it?

  • Andy Milburn

    This hack, after working reliably for a year, appears to have been broken by a change in Youtube format. Can anyone else confirm this? Any workarounds yet?

  • Greg

    Seems to no longer work.
    Would be nice to have an update, … but …

  • Yep!
    Seems to no longer work.
    Would be nice to have an update, … but …

  • Seraphim

    Please! Someone help! What is new format???

  • ural

    doesn’t work now! t urlVars = undefined

  • kay

    Hi It was so useful for me. But since last week the program doesn`t work. I think the U-tube change url method or thet don`t want to acess like this way. I really want to use this program again. so do U have another way to use it?? thank you for you`re kindness Bye 🙂

  • gaurav

    Yes it doesn’t work now.

  • Brian

    I have found a solution to this issue. Hopefully the following steps will work for you as well.

    1. Get the URL to the clip you wish to load. This URL must be of the form

      . If you are getting the URLs from the standardfeeds url (, the URL to the clip is the media:player item
    2. Load this URL and scan the source of the page for the “watch_fullscreen” URL. It will look something like this:
      var fullscreenUrl = ‘/watch_fullscreen?fs=1…
    3. Take everything after “watch_fullscreen?” and save it to a variable (we’ll use params)
    4. Generate your FLV url as follows:

        finalURL = “” + params;

      And there you go. Hope this works for you.

  • jean-marc

    They changed the code on their server.
    Even though I can get the t var and perform a GET on the get_video url, i get a 404 not found on the download.
    But if I use a web browser and view the source, and manually extract the t variable, the download link works.
    Maybe it’s something to do with cookies…

  • Yes

    Yes, youtube’s broken the “t=” method. Not sure how to resolve this. They’re saying that downloading videos breaks the “Terms of Service” agreement.

  • owen

    Hmm… I’m trying to write a workaround for this right now. The AS3 chromeless API might work, as long as you don’t mind using the external interface controls for your embedded player.

  • mincheol Lee

    Your blog helped me to develop Youtube widget player. Thank you!
    As other people said, the url format had been changed. Does anyone find the new way of getting flv url?

  • use this way to call the video-url. First call, you should return the result in AS2/3 as a text (html), then search for the text swfargs = and decode the variables in this string, then you can rebuild the right url again, I’ve got it working on my own site

  • download the html page in as3 (…..), search for swfargs= and split and decode the parameters behind this string, then you can compose the video-url again, it works on my site

  • Hi Guys
    Sorry for not responding to your comments, seems it’s time for an updated post for latest workaround.
    I have been busy with many things, one of those is Chromeless AS3 Player (YouTube) Wrapper – It uses ExternalInterace or LocalConnection (both options would be there).
    Once it’s ready, I would post it.

  • This technique to get the FLV URL indeed no longer work. You now have to load the swf web page and extract the parameters from there. I’ve posted the source code to do that on my blog:

  • comment obtenir l’url flv de youtube avec un script php

  • Bora

    Notice: Undefined offset: 1 in dm.php on line 77
    This script is wrong! Anyone know working code?

  • Seems like YouTube is working against this obviously, all new php scrips work for a while then they stop working.

  • Name

    Since August 12 2009 Youtube has changed the htlm source code of their video web pages,,,so this old method doesnt work anymore…

    Does somebody know how to build the the donwload url for the new youtube video pages format?

    • Yup! YouTube has done changes so many times, they kept changing the ways. After a point, it was hard for me to keep track of it, hence no update in my script in long time.

      I always promise to update it but can’t, due to various other commitments. I am sure, there are a lot of folks who are taking care of it, i.e. always coming up with new ways to do things.

  • Z

    Tryout … it works perfectly for all videos (including HD!)

  • Miranda

    How can we play video from domains like Youtube like dailymotion?

    • I am sure, there are ways to do. This post is very old and I am not even sure, these techniques work anymore.