#!/usr/bin/perl use HTTP::Request::Common; use LWP::UserAgent; use strict; my (%conf, $ua, $res, $challenge, $u, $crumb); 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 login page $res = $ua->request(GET "https://login.yahoo.com/config/login?.done=http%3A%2F%2Fvideo.yahoo.com%2F%3Fei%3DUTF-8%26debug%3DStrings%26.scrumb%3D0&.src=vsu&.intl=us"); die("ERROR: GET login.yahoo.com") unless ($res->is_success); # Parse some values out of the login page. They are tricky. $challenge = $1 if ($res->content =~ /\.challenge\" value=\"(.+?)\"/); $u = $1 if ($res->content =~ /\.u\" value=\"(.+?)\"/); die("ERROR: No challenge\n") unless $challenge; die("ERROR: No U\n") unless $u; # Now we login with our user/pass, challenge and u (what is u anyway?) # Whew their login process is verbose. That "chkP" var makes me wonder.. # if it were set to N would it let me login to any account without # a password? Yikes. $res = $ua->request( POST "https://login.yahoo.com/config/login?", Referer => "https://login.yahoo.com/config/login?.done=http%3A%2F%2Fvideo.yahoo.com%2F%3Fei%3DUTF-8%26debug%3DStrings%26.scrumb%3D0&.src=vsu&.intl=us", Content_Type => "application/x-www-form-urlencoded", Content => [ '.tries' => "1", '.src' => "", '.md5' => "", '.hash' => "", '.js' => "", '.last' => "", 'promo' => "", '.intl' => "us", '.bypass' => "", '.partner' => "", '.u' => $u, '.v' => "0", '.challenge' => $challenge, '.yplus' => "", '.emailCode' => "", 'pkg' => "", 'stepid' => "", '.ev' => "", 'hasMsgr' => "0", 'chkP' => "Y", '.done' => "http://video.yahoo.com/", '.pd' => "vsu_ver%253d0", 'login' => $conf{'Username'}, 'passwd' => $conf{'Password'}, '.save' => "Sign+In" ] ); die("ERROR: Login Failed\n") unless ($res->content =~ /redirecting to a new URL/); # At this point we are logged in. # Get some info from the upload page (Crumb) # Wow yahoo likes validating every step.. but # they are much easier to trick than AOL $res = $ua->request( GET "http://video.yahoo.com/video/upload", Referer => "http://video.yahoo.com/" ); $crumb = $1 if ($res->content =~ /crumb value=\"(.+?)\"/); die("ERROR: No crumb\n") unless ($crumb); undef($u); $u = $1 if ($res->content =~ /upload_time value=\"(\d+)\"/); die("ERROR: No upload_time\n") unless $u; # And now the upload $res = $ua->request( POST "http://upload.video.yahoo.com/upload/submit.php", Referer => "http://video.yahoo.com/video/upload", Content_Type => "multipart/form-data", Content => [ '_crumb' => $crumb, '_done' => "http://video.yahoo.com/video/studio", '_error' => "http://video.yahoo.com/video/upload", 'cat_count' => "11", 'upload_time' => $u, 'MAX_FILE_SIZE' => "104857600", 'terms' => "yes", 'site_intl' => "us", 'intl' => "us", 'userfile' => [ $conf{'File'} ], 'title' => $conf{'Title'}, 'desc' => $conf{'Descr'}, 'tags' => $conf{'Tags'}, 'cat_[9]' => "nonadult/travel" ]); die("ERROR: Upload Failed!\n") unless ($res->is_redirect()); $res = $ua->request( GET $res->header("Location"), Referer => "http://upload.video.yahoo.com/upload/submit.php", ); die("ERROR: Upload Failed!\n") unless ($res->content =~ /thank you for submitting/); print $res->content; # CRAP! Yahoo gives you the link only AFTER it's done processing # This means I need a second script and a database to match titles/times -> links # Uncool. # 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); }