updated git and svn scripts
[xrzperl.git] / qq.qzone.photo
blob55a3ac74fb906b4b056cf4222aa9346032ba1f65
1 #!/usr/bin/perl -w
2 use strict;
3 use utf8;
4 use Encode;
7 die("Usage:$0 ID [name]\n") unless(@ARGV);
9 my $gb = find_encoding("gb2312");
11 sub get_list {
12 my $url = shift;
13 open FI,"-|", "httpget.pl","$url" or return undef;
14 my $code="";
15 while(<FI>) {
16 $_ =~ s/^\s*_Callback\s*\(//;
17 $_ =~ s/^\s*\);/;/;
18 $_ =~ s/\s+:\s+/=>/g;
19 $code = $code . $_;
21 close FI;
22 $code = $gb->decode($code);
23 return eval($code);
27 sub get_album_list {
28 my $uin = shift;
29 open FI,"-|", "httpget.pl","http://alist.photo.qq.com/fcgi-bin/fcg_list_album?uin=$uin&outstyle=2" or return undef;
30 # open FI,"-|", "httpget.pl","http://xalist.photo.qq.com/fcgi-bin/fcg_list_album?uin=$uin&outstyle=2" or return undef;
31 my $code="";
32 while(<FI>) {
33 $_ =~ s/^\s*_Callback\s*\(//;
34 $_ =~ s/^\s*\);/;/;
35 $_ =~ s/\s+:\s+/=>/g;
36 $code = $code . $_;
38 close FI;
39 $code = $gb->decode($code);
40 return eval($code);
43 sub get_photo_list {
44 my $uin = shift;
45 my $id = shift;
46 open FI,"-|","httpget.pl","http://plist.photo.qq.com/fcgi-bin/fcg_list_photo?uin=$uin&albumid=$id&outstyle=2" or return undef;
47 #open FI,"-|","httpget.pl","http://xaplist.photo.qq.com/fcgi-bin/fcg_list_photo?uin=$uin&albumid=$id&outstyle=2" or return undef;
48 my $code="";
49 while(<FI>) {
50 $_ =~ s/^\s*_Callback\s*\(//;
51 $_ =~ s/^\s*\);\s*$/;/;
52 $_ =~ s/\s+:\s+/=>/g;
53 $code = $code . $_;
55 close FI;
56 $code = $gb->decode($code);
57 return eval($code);
59 #Photo List:
61 my $uin = shift;
62 my $name = shift;
63 $name = $uin unless($name);
65 my %url_map = (
66 "http://alist.photo.qq.com/fcgi-bin/fcg_list_album?uin=###UIN###&outstyle=2" =>
67 "http://plist.photo.qq.com/fcgi-bin/fcg_list_photo?uin=###UIN###&albumid=###ALBUMID###&outstyle=2",
68 "http://xalist.photo.qq.com/fcgi-bin/fcg_list_album?uin=###UIN###&outstyle=2" =>
69 "http://xaplist.photo.qq.com/fcgi-bin/fcg_list_photo?uin=###UIN###&albumid=###ALBUMID###&outstyle=2",
72 my $good_url;
73 foreach my $album_exp (keys %url_map) {
74 my $album_url = $album_exp;
75 $album_url =~ s/###UIN###/$uin/;
76 my $list_ref = get_list($album_url);
77 next unless($list_ref and ref $list_ref);
78 my $albums = $list_ref->{"album"};
79 next unless($albums and ref $albums);
80 print STDERR "For $name, Get " . scalar(@{$albums}) . " albums.\n";
81 $good_url=1;
82 mkdir $name unless(-d $name);
83 chdir $name or die("$!\n");
84 foreach my $album (@{$albums}) {
85 my $album_name = $album->{"name"};
86 $album_name =~ s/^[\s ]+//;
87 $album_name =~ s/[\s ]+$//;
88 $album_name = "_noname" unless($album_name);
89 mkdir $album_name unless(-d $album_name);
90 chdir $album_name or die("$!\n");
91 print STDERR "Downloading [$album_name] ...\n";
92 my $photo_url = $url_map{$album_exp};
93 $photo_url =~ s/###UIN###/$uin/;
94 $photo_url =~ s/###ALBUMID###/$album->{id}/;
95 my $photo_list_ref = get_list($photo_url);
96 next unless($photo_list_ref and ref $photo_list_ref);
97 my $photos = $photo_list_ref->{"pic"};
98 next unless($photos and ref $photos);
99 print STDERR "Get " . scalar(@{$photos}) . " photos.\n";
100 foreach my $photo (@{$photos}) {
101 my $url = $photo->{"origin_url"};
102 my $filename = $photo->{"name"};
103 $filename =~ s/^[ \s]+//;
104 $filename =~ s/[\s ]+$//;
105 system("download","-u",$url,"-s",$filename . "_" . $photo->{"lloc2"} . ".jpg");
107 chdir "..";
109 chdir "..";
110 last if($good_url);
113 print "Can't get any photos\n" unless($good_url);