I come up with this idea after realizing that downloading on my Youtube online video downloader and converter doesn't support download accelerator (only one part/thread) and doesn't support resuming paused download. Personally I didn't like this because my internet connection is not dedicated and not too fast (well, it's common on my country).
I'm using PHP to serve the converted file to users. I think there must be something that can solve the issue. I know it can be done because Indowebster.com use this kind of technique. After looking at the header that Indowebster send to user, I bump into some strange header: X-Accel-Redirect. Maybe this is the key to overcome my problem.
I'm Googling a bit then realize that X-Accel-Redirect header is belong to Nginx where my VPS is using Apache as the web server. Googling again a bit deeper, found one Apache header that compatible with Nginx X-Accel-Redirect that is X-Sendfile. The installation is very easy on CentOS 5:
If you're using other distros than CentOS, make sure your Apache .conf files consist this following lines:
Using mod_xsendfile (X-Sendfile) on PHP
You can find some PHP example on Apache mod_xsendfile page. On my Youtube online video downloader and converter, I'm using this code (just some part of it) :
Now, my Youtube downloader is supporting download accelerator and paused download can be resumed.
This is download screenshot before applying Apache mod_xsendfile (X-Sendfile) -- only one thread/part and NO resume capability :

And this is screenshot after applying Apache mod_xsendfile (X-Sendfile) -- multi-part downloading and resume capability :

Yeah, more power for leechers! LOL!
Limitation on my Youtube Online Converter
Well, still, it has limitation like the grabbing process (before conversion) is still slow like-a-hell. in some case, after conversion done, you're redirected to homepage rather than download page. If this happen to you, you just need to redownload it again (enter the youtube URL and click 'convert' again).
There's another limitation: the conversion result file will be automatically deleted after 12 hours.
Enjoy the service!
I'm using PHP to serve the converted file to users. I think there must be something that can solve the issue. I know it can be done because Indowebster.com use this kind of technique. After looking at the header that Indowebster send to user, I bump into some strange header: X-Accel-Redirect. Maybe this is the key to overcome my problem.
I'm Googling a bit then realize that X-Accel-Redirect header is belong to Nginx where my VPS is using Apache as the web server. Googling again a bit deeper, found one Apache header that compatible with Nginx X-Accel-Redirect that is X-Sendfile. The installation is very easy on CentOS 5:
- install the package: # yum install mod_xsendfile
- restart Apache: # /etc/init.d/httpd restart
If you're using other distros than CentOS, make sure your Apache .conf files consist this following lines:
LoadModule xsendfile_module modules/mod_xsendfile.sodon't forget to restart Apache.
XSendFile on
XSendFileAllowAbove off
Using mod_xsendfile (X-Sendfile) on PHP
You can find some PHP example on Apache mod_xsendfile page. On my Youtube online video downloader and converter, I'm using this code (just some part of it) :
//code snippet ....
$mp3name =md5($v) . $ext;
$location="./tmp/" . $mp3name;
$type ="application/octet-stream";
$fname =$title . $ext;
header ('Content-Description: File Transfer');
header ("Content-Type: $type");
header ('Content-Disposition: attachment; filename="' . $fname . '"');
header ('Content-Transfer-Encoding: binary');
header ('Expires: 0');
header ('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header ('Pragma: public');
header ("X-Sendfile: " . $location);
?>
Now, my Youtube downloader is supporting download accelerator and paused download can be resumed.
This is download screenshot before applying Apache mod_xsendfile (X-Sendfile) -- only one thread/part and NO resume capability :

And this is screenshot after applying Apache mod_xsendfile (X-Sendfile) -- multi-part downloading and resume capability :

Yeah, more power for leechers! LOL!
Limitation on my Youtube Online Converter
Well, still, it has limitation like the grabbing process (before conversion) is still slow like-a-hell. in some case, after conversion done, you're redirected to homepage rather than download page. If this happen to you, you just need to redownload it again (enter the youtube URL and click 'convert' again).
There's another limitation: the conversion result file will be automatically deleted after 12 hours.
Enjoy the service!



0 komentar:
Post a Comment