The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

This is probably far from the best way to do it, but it works. BUT, there is a problem now, as of yesterday, and I need to find a solution. Basically, the process goes something like this (the URLs expire BTW):

Recently it seems that YouTube have started to restrict access to the video to the IP of the machine that requested it. This means that if you make the JavaScript above in to a link and drag it to your shortcut bar that you can click it on the YouTube page and you will be prompted to download the video. It also means that if I run my script on my machine that I get a working URL, which I can use in other places on the web to allow me to download it, but nobody else can use it. Changing the IP is not good enough.

A solution? Well I figure that if I can have a file that acts as a proxy on my server, that requests the file, so my web server's IP is recorded, and then streams the video through, then anyone will be able to watch the video. But is this feasible, and if so, how do I do it?

A direct download won't work for another user, as YouTube are specifying the IP address in the URL. As far as YouTube is concerned, it must be my server that is downloading it. I need it to work for a streaming media system you see. What I've got right now is a page that loads the .MP4 in to memory, and then sends it to the client with no problems, but it's time and memory consuming, and I can't do that on a public web server

Ah I see, I thought you just wanted to provide a download link for your users. The code above negates the IP issue because it sends the user to youtube to download the file, rather that have your server, well, serve it.

Yeah, that works already for me though, so it's not a problem. I just can't work out a way to not fill my servers memory when I'm doing this. There's also the execution time that is causing a problem. I guess I effectively want a pipe, maybe? If it's not feasible then it's not feasible and I'll have to let it go

I think I'm doing all of that, bar the block bit at the end. Not sure how to do that. I've just been loading the whole thing in to a variable and echoing it when it's ready (after sending an MP4 header first)

Firstly, I need the video to play in browser, and not download, so I removed this line:
header('content-disposition: attachment; filename=video.mp4');

Secondly, I'm still sat waiting for the video to buffer and then I get a question mark in a Quicktime logo. I removed the content-type header to get the output in a browser by my FF self destructed. I'm guessing that the script timed out. Either way, I can't have it buffer so much, it needs to be outputting some content within seconds

Any idea why I'm buffering the whole video? Is there a way to split it into small chunks, say 128kb at a time, send it to the client, then clear what's already in memory and continue? I need to do this without killing my web server