updated git and svn scripts
[xrzperl.git] / photo.blog.163.com
blob43e9ac4f4c02247f4989e5e5164ea2f83cc9d9ee
1 #!/usr/bin/perl -w
2 # $Id$
3 use strict;
4 require v5.10.0;
5 our $VERSION = 'v0.1';
7 BEGIN
9     my $PROGRAM_DIR = $0;
10     $PROGRAM_DIR =~ s/[^\/\\]+$//;
11     $PROGRAM_DIR = "./" unless($PROGRAM_DIR);
12     unshift @INC, 
13         map "$PROGRAM_DIR$_",qw{modules lib ../modules ..lib};
16 my %OPTS;
17 my @OPTIONS = qw/help|h|? version|ver edit-me manual|man/;
19 if(@ARGV)
21     require Getopt::Long;
22     require MyPlace::Usage;
23     Getopt::Long::GetOptions(\%OPTS,@OPTIONS);
24     MyPlace::Usage::Process(\%OPTS,$VERSION);
26 else
28     require MyPlace::Usage;
29     MyPlace::Usage::PrintHelp();
32 use Encode;
33 my $_UTF8 = find_encoding('utf8');
34 binmode STDOUT,'utf8';
35 binmode STDERR,'utf8';
36 my $USERNAME = shift;
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);
48 #my $albums_url;
49 #if($result =~ m/cacheFileUrl:"([^"]+)"/) {
50 #    $albums_url = 'http://' . $1;
52 #else {
53 #    print STDERR $result,"\n";
54 #    exit 1;
57 #use Data::Dumper;
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) {
61 #        $html_data = $1;
62 #        $html_data =~ s/:/=>/g;
63 #        $html_data =~ s/true/"true"/g;
64 #        my $r = eval($html_data);
65 #        if($@) {
66 #            print STDERR $@,"\n";
67 #            return undef;
68 #        }
69 #        elsif((!$r) or (!@{$r})) {
70 #            return undef;
71 #        }
72 #        return $r;
73 #    }
74 #    else {
75 #        return undef;
76 #    }
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();
85 if(!$albums) {
86 #    print STDERR $albums_data,"\n";
87     print STDERR ("Couldn't get albums data!\n");
88     exit 1;
91 print STDERR "Get ",scalar(@{$albums})," album(s).\n";
92 if(@QUERYS) {
93     my @new_albums;
94     foreach my $id_or_name (@QUERYS) {
95         foreach(@{$albums}) {
96             if($id_or_name eq $_->{name}) {
97                 push @new_albums,$_;
98             }
99             elsif($id_or_name eq $_->{id}) {
100                 push @new_albums,$_;
101             }
102         }
103     }
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;
118 #    }
119 #    elsif($picture->{ourl} =~ m/^(\d*)\/(.+)$/o) {
120 #            return $1 ? $pic_host_1 . $1 . $pic_host_2 . $2 : $pic_host . $2;
121 #    }
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);
130     if($pictures) {
131         print "#BATCHGET:chdir:",$album->{name},"\n";
132         foreach my $picture (@{$pictures}) {
133             print $picture->{url},"\n";
134 #            print convert_pic_url($picture),"\n";
135         }
136     }
137     else {
138         print STDERR "Couldn't get pictures of [",$album->{name},"]\n";
139     }
140     sleep 2;
141 #    print STDERR $pictures_data,"\n";
144 __END__
146 =pod
148 =head1  NAME
150 photo.blog.163.com - PERL script
152 =head1  SYNOPSIS
154 photo.blog.163.com username [album_id|album_name]...
156 =head1  OPTIONS
158 =over 12
160 =item B<--version>
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
172 =item B<--edit-me>
174 Invoke 'editor' against the source
176 =back
178 =head1  DESCRIPTION
180 ___DESC___
182 =head1  CHANGELOG
184     2010-08-18  xiaoranzzz  <xiaoranzzz@myplace.hell>
185         
186         * file created.
188 =head1  AUTHOR
190 xiaoranzzz <xiaoranzzz@myplace.hell>
192 =cut
194 #       vim:filetype=perl