| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::GData::ClientLogin; |
|
2
|
4
|
|
|
4
|
|
209810
|
use WebService::GData 'private'; |
|
|
4
|
|
|
|
|
13
|
|
|
|
4
|
|
|
|
|
19
|
|
|
3
|
4
|
|
|
4
|
|
22
|
use base 'WebService::GData'; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
462
|
|
|
4
|
4
|
|
|
4
|
|
2628
|
use WebService::GData::Error; |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
35
|
|
|
5
|
4
|
|
|
4
|
|
2565
|
use WebService::GData::Constants; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
212
|
|
|
6
|
4
|
|
|
4
|
|
2535
|
use LWP; |
|
|
4
|
|
|
|
|
58908
|
|
|
|
4
|
|
|
|
|
4461
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 0.01_06; |
|
10
|
|
|
|
|
|
|
our $CLIENT_LOGIN_URI = WebService::GData::Constants::CLIENT_LOGIN_URL; |
|
11
|
|
|
|
|
|
|
our $CAPTCHA_URL = WebService::GData::Constants::CAPTCHA_URL; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
WebService::GData::install_in_package( |
|
14
|
|
|
|
|
|
|
[qw(type password service source captcha_token captcha_answer email key)], |
|
15
|
|
|
|
|
|
|
sub { |
|
16
|
|
|
|
|
|
|
my $subname = shift; |
|
17
|
|
|
|
|
|
|
return sub { |
|
18
|
43
|
|
|
43
|
|
835
|
my $this = shift; |
|
|
|
|
|
43
|
|
|
|
|
19
|
43
|
|
|
|
|
228
|
$this->{$subname} |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub __init { |
|
25
|
4
|
|
|
4
|
|
20
|
my ( $this, %params ) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
4
|
|
|
|
|
145
|
$this->{email} = $params{email}; |
|
28
|
4
|
|
|
|
|
11
|
$this->{password} = $params{password}; |
|
29
|
|
|
|
|
|
|
|
|
30
|
4
|
100
|
66
|
|
|
34
|
die new WebService::GData::Error( 'invalid_parameters', |
|
31
|
|
|
|
|
|
|
'Password and Email are required to log in.' ) |
|
32
|
|
|
|
|
|
|
if ( !$params{password} || !$params{email} ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
3
|
|
100
|
|
|
21
|
$this->{service} = $params{service} |
|
35
|
|
|
|
|
|
|
|| WebService::GData::Constants::YOUTUBE_SERVICE; |
|
36
|
|
|
|
|
|
|
|
|
37
|
3
|
|
100
|
|
|
16
|
$this->{type} = $params{type} || 'HOSTED_OR_GOOGLE'; |
|
38
|
|
|
|
|
|
|
|
|
39
|
3
|
100
|
|
|
|
39
|
$this->{source} = |
|
40
|
|
|
|
|
|
|
( defined $params{source} ) |
|
41
|
|
|
|
|
|
|
? $params{source} |
|
42
|
|
|
|
|
|
|
: __PACKAGE__ . '-' . $VERSION; |
|
43
|
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
7
|
$this->{captcha_token} = $params{captcha_token}; |
|
45
|
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
7
|
$this->{captcha_answer} = $params{captcha_answer}; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#youtube related? |
|
49
|
3
|
|
|
|
|
9
|
$this->{key} = $params{key}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
3
|
|
|
|
|
14
|
$this->{ua} = $this->_create_ua(); |
|
52
|
|
|
|
|
|
|
|
|
53
|
3
|
|
|
|
|
14
|
return $this->_clientLogin(); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub captcha_url { |
|
57
|
2
|
|
|
2
|
1
|
7
|
my $this = shift; |
|
58
|
2
|
50
|
|
|
|
11
|
if ( $this->{captcha_url} ) { |
|
59
|
0
|
|
|
|
|
0
|
return $CAPTCHA_URL . $this->{captcha_url}; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
2
|
|
|
|
|
11
|
return undef; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub authorization_key { |
|
65
|
3
|
|
|
3
|
1
|
55
|
my $this = shift; |
|
66
|
3
|
|
|
|
|
30
|
return $this->{Auth}; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#for developer only |
|
70
|
|
|
|
|
|
|
sub set_authorization_headers { |
|
71
|
1
|
|
|
1
|
0
|
3
|
my ( $this, $subject, $req ) = @_; |
|
72
|
1
|
|
|
|
|
5
|
$req->header( |
|
73
|
|
|
|
|
|
|
'Authorization' => 'GoogleLogin auth=' . $this->authorization_key ); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#youtube |
|
77
|
|
|
|
|
|
|
sub set_service_headers { |
|
78
|
1
|
|
|
1
|
0
|
3
|
my ( $this, $subject, $req ) = @_; |
|
79
|
1
|
50
|
|
|
|
5
|
$req->header( 'X-GData-Key' => 'key=' . $this->key ) if defined $this->key; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#private |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
private _create_ua => sub { |
|
85
|
|
|
|
|
|
|
my $this = shift; |
|
86
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
|
87
|
|
|
|
|
|
|
$ua->agent( $this->source ); |
|
88
|
|
|
|
|
|
|
return $ua; |
|
89
|
|
|
|
|
|
|
}; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
private _post => sub { |
|
92
|
|
|
|
|
|
|
my ( $this, $uri, $content ) = @_; |
|
93
|
|
|
|
|
|
|
my $req = HTTP::Request->new( POST => $uri ); |
|
94
|
|
|
|
|
|
|
$req->content_type('application/x-www-form-urlencoded'); |
|
95
|
|
|
|
|
|
|
$req->content($content); |
|
96
|
|
|
|
|
|
|
my $res = $this->{ua}->request($req); |
|
97
|
|
|
|
|
|
|
if ( $res->is_success |
|
98
|
|
|
|
|
|
|
|| ( $res->code == 403 && $res->content() =~ m/CaptchaRequired/ ) ) |
|
99
|
|
|
|
|
|
|
{ |
|
100
|
|
|
|
|
|
|
return $res->content(); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
else { |
|
103
|
|
|
|
|
|
|
if ( $res->code == 500 |
|
104
|
|
|
|
|
|
|
&& $res->content() =~ m/www.google.com:443 \(Invalid argument\)/ ) |
|
105
|
|
|
|
|
|
|
{ |
|
106
|
|
|
|
|
|
|
die new WebService::GData::Error( 'missing_ssl_module', |
|
107
|
|
|
|
|
|
|
'Crypt::SSLeay must be installed in order to use ssl.' ); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
my $error = _parse_response( 'Error', $res->content ); |
|
110
|
|
|
|
|
|
|
die new WebService::GData::Error( $error, $res->content ); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
}; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
private _parse_response => sub { |
|
115
|
|
|
|
|
|
|
my ( $key, $content ) = @_; |
|
116
|
|
|
|
|
|
|
return ( split( /$key\s*=(.+?)\s{1}/m, $content ) )[1]; |
|
117
|
|
|
|
|
|
|
}; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
private _clientLogin => sub { |
|
120
|
|
|
|
|
|
|
my $this = shift; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $content = 'Email=' . _urlencode( $this->email ); |
|
123
|
|
|
|
|
|
|
$content .= '&Passwd=' . _urlencode( $this->password ); |
|
124
|
|
|
|
|
|
|
$content .= '&service=' . $this->service; |
|
125
|
|
|
|
|
|
|
$content .= '&source=' . _urlencode( $this->source ); |
|
126
|
|
|
|
|
|
|
$content .= '&accountType=' . $this->type; |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
#when failed the first time, add the captcha |
|
129
|
|
|
|
|
|
|
$content .= '&logintoken=' . $this->captcha_token |
|
130
|
|
|
|
|
|
|
if ( $this->captcha_token ); |
|
131
|
|
|
|
|
|
|
$content .= '&logincaptcha=' . $this->captcha_answer |
|
132
|
|
|
|
|
|
|
if ( $this->captcha_answer ); |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$this->{content} = $content; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $ret = $this->_post( $CLIENT_LOGIN_URI, $content ); |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$this->{Auth} = _parse_response( 'Auth', $ret ); |
|
139
|
|
|
|
|
|
|
$this->{captcha_token} = _parse_response( 'CaptchaToken', $ret ); |
|
140
|
|
|
|
|
|
|
$this->{captcha_url} = _parse_response( 'CaptchaUrl', $ret ); |
|
141
|
|
|
|
|
|
|
return $this; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
}; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
private _urlencode => sub { |
|
146
|
|
|
|
|
|
|
my ($string) = shift; |
|
147
|
|
|
|
|
|
|
$string =~ s/(\W)/"%" . unpack("H2", $1)/ge; |
|
148
|
|
|
|
|
|
|
return $string; |
|
149
|
|
|
|
|
|
|
}; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
"The earth is blue like an orange."; |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__ |