@ 2015-12-13T20:01:54Z <?php
// ************************************************************************
// Class PHPTube
// Version: 0.1.3
// Date: 2007/07/01
// Author: Michael Kamleitner (michael.kamleitner@gmail.com)
// WWW: http://www.kamleitner.com/code
// (suggestions, bug-reports & general shouts are welcome)
// Copyright: copyright 2007 - Michael Kamleitner
//
// This file is part of PHPTube
//
// PHPTube is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PHPTube is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with PHPTube; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// ************************************************************************
require_once 'HTTP/Client.php';
require_once 'HTTP/Request.php';
require_once 'HTTP/Client/CookieManager.php';
class PHPTube {
var $cookies;
var $mgr;
var $req;
var $debug = false;
var $auth = false;
// Function: PHPTube ... Initialize YouTube-Object
// Paramters: $username ... YouTube Accountname (if empty, upload is disabled)
// $password ... YouTube Passwort (if empty, upload is disabled)
// $debug ... Debug-Flag
function PHPTube ($username = "", $password = "", $debug = false) {
if ($username != "" && $password != "") {
$url = "http://youtube.com/login?username=".$username."&password=".$password."&next=/index¤t_form=loginForm&action_login=1";
$this->debug = $debug;
$this->req =& new HTTP_Request($url);
$this->req->addHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
$this->mgr = new HTTP_Client_CookieManager();
$response = $this->req->sendRequest();
if (PEAR::isError($response)) {
echo $response->getMessage()."\n";
} else {
$this->auth = true;
$this->cookies = $this->req->getResponseCookies();
$success = false;
foreach ($this->cookies as $c) {
if ($c["name"]=="LOGIN_INFO" && $c["value"]<>"")
$success = true;
}
if (!$success)
die ("Login failed!\n");
}
}
}
// Function: download ... Download any Video-Clip from YouTube
// Paramters: $video_id ... Video-ID as given in YouTube URL (f.e. the Video at http://youtube.com/watch?v=TWZ5j-SNVKs
// has the ID "TWZ5j-SNVKs"
// $video_filename ... local path+filename, the video is downloaded to (check write-permissions!)
function download ($video_id, $video_filename) {
$url = "http://www.youtube.com/watch?v=".$video_id;
$this->req =& new HTTP_Request($url);
$response = $this->req->sendRequest();
if (PEAR::isError($response)) {
echo $response->getMessage()."\n";
} else {
$page = $this->req->getResponseBody();
preg_match('/watch_fullscreen\?video_id=(.*?)&l=(.*?)+&t=(.*?)&/', $page, $match);
$url = "";
$url .= $match[1];
$url .= "&t=";
$url .= $match[3];
$url = "http://www.youtube.com/get_video?video_id=".$url;
if ($this->debug)
print $url."\n";
$req =& new HTTP_Request($url,array ("allowRedirects"=>true, "maxRedirects"=> 99));
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->addHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
$response = $req->sendRequest();
if (PEAR::isError($response)) {
//echo $response->getMessage()."\n";
print "Error: Failed to open YouTube-Source\n";
} else {
if ($o = fopen ($video_filename, "w")) {
fwrite($o,$req->getResponseBody());
fclose ($o);
print "Download done! File: ".$video_filename."\n";
} else {
print "Error: Failed to open target-file\n";
}
}
/* Old Dowload-Code was using fopen
if ($h = fopen ($url,"r")) {
if ($o = fopen ($video_filename, "w")) {
while (fwrite($o,fread($h,1024)));
fclose ($o);
print "Download done! File: ".$video_filename."\n";
} else {
print "Error: Failed to open target-file\n";
}
fclose ($h);
} else {
print "Error: Failed to open YouTube-Source\n";
}
*/
}
}
// Function: upload ... Upload Video-Clip to YouTube
// Returns: ... ID of the new Clip
// Paramters: $video_filename ... local filename of the Clip which is to be uploaded
// $video_title ... Video-Title (String)
// $video_tags ... Tags (String, Separeator = Blank)
// $video_description ... Description (String)
// $video_category ... Category (2=Autos & Vehicles, 23=Comedy, 24=Entertainment,
// 1=Film & Animation, 20=Gadgets & Games, 26=Howto & DIY,
// 10=Music, 25=News & Politics, 22=People & Blogs,
// 15=Pets & Animals, 17=Sports 19=Travel & Places)
// $video_language ("DE", "EN"...)
// $public (true / false)
// $family (true / false) - Not Supported anymore
// $friends (true / false) - Not Supported anymore
function upload ($video_filename, $video_title, $video_tags, $video_description, $video_category, $video_language, $public=true, $family=true, $friends=true)
{
if ($this->auth) {
if (file_exists($video_filename)) {
$url = "http://www.youtube.com/my_videos_upload";
$this->req =& new HTTP_Request($url);
$this->req->setMethod(HTTP_REQUEST_METHOD_POST);
$this->req->addHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
$this->req->addPostData("field_myvideo_title",$video_title);
$this->req->addPostData("field_myvideo_keywords",$video_tags);
$this->req->addPostData("field_myvideo_descr",$video_description);
$this->req->addPostData("language",$video_language);
$this->req->addPostData("field_myvideo_categories",$video_category);
$this->req->addPostData("ignore_broadcast_settings","0");
$this->req->addPostData("action_upload","1");
if ($public) {
$this->req->addPostData("field_privacy","public");
} else {
$this->req->addPostData("field_privacy","private");
// Seems like the Family/Friends-option isn't existing anymore
//if ($family && $friends)
// $this->req->addPostData("share_list","Family,Friends");
//elseif ($family)
// $this->req->addPostData("share_list","Family");
//elseif ($friends)
// $this->req->addPostData("share_list","Friends");
}
foreach ($this->cookies as $c) {
$this->mgr->addCookie ($c);
}
$this->mgr->passCookies ($this->req);
$response = $this->req->sendRequest();
if (PEAR::isError($response)) {
die ("Error: ".$response->getMessage()."\n");
} else {
$p = strpos($this->req->getResponseBody(),"id=\"theForm\"");
$p = strrpos(substr($this->req->getResponseBody(),0,$p),"<form");
$p = $p + strpos(substr($this->req->getResponseBody(),$p),"action=\"") + 8;
$url = substr($this->req->getResponseBody(),$p,strpos(substr($this->req->getResponseBody(),$p),"\""));
$p = strpos($this->req->getResponseBody(),"name=\"addresser\" value=\"");
$addresser = substr($this->req->getResponseBody(),$p+24,strpos(substr($this->req->getResponseBody(),$p+24),"\""));
if ($this->debug) {
print "action: ".$url."\n";
print "addresser: ".$addresser."\n";
}
$this->req =& new HTTP_Request($url);
$this->req->addHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
$this->req->setMethod(HTTP_REQUEST_METHOD_POST);
$this->req->addPostData("field_command","myvideo_submit");
$this->req->addPostData("field_myvideo_title",$video_title);
$this->req->addPostData("field_myvideo_keywords",$video_tags);
$this->req->addPostData("field_myvideo_descr",$video_description);
$this->req->addPostData("language",$video_language);
$this->req->addPostData("field_myvideo_categories",$video_category);
$this->req->addPostData("action_upload","1");
$this->req->addPostData("addresser",$addresser);
if ($public) {
$this->req->addPostData("field_privacy","public");
} else {
$this->req->addPostData("field_privacy","private");
//if ($family && $friends)
// $this->req->addPostData("share_list","Family,Friends");
//elseif ($family)
// $this->req->addPostData("share_list","Family");
//elseif ($friends)
// $this->req->addPostData("share_list","Friends");
}
if ($this->debug)
print "file: ".$video_filename."\n";
$this->req->addFile("field_uploadfile",$video_filename);
$this->mgr->passCookies ($this->req);
$response = $this->req->sendRequest();
if (PEAR::isError($response)) {
echo "Error: ".$response->getMessage()."\n" ;
} else {
if ($this->debug)
print "Upload OK - ".$response."!\n";
$this->req =& new HTTP_Request("http://youtube.com/my_videos");
$this->mgr->passCookies ($this->req);
$response = $this->req->sendRequest();
if (PEAR::isError($response)) {
echo $response->getMessage()."\n";
} else {
$p = strpos($this->req->getResponseBody(),"id=\"checkbox_");
$video_id = substr($this->req->getResponseBody(),$p+13,
strpos(substr($this->req->getResponseBody(),$p+13),"\""));
print "Upload done! ID: ".$video_id."\n";
return $video_id;
}
}
}
}
} else {
print "Error: not authenticated!\n";
}
}
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.0.7 0.013 0.073 19.84 7.0.6 0.007 0.083 19.94 7.0.5 0.007 0.053 20.28 7.0.4 0.010 0.083 20.13 7.0.3 0.013 0.083 20.14 7.0.2 0.007 0.087 20.18 7.0.1 0.010 0.077 20.10 7.0.0 0.013 0.080 20.07 5.6.22 0.010 0.077 20.75 5.6.21 0.003 0.083 20.84 5.6.20 0.010 0.077 21.20 5.6.19 0.020 0.067 21.14 5.6.18 0.013 0.057 21.19 5.6.17 0.007 0.050 21.19 5.6.16 0.003 0.073 21.13 5.6.15 0.010 0.080 21.26 5.6.14 0.007 0.087 21.15 5.6.13 0.007 0.050 21.09 5.6.12 0.023 0.073 21.22 5.6.11 0.000 0.060 21.13 5.6.10 0.013 0.037 21.18 5.6.9 0.013 0.070 21.07 5.6.8 0.007 0.083 20.54 5.6.7 0.013 0.073 20.43 5.6.6 0.010 0.063 20.54 5.6.5 0.017 0.043 20.41 5.6.4 0.013 0.073 20.55 5.6.3 0.010 0.077 20.50 5.6.2 0.007 0.077 20.47 5.6.1 0.003 0.043 20.48 5.6.0 0.013 0.070 20.51 5.5.36 0.007 0.070 20.48 5.5.35 0.007 0.083 20.52 5.5.34 0.017 0.073 20.98 5.5.33 0.007 0.080 20.88 5.5.32 0.017 0.070 20.89 5.5.31 0.010 0.080 20.87 5.5.30 0.017 0.070 20.95 5.5.29 0.013 0.053 20.82 5.5.28 0.000 0.080 21.02 5.5.27 0.013 0.073 20.88 5.5.26 0.017 0.043 21.01 5.5.25 0.007 0.040 20.79 5.5.24 0.007 0.083 20.21 5.5.23 0.007 0.080 20.39 5.5.22 0.013 0.070 20.34 5.5.21 0.020 0.070 20.38 5.5.20 0.003 0.083 20.32 5.5.19 0.017 0.070 20.17 5.5.18 0.003 0.060 20.28 5.5.16 0.003 0.050 20.33 5.5.15 0.013 0.077 20.28 5.5.14 0.007 0.080 20.08 5.5.13 0.010 0.077 20.27 5.5.12 0.010 0.043 20.08 5.5.11 0.007 0.077 20.30 5.5.10 0.010 0.087 20.17 5.5.9 0.010 0.080 20.18 5.5.8 0.003 0.040 20.16 5.5.7 0.007 0.060 20.18 5.5.6 0.007 0.083 20.23 5.5.5 0.017 0.037 20.14 5.5.4 0.013 0.073 20.10 5.5.3 0.000 0.053 20.17 5.5.2 0.020 0.067 20.23 5.5.1 0.010 0.060 20.13 5.5.0 0.007 0.047 20.09
preferences:dark mode live preview
145.69 ms | 1394 KiB | 7 Q