Yoshihisa Fukuhara
higef****@users*****
2005年 8月 29日 (月) 19:41:04 JST
Index: affelio/apps/Mixi/extlib/WWW/Mixi.pm
diff -u affelio/apps/Mixi/extlib/WWW/Mixi.pm:1.3 affelio/apps/Mixi/extlib/WWW/Mixi.pm:1.4
--- affelio/apps/Mixi/extlib/WWW/Mixi.pm:1.3 Fri Jul 1 01:26:41 2005
+++ affelio/apps/Mixi/extlib/WWW/Mixi.pm Mon Aug 29 19:41:04 2005
@@ -4,7 +4,7 @@
use Carp ();
use vars qw($VERSION @ISA);
-$VERSION = 0.32;
+$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
require LWP::RobotUA;
@ISA = qw(LWP::RobotUA);
@@ -21,7 +21,7 @@
# オプションの処理
Carp::croak('WWW::Mixi mail address required') unless $email;
- Carp::croak('WWW::Mixi password required') unless $password;
+ # Carp::croak('WWW::Mixi password required') unless $password;
# オブジェクトの生成
my $name = "WWW::Mixi/" . $VERSION;
@@ -49,9 +49,11 @@
my $self = shift;
my $page = 'login.pl';
my $next = ($self->{'mixi'}->{'next_url'}) ? $self->{'mixi'}->{'next_url'} : '/home.pl';
+ my $password = (@_) ? shift : $self->{'mixi'}->{'password'};
+ return undef unless (defined($password) and length($password));
my %form = (
'email' => $self->{'mixi'}->{'email'},
- 'password' => $self->{'mixi'}->{'password'},
+ 'password' => $password,
'next_url' => $self->absolute_url($next),
);
$self->enable_cookies;
@@ -59,6 +61,7 @@
$self->log("[info] 再ログインします。\n") if ($self->session);
my $res = $self->post($page, %form);
$self->{'mixi'}->{'refresh'} = ($res->is_success and $res->headers->header('refresh') =~ /url=([^ ;]+)/) ? $self->absolute_url($1) : undef;
+ $self->{'mixi'}->{'password'} = $password if ($res->is_success);
return $res;
}
@@ -85,12 +88,22 @@
sub session {
my $self = shift;
+ if (@_) {
+ my $session = shift;
+ $self->enable_cookies;
+ $self->cookie_jar->set_cookie(undef, 'BF_SESSION', $session, '/', 'mixi.jp', undef, 1, undef, undef, 1);
+ }
return undef unless ($self->cookie_jar);
return ($self->cookie_jar->as_string =~ /\bSet-Cookie.*?:.*? BF_SESSION=(.*?);/) ? $1 : undef;
}
sub stamp {
my $self = shift;
+ if (@_) {
+ my $stamp = shift;
+ $self->enable_cookies;
+ $self->cookie_jar->set_cookie(undef, 'BF_STAMP', $stamp, '/', 'mixi.jp', undef, 1, undef, undef, 1);
+ }
return undef unless ($self->cookie_jar);
return ($self->cookie_jar->as_string =~ /\bSet-Cookie.*?:.*? BF_STAMP=(.*?);/) ? $1 : undef;
}
@@ -104,9 +117,17 @@
if ($res->is_success) {
# check contents existence
- if ($res->content and $res->content =~ /^(\Qデータはありません。\E)<html>/) {
+ if ($res->content and $res->content =~ /^\Qデータはありません。\E<html>/) {
$res->code(400);
$res->message('No Data');
+ # check rejcted by too frequent requests.
+ } elsif ($res->content and $res->content =~ /^\Q間隔を空けない連続的なページの遷移・更新を頻繁におこなわれている\E/) {
+ $res->code(503);
+ $res->message('Too frequently requests');
+ # check rejcted since content is closed.
+ } elsif ($res->content and $res->content =~ /^\Qアクセスできません\E<html>/) {
+ $res->code(403);
+ $res->message('Closed content');
# check login form existence
} elsif (my $message = $self->is_login_required($res)) {
$res->code(401);
@@ -362,21 +383,26 @@
my $base = $res->base->as_string;
my $content = $res->content;
my @items = ();
+ my $status_backgrounds = {
+ 'http://img.mixi.jp/img/bg_orange1-.gif' => '管理者',
+ };
if ($content =~ /<table BORDER=0 CELLSPACING=1 CELLPADDING=2 WIDTH=560>(.+?)<\/table>/s) {
$content = $1;
while ($content =~ s/<tr ALIGN=center BGCOLOR=#FFFFFF>(.*?)<tr ALIGN=center BGCOLOR=#FFF4E0>(.*?)<\/tr>//is) {
my ($image_part, $text_part) = ($1, $2);
- my @images = ($image_part =~ /<td WIDTH=20% HEIGHT=100 background=http:\/\/img.mixi.jp\/img\/bg_line.gif>(.*?)<\/td>/gi);
+ my @images = ($image_part =~ /<td WIDTH=20% HEIGHT=100 background=http:\/\/img.mixi.jp\/img\/bg_[a-z0-9-]+.gif>.*?<\/td>/gi);
my @texts = ($text_part =~ /<td>(.*?)<\/td>/gi);
for (my $i = 0; $i < @images or $i < @texts; $i++) {
my $item = {};
my ($image, $text) = ($images[$i], $texts[$i]);
($item->{'subject'}, $item->{'count'}) = ($1, $2) if ($text =~ /^\s*(.*?)\((\d+)\)\s*$/);
- ($item->{'link'}, $item->{'image'}) = ($1, $2) if ($image =~ /<a href=(.*?)><img SRC=(.*?) border=0><\/a>/);
+ ($item->{'background'}, $item->{'link'}, $item->{'image'}) = ($1, $2, $3) if ($image =~ /<td .*? background=([^<> ]*).*?><a href=(.*?)><img SRC=(.*?) border=0><\/a>/);
if ($item->{'link'}) {
- $item->{'subject'} = $self->rewrite($item->{'subject'});
- $item->{'link'} = $self->absolute_url($item->{'link'}, $base);
- $item->{'image'} = $self->absolute_url($item->{'image'}, $base);
+ $item->{'subject'} = $self->rewrite($item->{'subject'});
+ $item->{'link'} = $self->absolute_url($item->{'link'}, $base);
+ $item->{'image'} = $self->absolute_url($item->{'image'}, $base);
+ $item->{'background'} = $self->absolute_url($item->{'background'}, $base);
+ $item->{'status'} = $status_backgrounds->{$item->{'background'}};
push(@items, $item);
}
}
@@ -483,6 +509,22 @@
return $next;
}
+sub parse_list_diary_monthly_menu {
+ my $self = shift;
+ my $res = (@_) ? shift : $self->response();
+ return unless ($res and $res->is_success);
+ my $base = $res->base->as_string;
+ my $content = $res->content;
+ my @items = ();
+ if ($content =~ /<!-- start: monthly menu -->(.+)<!-- end: monthly menu -->/s) {
+ $content = $1;
+ while ($content =~ s/<a HREF=['"]?(list_diary.pl\?year=(\d+)\&month=(\d+))['"]?.*?>.*?<\/a>//is) {
+ push(@items, {'link' => $self->absolute_url($1, $base), 'year' => $2, 'month' => $3});
+ }
+ }
+ return @items;
+}
+
sub parse_list_friend {
my $self = shift;
my $res = (@_) ? shift : $self->response();
@@ -490,26 +532,30 @@
my $base = $res->base->as_string;
my $content = $res->content;
my @items = ();
- my %status_icons = (
- 'http://img.mixi.jp/img/new6.gif' => '日記 - new!!',
- );
+ my $status_backgrounds = {
+ 'http://img.mixi.jp/img/bg_orange1-.gif' => '1時間以内',
+ 'http://img.mixi.jp/img/bg_orange2-.gif' => '1日以内',
+ };
+ my @time1 = reverse((localtime(time - 3600))[0..5]);
+ my @time2 = reverse((localtime(time - 3600 * 24))[0..5]);
if ($content =~ /<table BORDER=0 CELLSPACING=1 CELLPADDING=2 WIDTH=560>(.+?)<\/table>/s) {
$content = $1 ;
while ($content =~ s/<tr ALIGN=center BGCOLOR=#FFFFFF>(.*?)<tr ALIGN=center BGCOLOR=#FFF4E0>(.*?)<\/tr>//is) {
my ($image_part, $text_part) = ($1, $2);
- my @images = ($image_part =~ /<td WIDTH=20% HEIGHT=100 background=http:\/\/img.mixi.jp\/img\/bg[\w\_\-]*.gif>(.*?)<\/td>/gi);
+ my @images = ($image_part =~ /<td WIDTH=20% HEIGHT=100 background=http:\/\/img.mixi.jp\/img\/bg_[a-z0-9-]+.gif>.*?<\/td>/gi);
my @texts = ($text_part =~ /<td>(.*?)<\/td>/gi);
for (my $i = 0; $i < @images or $i < @texts; $i++) {
my $item = {};
my ($image, $text) = ($images[$i], $texts[$i]);
($item->{'subject'}, $item->{'count'}) = ($1, $2) if ($text =~ /^\s*(.+?)\((\d+)\)/);
- ($item->{'link'}, $item->{'image'}) = ($1, $2) if ($image =~ /<a href=(.*?)><img SRC=(.*?) border=0><\/a>/);
- $item->{'status'} = $status_icons{$1} if ($text =~ /<img src=["']?([^\s'"<>]+)/);
+ ($item->{'background'}, $item->{'link'}, $item->{'image'}) = ($1, $2, $3) if ($image =~ /<td .*? background=([^<> ]*).*?><a href=(.*?)><img alt=(?:.*?) SRC=(.*?) border=0><\/a>/);
if ($item->{'link'}) {
- $item->{'subject'} = $self->rewrite($item->{'subject'});
- $item->{'link'} = $self->absolute_url($item->{'link'}, $base);
- $item->{'id'} = $2 if ($item->{'link'} =~ /(.*?)?id=(\d*)/);
- $item->{'image'} = $self->absolute_url($item->{'image'}, $base);
+ $item->{'subject'} = $self->rewrite($item->{'subject'});
+ $item->{'link'} = $self->absolute_url($item->{'link'}, $base);
+ $item->{'id'} = $2 if ($item->{'link'} =~ /(.*?)?id=(\d*)/);
+ $item->{'image'} = $self->absolute_url($item->{'image'}, $base);
+ $item->{'background'} = $self->absolute_url($item->{'background'}, $base);
+ $item->{'status'} = $status_backgrounds->{$item->{'background'}};
push(@items, $item);
}
}
@@ -524,7 +570,7 @@
return unless ($res and $res->is_success);
my $base = $res->base->as_string;
my $content = $res->content;
- return unless ($content =~ / <a href=([^<>]*?list_friend.pl\?page=.*?)>(.*?)<\/a>/);
+ return unless ($content =~ / <a href=([^<>]*?list_friend.pl\?[^<>\s]*page=[^<>\s]*)>((?:(?!<\/a>).)*)<\/a>/);
my $subject = $2;
my $link = $self->absolute_url($1, $base);
my $next = {'link' => $link, 'subject' => $2};
@@ -537,7 +583,7 @@
return unless ($res and $res->is_success);
my $base = $res->request->uri->as_string;
my $content = $res->content;
- return unless ($content =~ /<a href=([^<>]*?list_friend.pl\?page=.*?)>(.*?)<\/a> /);
+ return unless ($content =~ /<a href=([^<>\s]*list_friend.pl\?[^<>\s]*page=[^<>\s]*)>((?:(?!<\/a>).)*)<\/a> /);
my $subject = $2;
my $link = $self->absolute_url($1, $base);
my $previous = {'link' => $link, 'subject' => $2};
@@ -620,6 +666,16 @@
return $self->parse_standard_history(@_);
}
+sub parse_new_bbs_next {
+ my $self = shift;
+ return $self->parse_standard_history_next(@_);
+}
+
+sub parse_new_bbs_previous {
+ my $self = shift;
+ return $self->parse_standard_history_previous(@_);
+}
+
sub parse_new_comment {
my $self = shift;
return $self->parse_standard_history(@_);
@@ -694,28 +750,32 @@
sub parse_new_friend_diary_next {
my $self = shift;
- my $res = (@_) ? shift : $self->response();
- return unless ($res and $res->is_success);
- my $base = $res->base->as_string;
- my $content = $res->content;
- return unless ($content =~ /<td ALIGN=right BGCOLOR=#EED6B5>[^\r\n]*?<a href=["']?(.+?)['"]?>([^<>]+)<\/a><\/td><\/tr>/);
- my $subject = $2;
- my $link = $self->absolute_url($1, $base);
- my $next = {'link' => $link, 'subject' => $2};
- return $next;
+ return $self->parse_standard_history_next(@_);
+# my $self = shift;
+# my $res = (@_) ? shift : $self->response();
+# return unless ($res and $res->is_success);
+# my $base = $res->base->as_string;
+# my $content = $res->content;
+# # return unless ($content =~ /<td ALIGN=right BGCOLOR=#EED6B5>[^\r\n]*?<a href=["']?(.+?)['"]?>([^<>]+)<\/a><\/td><\/tr>/);
+# return unless ($content =~ /<td ALIGN=right BGCOLOR=#EED6B5>[^\r\n]*?<a href=["']?([^>]+?)['"]?>([^<>]+)<\/a><\/td><\/tr>/);
+# my $subject = $2;
+# my $link = $self->absolute_url($1, $base);
+# my $next = {'link' => $link, 'subject' => $2};
+# return $next;
}
sub parse_new_friend_diary_previous {
- my $self = shift;
- my $res = (@_) ? shift : $self->response();
- return unless ($res and $res->is_success);
- my $base = $res->request->uri->as_string;
- my $content = $res->content;
- return unless ($content =~ /<td ALIGN=right BGCOLOR=#EED6B5><a href=["']?(.+?)['"]?>([^<>]+)<\/a>[^\r\n]*?<\/td><\/tr>/);
- my $subject = $2;
- my $link = $self->absolute_url($1, $base);
- my $previous = {'link' => $link, 'subject' => $2};
- return $previous;
+ my $self = shift;
+ return $self->parse_standard_history_previous(@_);
+# my $res = (@_) ? shift : $self->response();
+# return unless ($res and $res->is_success);
+# my $base = $res->request->uri->as_string;
+# my $content = $res->content;
+# return unless ($content =~ /<td ALIGN=right BGCOLOR=#EED6B5><a href=["']?(.+?)['"]?>([^<>]+)<\/a>[^\r\n]*?<\/td><\/tr>/);
+# my $subject = $2;
+# my $link = $self->absolute_url($1, $base);
+# my $previous = {'link' => $link, 'subject' => $2};
+# return $previous;
}
sub parse_new_review {
@@ -729,7 +789,7 @@
return unless ($res and $res->is_success);
my $base = $res->base->as_string;
my $content = $res->content;
- my $self_id = ($content =~ /<form action="list_review.pl\?id=(\d+)" method=post>/) ? $1 : 0;
+ my $self_id = ($content =~ /\(URL は http:\/\/mixi.jp\/show_friend.pl\?id=(\d+) です。\)/) ? $1 : 0;
return $self_id;
}
@@ -1160,6 +1220,14 @@
return $self->parse_list_diary_previous();
}
+sub get_list_diary_monthly_menu {
+ my $self = shift;
+ my $url = 'list_diary.pl';
+ $url = shift if (@_ and $_[0] ne 'refresh');
+ $self->set_response($url, @_) or return;
+ return $self->parse_list_diary_monthly_menu();
+}
+
sub get_list_friend {
my $self = shift;
my $url = 'list_friend.pl';
@@ -1216,6 +1284,22 @@
return $self->parse_new_bbs();
}
+sub get_new_bbs_next {
+ my $self = shift;
+ my $url = 'new_bbs.pl';
+ $url = shift if (@_ and $_[0] ne 'refresh');
+ $self->set_response($url, @_) or return;
+ return $self->parse_new_bbs_next();
+}
+
+sub get_new_bbs_previous {
+ my $self = shift;
+ my $url = 'new_bbs.pl';
+ $url = shift if (@_ and $_[0] ne 'refresh');
+ $self->set_response($url, @_) or return;
+ return $self->parse_new_bbs_previous();
+}
+
sub get_new_comment {
my $self = shift;
my $url = 'new_comment.pl';
@@ -1303,7 +1387,7 @@
sub get_self_id {
my $self = shift;
- my $url = 'list_review.pl';
+ my $url = 'show_profile.pl';
$self->set_response($url, @_) or return;
return $self->parse_self_id();
}
@@ -1631,6 +1715,21 @@
return $str;
}
+sub remove_diary_tag {
+ my $self = shift;
+ my $str = shift;
+ my $re_diary_tag = join('|',
+ q{<a HREF="[^"]*" target="_blank">},
+ q{<a href="[^"]*" onClick="MM_openBrWindow\([^"]*\)">},
+ q{<img alt=写真 src=\S* border=0>},
+ q{<span (?:class|style)="[^"]*">},
+ q{<(?:blockquote|u|em|strong)>},
+ q{<\/(?:a|blockquote|u|em|span|strong)>}
+ );
+ $str =~ s/$re_diary_tag//g;
+ return $str;
+}
+
sub redirect_ok {
return 1;
}
@@ -1643,7 +1742,7 @@
my $content = $res->content;
my @items = ();
my $re_date = '(?:(\d{4})年)?(\d{2})月(\d{2})日 (\d{1,2}):(\d{2})';
- my $re_name = '\((.*?)\)';
+ my $re_name = '\(([^\r\n]*)\)';
my $re_link = '<a href="?(.+?)"?>(.+?)\s*<\/a>';
if ($content =~ /<table BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=630>(.+?)<\/table>/s) {
$content = $1;
@@ -1663,6 +1762,32 @@
return @items;
}
+sub parse_standard_history_next {
+ my $self = shift;
+ my $res = (@_) ? shift : $self->response();
+ return unless ($res and $res->is_success);
+ my $base = $res->base->as_string;
+ my $content = $res->content;
+ return unless ($content =~ /<td ALIGN=right BGCOLOR=#EED6B5>[^\r\n]*?<a href=["']?([^>]+?)['"]?>([^<>]+)<\/a><\/td><\/tr>/);
+ my $subject = $2;
+ my $link = $self->absolute_url($1, $base);
+ my $next = {'link' => $link, 'subject' => $2};
+ return $next;
+}
+
+sub parse_standard_history_previous {
+ my $self = shift;
+ my $res = (@_) ? shift : $self->response();
+ return unless ($res and $res->is_success);
+ my $base = $res->request->uri->as_string;
+ my $content = $res->content;
+ return unless ($content =~ /<td ALIGN=right BGCOLOR=#EED6B5><a href=["']?(.+?)['"]?>([^<>]+)<\/a>[^\r\n]*?<\/td><\/tr>/);
+ my $subject = $2;
+ my $link = $self->absolute_url($1, $base);
+ my $previous = {'link' => $link, 'subject' => $2};
+ return $previous;
+}
+
sub parse_standard_form {
my $self = shift;
my $res = (@_) ? shift : $self->response();
@@ -1781,9 +1906,9 @@
my $self = shift;
my %values = @_;
my $url = 'delete_diary.pl';
- my @fields = qw(submit id);
- my @required = qw(id);
- my %label = ('id' => '日記ID');
+ my @fields = qw(submit id post_key);
+ my @required = qw(id post_key);
+ my %label = ('id' => '日記ID', 'post_key' => '送信キー');
# データの生成とチェック
my %form = map {$_ => $values{$_}} @fields;
$form{'id'} = $values{'diary_id'} if (not $form{'id'} and defined($values{'diary_id'}));
@@ -1860,7 +1985,6 @@
$mixi->test_save_and_read_cookies; # Cookieの読み書き
# 終了
$mixi->log("終了しました。\n");
- $mixi->dumper_log($mixi->{'__test_record'});
exit 0;
}
@@ -2024,6 +2148,7 @@
'list_community' => 'コミュニティ一覧',
'list_diary' => '日記',
'list_diary_capacity' => '日記容量',
+ 'list_diary_monthly_menu' => '日記月別ページ',
'list_friend' => '友人・知人一覧',
'list_message' => '受信メッセージ',
'list_outbox' => '送信メッセージ',
@@ -2065,6 +2190,7 @@
'list_community' => 'コミュニティ一覧',
'list_diary' => '日記',
'list_friend' => '友人・知人一覧',
+ 'new_bbs' => 'コミュニティ最新書き込み',
'new_diary' => '新着日記検索',
'new_friend_diary' => 'マイミクシィ最新日記',
);
@@ -2213,7 +2339,7 @@
require WWW::RobotRules;
@ISA = qw(WWW::RobotRules::InCore);
-$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
sub allowed {
return 1;