Problem in a PHP script that graps youtube videos


I’m working on a PHP script that used to grap videos from youtube. It was working properly until the new update of YouTube. I tried to figure out the problem and make the suitable change in the code in order to make it compatible with the new YouTube website. The video page on youtube still has the parameter fmt_url_map which carry the URLs of the FLV files of the video in different quality.

The script decodes these URLs and print them. On my localhost I can use the URLs to download but when the script runs on my website, youtube gives me “Forbidden 403 error” when I click the URLs (ex:

This is my PHP code:

$youTubeFile = file_get_contents($_POST[youtubevideolink]);
preg_match('/&fmt_url_map=(.*?)&/', $youTubeFile, $match);
$urls = urldecode($match[1]);
$urls = explode(",", $urls);
foreach($urls AS $url)
 $explode = explode("|", $url);
 echo "$explode[0] : <a href='$explode[1]'>".$explode[1]."</a><hr>";

I have these questions:

1- I read that YouTube consider downloading their videos is a violation of their terms of use but Iam not sure about that. If so, why do they allow RealPlayer and the other Windows applications to download their videos? Also, why do they leave the fmt_url_map parameter on the video page source?

2- I noticed that most of the websites that allow you to download from youtube stopped working but I found this website which states that they made an upgrade to make their website compatible with the new YouTube which means that the upgrade is possible. Any help on how to fix my code to meet the new update?

Thanks in advance.