YouTube download ability added!
I’ve added the ability to download YouTube videos from OxyTube directly. Just click on the download input button on the far right of a video result and wait for a second or two.
Just in case you’re wondering how it’s done:
<?php
$engineName = $_POST['engine'];
$id = $_POST['id'];
switch ($engineName) {
case "youtube":
$txt = file_get_contents("http://youtube.com/watch?v=" . $id);
$t = substr($txt, strpos($txt, '"t":') + 6, 32);
$url = "http://www.youtube.com/get_video?video_id=" . $id . "&t=" . $t;
break;
case "myspace":
// myspace: short urls?, long id case is specific case of general bitwise operations?
$lastFour = strrev(substr($id, strlen($id) - 4));
$firstChars = substr($id, 0, strlen($id) - 5);
while (strlen($firstChars) < 7) $firstChars = "0" . $firstChars;
$url = "http://content.movies.myspace.com/" . $firstChars . "/" . substr($lastFour, 0, 2) . "/" . substr($lastFour, 2) . "/" . $id . ".flv";
break;
}
echo $url;
?>
The code should be pretty self explanatory.
For YouTube, within a video’s page source, there lies an SWF argument ambiguously named “t”. Find the value of the 32 characters string “t” and the download URL is merely:
http://www.youtube.com/get_video?video_id=<id>&t=<t>
where <id> refers to a video’s id and <t> refers to the SWF arg “t”. The above could also be accomplished with regular expressions, however I think substr and strpos are easier to understand.
I’ve also figured out how to generate MySpace download URL’s for videos with ID’s of length 10. Unfortunately some older videos have ID’s of less than 10 characters. In the near future I’ll add the ability to download from other sites such as Vimeo and MySpace.

