#!/usr/bin/perl use HTTP::Request::Common; use LWP::UserAgent; use strict; my (%conf, $url, $ua, $res); my $configfile = shift or die("ERROR: usage: $0 \n"); loadconf($configfile); # Create user agent, make it look like FireFox and store cookies $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20051213 Firefox/1.0.7"); $ua->cookie_jar ( {} ); # Request the login page. $ua->request ( GET "https://www.google.com/accounts/Login?skipvpage=true&sendvemail=false&continue=http%3A%2F%2Fvideo.google.com%2F&hl=en" ); # Login with our user/pass # Note username = foo not foo@gmail.com $res = $ua->request( POST "https://www.google.com/accounts/LoginAuth?continue=http%3A%2F%2Fvideo.google.com%2F&hl=en", Referer => "https://www.google.com/accounts/Login?skipvpage=true&sendvemail=false&continue=http%3A%2F%2Fvideo.google.com%2F&hl=en", Content_Type => "application/x-www-form-urlencoded", Content => [ continue => "http://video.google.com/", skipvpage => "true", sendvemail => "false", hl => "en", Email => $conf{'Username'}, Passwd => $conf{'Password'}, rmShown => "1", ] ); # Google redirects (302) to a new page when login is success # and returns OK (200) if the login failed. die("ERROR: Login Failed\n") unless ($res->is_redirect()); # At this point we are logged in. # A dummy request to the upload page to get the proper cookies # and look like a real browser. $ua->request(GET "http://video.google.com/videouploadform?utm_campaign=gv-ww-hdr&utm_source=EM&utm_medium=link", Referer => "http://video.google.com/"); $res = $ua->request( POST 'http://www.google.com/video/uploader/form/videoonline', Referer => 'http://video.google.com/videouploadform?utm_campaign=gv-ww-hdr&utm_source=EM&utm_medium=link', Content_Type => 'multipart/form-data', Content => [ baseurl => 'http://video.google.com', domain => 'video.google.com', countrycode => "US", hl => "en", 'video-file' => [ $conf{'File'} ], title => $conf{'Title'}, description => $conf{'Descr'}, genere => "SPECIAL_INT", language => "EN", access => "public", s => 'Upload video', ] ); die("ERROR: Upload failed\n") unless $res->is_redirect(); # Follow that last redirect $res = $ua->request( GET $res->header("Location"), Referer => "http://video.google.com/videouploadform?utm_campaign=gv-ww-hdr&utm_source=EM&utm_medium=link" ); # Ok, Google uses a LOT of funky obfuscated javascript here # to tell the video status. But the thing is, if the last # request was successful, chances are the video uploaded # fine. Lets ignore the javascript, and just pull out the # docid for a link. if ($res->content =~ /success = \"(.+?)\"/) { my $str = $1; if ($str =~ /docid(.+?)\&/) { my $docid = $1; $docid =~ s/\\u003d//g; print ("LINK: http://video.google.com/videoplay?docid=$docid\n"); } else { die("ERROR: Cannot get docid\n"); } } else { die("ERROR: Cannot get link\n"); } # Load our configfile sub loadconf { open(C, "$_[0]") or die("ERROR: Could not open $_[0] for read: $!\n"); while() { chomp; chomp; my ($key, $value) = split(/\:/, $_, 2); $value =~ s/^\s+//g; # Trim any leading whitespace $conf{$key} = $value; } close(C); }