You're replying to a comment by Vially.

Vially Permalink
July 06, 2009, 00:43

I am working on creating the same script for other sites (DailyMotion, MySpace, Metacafe, etc) but I got stuck on the DailyMotion script.
I've tried creating this script also in Java and I get the exactly same error (Error 500: Connection reset).

Here is the perl version of the dailymotion upload script. I've tried to figure out for more than 12 hours what is the problem but I couldn't figure out.
Any help would be highly appreaciated.


use strict;
use warnings;
use LWP::UserAgent;
use Getopt::Std;
use Net::SSLeay;
use Data::Dumper;
use HTML::Entities;


# various urls
my $login_url  = '';
my $upload_url = '';

# create the user agent, have it store cookies and
# pretend to be an even cooler Linux firefox browser
my $ua = LWP::UserAgent->new(
	cookie_jar => {},
	agent => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20070802 SeaMonkey/1.1.4'

# let the user agent follow redirects after a POST request
push @{$ua->requests_redirectable}, 'POST';

print "Logging in to DailyMotion…\n";

print "Uploading the video…\n";

print "Done!\n";

sub login {
    # submit the login form
    my $res = $ua->post($login_url,
            username     => "dmtesting",
            password    => "dmtesting",
            login_submit  => "Login",
            form_name => "dm_pageitem_login"
    unless ($res->is_success){
        die "Failed logging in: failed submitting login form: ",

    # We have no good way to check if we really logged in.
    # I found that when you have logged in the upper right menu changes
    # and you have access to ‘Log Out’ option.
    # We check for this string to see if we have logged in.
    unless ($res->content =~ /logout/){
        die $res->content;
        die "Failed logging in: username/password incorrect";

sub upload {
    # upload is actually a two step process, first we set the video info,
    # and then we post the actual video file

    my $resp = $ua->get($upload_url);
    unless ($resp->is_success) {
        die "Failed getting $upload_url: ", $resp->status_line;

    my $form_action = extract_form_action($resp->content);
    unless (defined $form_action) {
        die "Failed extracting form action, DailyMotion might have redesigned!";

    #print $form_action;

    # let’s prepare the video field hash which we will need in both steps
    my %vid_fields = (
        file    => [ "testmovie.avi" ],
        send    => "Upload"

    $resp = upload_step_one(\%vid_fields, $form_action);

sub extract_form_action {
    my $content = shift;

    if ($content =~ m{}) {
        return $1;


sub upload_step_one {
    my ($vid_fields, $action_url) = @_;

    my $resp = $ua->post($action_url, $vid_fields,
        "Content_Type" => "form-data");

    unless ($resp->is_success) {
        die "First upload step failed: ", $resp->status_line;

    return $resp;

PS: I'll post all the upload scripts here after I'll finish with them.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "lcd_15": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.