Changeset 233

Show
Ignore:
Timestamp:
03/02/06 10:35:05
Author:
miyagawa
Message:

CookieJar? support in Frepa.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/Frepa.pm

    r226 r233  
    1818sub load { 
    1919    my($self, $context) = @_; 
    20     $self->{frepa} = Plagger::Plugin::CustomFeed::Frepa::Mechanize->new($self->conf->{livedoor_id}, $self->conf->{password}); 
     20    $self->{frepa} = Plagger::Plugin::CustomFeed::Frepa::Mechanize->new($self); 
    2121 
    2222    my $feed = Plagger::Feed->new; 
     
    2828    my($self, $context, $args) = @_; 
    2929 
    30  
    3130    unless ($self->{frepa}->login) { 
    32         $context->log(error => "Login failed."); 
     31        $context->log(error => "Login to frepa failed."); 
    3332        return; 
    3433    } 
    3534 
    36     $context->log(info => 'Login to frepa succeed.'); 
     35    $context->log(info => 'Login to frepa succeeded.'); 
    3736 
    3837    my $feed = Plagger::Feed->new; 
     
    113112sub new { 
    114113    my $class = shift; 
     114    my $plugin = shift; 
     115 
     116    my $mech = WWW::Mechanize->new(cookie_jar => $plugin->cache->cookie_jar); 
     117    $mech->agent_alias( "Windows IE 6" ); 
    115118 
    116119    bless { 
    117         mecha       => WWW::Mechanize->new, 
    118         livedoor_id => shift, 
    119         password    => shift, 
    120  
    121         login_url => 'http://member.livedoor.com/login/?.next=http%3A%2F%2Ffrepa.livedoor.com&.sv=frepa&.nofrepa=1', 
     120        mecha       => $mech, 
     121        livedoor_id => $plugin->conf->{livedoor_id}, 
     122        password    => $plugin->conf->{password}, 
     123        start_url => 'http://www.frepa.livedoor.com/', 
    122124    }, $class; 
    123125} 
     
    126128    my $self = shift; 
    127129 
    128     my $res = $self->{mecha}->get($self->{login_url}); 
     130    my $res = $self->{mecha}->get($self->{start_url}); 
    129131    return 0 unless $self->{mecha}->success; 
    130132 
    131     $self->{mecha}->set_fields(livedoor_id => $self->{livedoor_id}, password => $self->{password}); 
    132     my $res = $self->{mecha}->submit; 
    133     return 0 unless $self->{mecha}->success; 
    134     return 0 if $self->{mecha}->content =~ /loginside/; 
     133    if ($self->{mecha}->content =~ /loginside/) { 
     134        Plagger->context->log(debug => "cookie not found. logging in"); 
     135        $self->{mecha}->submit_form( 
     136            fields => { 
     137                livedoor_id => $self->{livedoor_id}, 
     138                password    => $self->{password}, 
     139                auto_login  => 'on', 
     140            }, 
     141        ); 
     142        $self->{mecha}->submit; 
     143        return 0 unless $self->{mecha}->success; 
     144        return 0 if $self->{mecha}->content =~ /loginside/; 
     145    } 
    135146 
    136147    return 1;