OxyTube.com – Blog

Search through YouTube, MySpace, Vimeo, and other video hosting sites simultaneously at http://www.oxytube.com/

YouTube download ability added!

with 9 comments

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.

Written by oxytube

March 8, 2008 at 5:46 pm

9 Responses

Subscribe to comments with RSS.

  1. interesting….
    loads fast too..
    looks good…

    chandra

    March 16, 2008 at 12:43 am

  2. If your site encoded the video into AVI this would be a very handy tool. As it stands, I don’t have much use for it.

    pie

    March 17, 2008 at 12:23 am

  3. I agree with pie

    Dr Sunshine

    March 17, 2008 at 7:40 am

  4. Hello!
    Your script is excellent. I think it could be better if you put each videos in an individual page. Furthermore It will be more atractive for the searches like Google.

    I so interested in your script, how much do you want for this?

    Rescue

    April 9, 2008 at 12:51 pm

  5. to get better vid quality when i download from youtube i use the known &fmt=18 at the end of the address, would be good if this option was available built into the script?
    Anyway greaat stuff, you guys are gods and I a mere mortal.

    elwoode

    April 29, 2008 at 12:38 am

  6. I just found out it’s impossible to embed high quality videos without losing random seeking functionality. Once YouTube allows for the ability I’ll be sure to include it into the script.

    OxyTube

    May 1, 2008 at 11:09 am

  7. Awesome website
    Can’t the video be categorized just like web directory?

    Samiullah

    October 4, 2008 at 10:26 pm

  8. Thanks 4 All

    paya

    October 6, 2008 at 9:26 pm

  9. I forget to tell that after download video formats is unknown.

    paya -Iran

    October 6, 2008 at 9:29 pm


Leave a Reply