You're viewing a comment by lizard and its responses.
You're viewing a comment by lizard and its responses.
I am being sponsored by Syntress! They bought me an amazing dedicated server to run catonmat on. If you're looking web services, I highly recommend the Syntress guys!
I am being sponsored by A-Writer! If you ever need help with essay writing, look no further than A-Writer! They will help you with your writing in as quickly as 3 hours!
I love to read science books. They make my day and I get ideas for awesome blog posts, such as Busy Beaver, On Functors, Recursive Regular Expressions and many others.
Take a look at my
Amazon wish list, if you're curious about what I have planned reading next, and want to surprise me. :)
If you are interested in advertising on catonmat.net, contact me.
Free tools for coding on Vietstarsoft.com.
Programming homework help.


ok, was bored. here is a diff with non localized logincheck, fix for big files and an dirty-progress counter ;)
--- ytup.perl 2009-12-05 08:40:50.000000000 +0100 +++ ytup.pl 2010-01-18 21:40:52.000000000 +0100 @@ -8,6 +8,7 @@ # Peteris Krumins (peter@catonmat.net) # http://www.catonmat.net -- good coders code, great reuse # +$|=1; use constant VERSION => "1.3"; @@ -15,7 +16,10 @@ use warnings; use LWP::UserAgent; +use HTTP::Request::Common qw(POST); +$HTTP::Request::Common::DYNAMIC_FILE_UPLOAD++; use HTML::Entities 'decode_entities'; + use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 1; @@ -182,9 +186,9 @@ login(); print "Uploading the video ($opts{t})...\n"; -upload(); +my $video_id = upload(); -print "Done!\n"; +print "Done! http://www.youtube.com/watch?v=$video_id\n"; sub login { # go to login page to get redirected to google sign in page @@ -243,7 +247,7 @@ # I found that when you have logged in the upper right menu changes # and you have access to 'Sign Out' option. # We check for this string to see if we have logged in. - unless ($res->content =~ />Sign Out</) { + unless ($res->content =~ /<form name="logoutForm"/) { die "Failed logging in: username/password incorrect"; } } @@ -304,12 +308,31 @@ } # now lets post the video - $resp = $ua->post($file_upload_url, + my $starttime = time(); + my $size = -s $opts{f}; + print "\n"; + my $req = POST($file_upload_url, { Filedata => [ $opts{f} ] }, "Content_Type" => "form-data" ); + + + # wrap content generator sub + my $gen = $req->content; + die unless ref($gen) eq "CODE"; + my $total = 0; + + $req->content(sub { + my $chunk = &$gen(); + $total += length($chunk); + print "\r$total / $size bytes (".int($total/$size*100)."%) sent, ".int($total/1000/(time()-$starttime+1)) . " k / sec "; + return $chunk; + }); + + $resp = $ua->request($req); + print "\n"; unless ($resp->is_success) { die "Failed uploading the file: ", $resp->status_line; @@ -345,6 +368,8 @@ if ($resp->content =~ /"errors":\s*\[(.+?)\]/) { die "The video uploaded OK, but there were errors setting the video info:\n", $1; } + + return $video_id; } sub prepare_upload_urls {Reply To This Comment