PHPTube – YouTube API f. Video Upload & Download
May 21st, 2007 by m.kamleitner
Attention: as of January 29th, I’ve decided to stop support for PHPTube! Due to recent changes in the YouTube uploading-process, uploading with PHPTube won’t work anymore! I recommend using the offical YouTube API, which can do uploads just fine! Since PHPTube is released under GPL, you’re of course free to adapt it!
Das momentan von YouTube angebotene API ist leider read-only und unterstützt weder den skript-gesteuerten Upload noch Download von Videos. Meine kleiner Hack – PHPTube – beseitigt dieses Manko in dem es beide Funktionalitäten über eine sauber gekapselte PHP-Klasse bereitstellt. Vor allem die Möglichkeit, automatisiert Videos auf YouTube hochzuladen – und damit YouTube beispielsweise als Video-Server für eigene Web-Applikationen zu “missbrauchen” – habe ich in dieser Form nirgendwo anders gefunden.
YouTube’s API – basically a read-only set of RSS-feeds and XML/RPC-calls – currently doesn’t support scripted upload or download of videofiles. My quick hack PHPTube offers this featureset in a cleanly encapsulated PHP-class. Special interest goes to the upload-functionality, which virtually allows the integration of YouTube as a video-storage-backend into any other web-app. And while there are several download-scripts out there on the web, I’ve yet to find another uploader.
Warning: due to changes in the YouTube HTML, all versions prior 0.1.7 are obsolete!
Download: PHPTube 0.1.7
Requirements: PEAR/HTTP
Attention: If you’re looking for PEAR, goto http://pear.php.net/ and read http://pear.php.net/manual/en/installation.getting.php!
Ports: Java-port of PHPTube (by James Schopp), Python-Port (by Sylvain Boily), Joomla-Plugin (download-only, by Mohamad Ballouk) – thx!
Using PHPTube? Consider a donation to keep things rolling… Thanks!
,
,
,
)
[...] of RSS-feeds – currently doesn’t support scripted upload or download of videofiles. My quick hack PHPTube offers this featureset in a cleanly encapsulated PHP-class. Special interest goes to the [...]
[...] Eigentlich ist die YouTube API nur read-only. Eigentlich. [...]
HI I am doing a website which is non-profit just for friend and social network.
I have embeded a uploading feature in my website and want to give a facility for user to upload the same content to youtube assuming they provide the username and password.
Please comment me on your code, for requirement and all. as i am using window 2003, Sql Server. Please suggest me any extra tools required to run PHPTube on this system
@Rawoof: from what you’re describing, PHPTube should do the job! just make sure you’re running a current version of PHP (+PEAR) on your system.
Dear m.kamleitner,
Thank i did and its working fine, i have uploaded some 3gp files too. But i can see that
1. sometimes it works perfectly fine but some time its taking too long and get halt down.
2. I dont get the ID in response but can see the file uploaded on youtube
Any suggestion what can be wrong?
@Rawoof: hm, just guessing – maybe some of your video-uploads exceed YouTube’s restriction in terms of video-length/size?
[...] der anderen Seite stehen Dinge wie DIY-Schneiderei, eine API zum Upload bei Youtube und ein großer Mineralwasser-Vergleich, die ich ohne Zögern als „Blogperle“ bezeichnen [...]
One note:
if a large video is being uploaded, it could exceed the PHP max execution time (30 seconds). Add a line to the upload function:
ini_set(‘max_execution_time’, 200);
This sets the max execution time to 200 seconds and will allow larger videos to upload without timing out.
Hi,
Congrats for this development which works perfectly. By the way, have you planned to add VIDEO DELETION which would be also great for perfect integration.
Best
JC
thx JC, for this excellent idea…
I’ll probably add deletion, but don’t expect me to release this until october, as I’m pretty overloaded with work right now…
thx again!
too bad my host does not provide PEAR. is PEAR required for all YouTube API scripts?
thanks!
I don’t really know much about this stuff at all but I can usually find my way around these things with some instructions. I couldn’t find any installation help anywhere on the site. Can somebody please help me out. Thanks
I was looking for a wordpress plugin. This doesn’t appear to be one. Is there a plugin of this for wordpress available. Also, I tried executing the demo.php and the phptube.php and I get the following errors. Running demo Warning: fopen(http://www.youtube.com/get_video?video_id=&t=) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/hypocrit/public_html/phptube.php on line 92
Error: Failed to open YouTube-Source Error: No URL .
Running phptube.php I get a blank screen.
Hi Justin, seems you’re missing the PEAR-library which is required for running phptube. You find more info about this on my english-language blog, http://nonsmokingarea.com/blog/2007/06/16/phptube-youtube-api-for-video-upload-download/
Michael,
Great tool. Just wanted to let you know that I have ported this utility to Java as well, and it works great. I also released it under GPL, and gave you credit where applicable. The java library can be found at:
http://www.jimischopp.com/jimischopp.com/Commentary/75ABCA7F-D109-482E-922D-3D0CC5E64975.html
thanks!
james
thx a lot James, your work is highly appreciated!
I’ll add links to your port…
regards,
michael
[...] able to upload movies via your own online application, YouTube was proven useless. I found one solution for this, but it’s far from the official API and kind of shady. Support for remote uploading [...]
I wonder what YouTube’s position is with people using this method of uploading videos. Would it not violate their T&Cs?
Excellent class, easy to use and understand. I’m just curious though; the upload function is
upload ($video_filename, …
as I understand it, the file needs to be already on the server you’re executing the script from correct? Is it possible to use a file upload to pull it from the end-users local machine and load it onto youtube, instead of… uploading to the current server, making a temp file, then using that temp file and loading it to youtube. I’d hate to have to have twice the upload time cause it has to upload onto two different servers.
Hi Lucas, thx for your kind words.
you’re absolutely right, the process requires the video-file to be on the same server as the PHPTube-script, so you’ll probably want your users to upload the file to your server, and than trigger the upload to YouTube via PHPTube in the background (that way the user wouldn’t have to wait for the YouTube-upload to finish).
Unfortunately I’m currently not aware of any possibility to avoid this behavior
OK thanks for the reply. I had figured the same thing. But you never know what other types of PHP trickery other people may have up their sleeve. Thanks again for the script though, it works like a champ!
PHPTube class is very good!
but I suffered an error while uploading with 2BYTES character.
sample code is below….
upload (“videofile.3gp”,”テスト Remote Tube2″, “PHP YouTube by PHPTube”, “…”, 10, “JA”);
?>
“テスト” means “TEST” with japanese.
Above code is well executed, but movie was NOT registerd!
maybe the reason is title of 2 BYTES character?
Please forgive my humble english…
Gong GunDoo
Hello!
Have you thought to add another useful script like video.google.com video uploader?:)
I’m using PhpTube right now and it works perfectly!
However I want to make a script to submit to all major video sharing websites!I’m at the begining and learning !Can you point me please?
Here is my code untill now for video.google.com :
login :
$postdata=?continue=http://video.google.com&skipvpage=true&sendvemail=false&hl=en&Email=? . $user . “&Passwd=? . $pass . “&rmShown=1&PersistentCookie=&signIn=Sign in?;
// login to google account
$user = “?;
$pass = “?;
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, “my_cookies.txt?);
curl_setopt($ch, CURLOPT_URL,?https://www.google.com/accounts/LoginAuth?continue=http%3A%2F%2Fvideo.google.com%2F&hl=en?);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
ob_start(); // prevent any output
curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($ch);
unset($ch);
login script works perfectly , but when I try to upload the video using this code :
$postdata[’video-file’]=?”;
$postdata[’title’]=?”;
$postdata[’description’]=?”;
$postdata[’genre’]=?”;
$postdata[’language’]=?”;
$postdata[’access’]=?”;
$postdata[’tos’]=?agree?;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,?http://video.google.com/videouploadform?);
curl_setopt($ch, CURLOPT_COOKIEJAR, “my_cookies.txt?); //initiates cookie file if needed
curl_setopt($ch, CURLOPT_COOKIEFILE, “my_cookies.txt?); // Uses cookies from previous session if exist
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); // follow redirects recursively
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
$buf=curl_exec ($ch);
curl_close ($ch);
echo $buf;
I get this error :
HTTP method POST is not supported by this URL
Can you tell me where is the error ?:(
Thanks!
Hi Junior,
glad you like PHPTube! however, I’ve currently no plans to support other video-sites like Google Video, althouh this is an interesting project, I just can’t spare the time at the moment…
Can’t comment on your code either, as I’ve never looked on the Google Video-upload html-code, sorry!
Can somebody show me an example of this working please?
I am wanting to implement this into a non-commercial website i am doing but am struggling to understand if i need an interface to test this or if there is a way i can upload an .avi file from the local computer onto my server then use phptube to upload to youtube and convert to .flv?
Thanks for help and support with this!
Hi Dan, checkout http://nonsmokingarea.com/blog/2007/06/16/phptube-youtube-api-for-video-upload-download/, your questions are answered there in the comments!
thx!
Hi… new changes in the YouTube upload-forms?
Thanks.
Hello
m.kamleitner
i have an problem for the PHPtub
give me this
” Login failed!”
Gaurang Jadav
(software engineer )
Aurosys Solutions Pvt.Ltd
Ahmedabad
Hi Gaurang…
did you enter your correct youtube-credentials in demo.php?
hello
m.kamleitner
as an when me run this demo.php its give me an error like this
Warning: fopen(http://www.youtube.com/get_video?video_id=&t=) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\wamp\www\phptube\phptube.php on line 95
Error: Failed to open YouTube-Source Error: No URL given
Gaurang Jadav
Update: V 0.1.4 fixes a problem with the download-method, caused by a recent change in YouTube’s HTML. If you’re only using phpTube’s upload-feature, you don’t have to upgrade.
[...] http://kamleitner.com [...]
Hi, how can i use this class with loops?
$lines[1]=yaA4qyfv5hA;
$lines[2]=2KQ0KuyduXk;
for($i=1;$idownload(“$lines[$i]“,”$i.flv”); }
give me 1.flv – 0 bytes, 2.flv – ok
hi,
When i upload a file, the size is 0 byte and there is no error. Can you help me?
thanks.
@vtoledo37: sorry, I’ld need more details to check on your problem. what exactly are you trying to do (code?), and which file has 0 byte size?
Can we port this utility to .NET ?, to use in asp.net websites.
=Uday
@uday: sure, feel free!
but you might also check the official youtube-api for uploading first (it’s only one week old).
http://nonsmokingarea.com/blog/2008/03/12/youtube-api-finally-supporting-uploads/
hi,
upload and download of videos is working fine.
can i delete a video on youtube using script in php
@padmini: sorry, delete & edit is currently not supported! you might want to check out the official youtube upload-API, which has been released in the meantime:
http://nonsmokingarea.com/blog/2008/03/12/youtube-api-finally-supporting-uploads/
[...] haben sich schon einige freundliche Menschen die Mühe gemacht, Ports meiner YouTube-Upload-API PHPTube zu entwicklen. Obwohl es seit kurzem ja auch eine offizielle API zum Upload gibt (näheres dazu auf [...]
YouTubeRobot.com today announces YouTube Robot 2.0, a tool that enables you to download video from YouTube.com onto your PC, convert it to various formats to watch it when you are on the road on mobile devices like mobile phone, iPod, iPhone, Pocket PC, PSP, or Zune.
YouTube Robot allows you to search for videos using keywords or browse video by category, author, channel, language, tags, etc. When you find something noteworthy, you can preview the video right in YouTube Robot and then download it onto the hard disk drive. The speed, at which you will be downloading, is very high: up to 5 times faster than other software when you download a single file and up to 4 times faster when you download multiple files at a time.
Manual download is not the only option with YouTube Robot. You may as well schedule the download and conversion tasks to be executed automatically, even when you are not around. Downloading is followed by conversion to the format of your choice and uploading videos to a mobile device (if needed). For example, you can plug in iPod, select the video, go to bed, and when you wake up next morning, your iPod will be ready to play new YouTube videos.
Product page: ww w.youtuberobot.com
Direct download link: ww w.youtuberobot.com/download/utuberobot.exe
Company web-site: ww w.youtuberobot.com
E-mail: support@youtuberobot.com
Hi, can u tell me tht how to convert any file(it may be video, swf, image, .dat, mp3, mpeg or any format) into flv and then upload in a folder and send information into database. i m using php and mysql.
please reply asap…..
sorry for my humble english…
@Rituraj: sorry, but I don’t see how your question is related to PHPTube?
In general, what you want to do is not trivial. You will have to look into ffmpeg, to commandline-tool which can be used to convert video, mpeg and (maybe) mp3 & images to flv. however I don’t see a way how this would work with .swf.
Hi everbody,
due to a recent change in YouTube’s HTML, you’re strongly recommended to upgrade to PHPTube 0.1.5!
Up until today everything has been fine but now when I use it I get “Login Failed”. I have checked the pass and user and these are correct. I am using 0.1.6
Hi,
I have an problem, give me this: Login failed!
But when i try http://youtube.com/login?username=“.$username.”&password=”.$password.”&next=/index¤t_form=loginForm&action_login=1
I can logon in youtube…
yeah, looks like something changed on the side of YouTube
unfortunately I’m travelling til august 14, so I won’t have a chance to fix this right now…maybe someone else want to look into this?
Is there anything changed..I am not able to create account on Yuotube as well and even my previously working code is no more working ……
=Uday Kadam
Same problem here, can’t login
There’s a quick fix for the problem posted on my other blog:
http://nonsmokingarea.com/blog/2007/06/16/phptube-youtube-api-for-video-upload-download/#comment-88097
I’ll post a patch after my return next thursday…
A fantastic site, and brilliant effort. A great piece of work.
just released 0.1.7, which patches the login-problem…
Is there any way I can set the Rating option to disabled. I dont like having my videos rated and would like to tun that option to disabled.
@DaZZ: sorry, this is currently not supported by PHPTube!
Hi,
I m getting “login failed” .Please give me a solution for this.
@tarangini: did you pass your correct youtube-accountname & -password when initializing the phptube object?
i can’t do login! all time appear “login faild”
@Pedro Monteiro: same here, did you pass your correct youtube-accountname & -password when initializing the phptube object?
Are you using V 0.1.7? all prior versions are obsolete!!
I have a problem width the downloads.
The videos are downloaded to my site server not to the clients.
Why does this happens?
@Troy: PHPTube is basically a server-based tool (although you could it run it on a client as well).
You can always read the file from your server’s file-system (fopen, fread) and output it to the user’s browser (don’t forget to set the right http-headers).
It’s time for version 0.1.8 cause i’m getting login failed again
login failed with version 0.1.7
Great work yet! But to this time, the deletion op remains. What do you mean will it take to code this function?
login failed with version 0.1.7
we have to use API !?
any idea?
@rovshan: 0.1.7 is still working for me, just successfully uploaded 2 clips…
It seems like that sometimes it works and sometimes it doesnt..
Hi, the delete function is very attractive, any plans to invoke it and when?
Hello m.kamleitner,
I have a few questions.
1. If i have video key(v=AHxNThhnB2Q for example), how i can check is available HD version for this video with php?
2. How i can get path to HD version of video?
Thanks.
Keep getting login failed now
sorry guys, I’ve just spent some time trying to fix this thing, but I couldn’t figure it out…
I could fix the login-problem by setting allowRedirect to false and setting the URL to “de.youtube.com”, but after logging in, uploading won’t work since there have been major changes to the upload-process (flash-uploader etc.)
I’m not going to fix this one, as I’ld strongly recommend everyone to switch to the official YouTube-API, which can do uploads since quite some time.
sorry again, but it’s time to move on
This api is grate, but i noticed that youtube API has been changed.
Anyway I found something similar at http://www.webdryver.com/php-tutorials/youtube-gdata-php-script-for-video-upload.html
Would be grate to update your script.
Thanks and keep the grate job.
hi , m using ver phptube 0.1.7.. login failed getting..
any luck ?
Hi Kamleitner,
I am working on video module.
I am trying to upload video using youtube url.
but don’t know which details can I enter in following code.
$tube = new PHPTube (“username”, “password”, true);
also want to know parameters of the upload function.
$id = $tube->upload (“videofile.3gp”,”PHPTube Demo”, “Demo PHP YouTube”, “…”, 10, “DE”);
help me on same.
thanks for reading my comments.
HiramMAN Patil….
Hi Kamleitner,
I am trying to upload my video using PHPTube but it is showing Login Failed!! but my username and password is correct can u pls help me to solve this problem..
Thanx
Hi,
Something has been changed on youtube, and now it doesn’t work.
Youtube now has it’s own browser base upload api. check this out!
http://code.google.com/apis/youtube/2.0/developers_guide_protocol_browser_based_uploading.html
hi i am using phptube 0.1.7 i need your help for edit videos
Great post!