10 $PROGRAM_DIR =~ s/[^\/\\]+$//;
11 $PROGRAM_DIR = "./" unless($PROGRAM_DIR);
13 map "$PROGRAM_DIR$_",qw{modules lib ../modules ..lib};
17 my @OPTIONS = qw/help|h|? version|ver edit-me manual|man/;
22 require MyPlace::Usage;
23 Getopt::Long::GetOptions(\%OPTS,@OPTIONS);
24 MyPlace::Usage::Process(\%OPTS,$VERSION);
28 require MyPlace::Usage;
29 MyPlace::Usage::PrintHelp();
33 my $_UTF8 = find_encoding('utf8');
34 binmode STDOUT,'utf8';
35 binmode STDERR,'utf8';
37 my @QUERYS = map {$_UTF8->decode($_)} @ARGV;
39 #use MyPlace::HTTPGet;
40 #my $api_url = 'http://photo.163.com/photo/' . $USERNAME . '/dwr/call/plaincall/UserSpaceBean.getUserSpace.dwr?';
41 #my $sess_id = 100+int(rand(1)*100+1);
42 #my $batch_id = 577000 + int(rand(1)*1000+1);
43 #my $request = $api_url . "callCount=1&scriptSessionId=\${scriptSessionId}$sess_id&c0-scriptName=UserSpaceBean&c0-methodName=getUserSpace&c0-id=0&c0-param0=string:$USERNAME&batchId=$batch_id";
45 #my $HTTP = MyPlace::HTTPGet->new();
46 #my (undef,$result) = $HTTP->get($request);
49 #if($result =~ m/cacheFileUrl:"([^"]+)"/) {
50 # $albums_url = 'http://' . $1;
53 # print STDERR $result,"\n";
58 #sub convert_from_html {
59 # my $html_data = shift;
60 # if($html_data =~ m/var\s+g_[pa]\$\d+d\s*=\s*(\[\{.+\}\])\s*;/s) {
62 # $html_data =~ s/:/=>/g;
63 # $html_data =~ s/true/"true"/g;
64 # my $r = eval($html_data);
66 # print STDERR $@,"\n";
69 # elsif((!$r) or (!@{$r})) {
79 #my (undef,$albums_data) = $HTTP->get($albums_url,'charset:gbk');
80 #my $albums = convert_from_html($albums_data);
81 use MyPlace::163::Blog;
82 my $blog = MyPlace::163::Blog->new($USERNAME);
83 my $albums = $blog->get_albums();
86 # print STDERR $albums_data,"\n";
87 print STDERR ("Couldn't get albums data!\n");
91 print STDERR "Get ",scalar(@{$albums})," album(s).\n";
94 foreach my $id_or_name (@QUERYS) {
96 if($id_or_name eq $_->{name}) {
99 elsif($id_or_name eq $_->{id}) {
104 $albums = \@new_albums;
105 print STDERR "Download ",scalar(@new_albums), " album(s) from all.\n";
107 #my $pic_host = 'http://img.ph.126.net/';
108 #my $pic_host_1 = 'http://img';
109 #my $pic_host_2 = '.ph.126.net/';
110 #my $blog_host = 'http://img.bimg.126.net/photo/';
111 #my $blog_host_1 = 'http://img';
112 #my $blog_host_2 = '.bimg.126.net/photo/';
114 #sub convert_pic_url {
115 # my $picture = shift;
116 # if($picture->{ourl} =~ m/^(\d*)\/photo\/(.+)$/o) {
117 # return $1 ? $blog_host_1 . $1 . $blog_host_2 . $2 : $blog_host . $2;
119 # elsif($picture->{ourl} =~ m/^(\d*)\/(.+)$/o) {
120 # return $1 ? $pic_host_1 . $1 . $pic_host_2 . $2 : $pic_host . $2;
124 foreach my $album (@{$albums}) {
125 print STDERR $album->{name},":",$album->{desc},"\n",'http://' . $album->{purl},"\n";
126 # my (undef,$pictures_data) = $HTTP->get('http://' . $album->{purl},'charset:gbk');
127 # my $pictures = convert_from_html($pictures_data);
128 # print STDERR Dumper($pictures),"\n";
129 my $pictures = $blog->get_pictures($album);
131 print "#BATCHGET:chdir:",$album->{name},"\n";
132 foreach my $picture (@{$pictures}) {
133 print $picture->{url},"\n";
134 # print convert_pic_url($picture),"\n";
138 print STDERR "Couldn't get pictures of [",$album->{name},"]\n";
141 # print STDERR $pictures_data,"\n";
150 photo.blog.163.com - PERL script
154 photo.blog.163.com username [album_id|album_name]...
162 Print version infomation.
164 =item B<-h>,B<--help>
166 Print a brief help message and exits.
168 =item B<--manual>,B<--man>
170 View application manual
174 Invoke 'editor' against the source
184 2010-08-18 xiaoranzzz <xiaoranzzz@myplace.hell>
190 xiaoranzzz <xiaoranzzz@myplace.hell>