cpsn 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/bin/cpsn +55 -32
  3. metadata +39 -18
  4. data/.gitignore +0 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.7.0
data/bin/cpsn CHANGED
@@ -3,7 +3,7 @@
3
3
  # cpsn - Query Friend status on the Playstation Network (tm)
4
4
  #
5
5
  # Author:: James Bowes <jbowes@repl.ca>
6
- # Copyright:: Copyright (C) 2009 James Bowes
6
+ # Copyright:: Copyright (C) 2009 - 2011 James Bowes
7
7
 
8
8
  require 'rubygems'
9
9
  require 'mechanize'
@@ -13,9 +13,8 @@ require 'optparse'
13
13
  require 'logger'
14
14
  require 'set'
15
15
 
16
- $login_url = "https://store.playstation.com/external/index.vm?returnURL=https%3a%2f%2fsecureus.playstation.com%2fRegistration%2fPSNL%2fSignInFrame.aspx"
17
- $friend_url = "http://profiles.us.playstation.com/playstation/psn/profile/friends"
18
- $json_url = "http://profiles.us.playstation.com/playstation/psn/profile/get_gamer_summary_data?id="
16
+ $login_url = "https://store.playstation.com/external/index.vm?returnURL=http://us.playstation.com/uwps/PSNTicketRetrievalGenericServlet"
17
+ $friend_url = "http://us.playstation.com/playstation/psn/profile/friends?id="
19
18
 
20
19
 
21
20
  class Cpsn
@@ -76,28 +75,51 @@ class Cpsn
76
75
  return groups
77
76
  end
78
77
 
78
+
79
+ def login_failed
80
+ puts "Error logging in. Did you give the right username and password?"
81
+ exit
82
+ end
83
+
84
+
79
85
  def get_cookie(username, password)
80
86
  @log.debug("Signing in for new cookie")
87
+
88
+ @agent.redirect_ok = false
81
89
  page = @agent.get($login_url)
82
90
  login_form = page.forms.first
83
- login_form.loginName = username
84
- login_form.password = password
91
+ login_form.j_username = username
92
+ login_form.j_password = password
85
93
  page = @agent.submit(login_form)
86
- link = page.links.first
94
+
95
+ if page.code != "302"
96
+ login_failed
97
+ end
87
98
 
88
- if link.text == "Sign In"
89
- puts "Error logging in. Did you give the right username and password?"
90
- exit
99
+ page = @agent.get(page.response['Location'])
100
+
101
+ if page.code != "302"
102
+ login_failed
91
103
  end
92
104
 
93
- page = link.click
94
-
105
+ # we don't need to follow this last redirect, just to get the sesison
106
+ # id
107
+ location = page.response['Location']
108
+ parts = location.split("sessionId=")
109
+ sessionId = parts[1]
110
+
111
+ # this sets the sessionid cookie and others, which we need.
112
+ @agent.get("http://us.playstation.com/uwps/HandleIFrameRequests?sessionId=" + sessionId)
113
+
95
114
  @agent.cookie_jar.save_as File.expand_path("~/.cpsn/cookies.yml")
115
+
116
+
117
+ @agent.redirect_ok = true
96
118
  end
97
119
 
98
120
  def get_agent(username, password, force_cookie)
99
121
  @log.debug("Creating new user agent")
100
- @agent = WWW::Mechanize.new
122
+ @agent = Mechanize.new
101
123
  @agent.user_agent_alias = 'Mac FireFox'
102
124
  @agent.redirect_ok = true
103
125
 
@@ -111,7 +133,7 @@ class Cpsn
111
133
  def get_friends()
112
134
  begin
113
135
  return _get_friends()
114
- rescue WWW::Mechanize::ResponseCodeError => response
136
+ rescue Mechanize::ResponseCodeError => response
115
137
  if response.response_code == '403'
116
138
  get_cookie(@settings[:username].value,
117
139
  @settings[:password].value)
@@ -125,7 +147,7 @@ class Cpsn
125
147
  def get_friend_status(friend)
126
148
  begin
127
149
  return _get_friend_status(friend)
128
- rescue WWW::Mechanize::ResponseCodeError => response
150
+ rescue Mechanize::ResponseCodeError => response
129
151
  if response.response_code == '403'
130
152
  get_cookie(@settings[:username].value,
131
153
  @settings[:password].value)
@@ -140,7 +162,12 @@ class Cpsn
140
162
 
141
163
  def _get_friends()
142
164
  @log.debug("Getting friends list")
143
- page = @agent.get($friend_url)
165
+ @agent.get( "http://us.playstation.com/myfriends/")
166
+ url = $friend_url + rand().to_s
167
+ page = @agent.get("http://us.playstation.com/uwps/decryptText?id=0.1234554")
168
+ @log.debug("friend url: " + url)
169
+ page = @agent.get(url, nil, "http://us.playstation.com/myfriends/")
170
+
144
171
  divs = page.search("div.slotcontent")
145
172
 
146
173
  friends = []
@@ -155,25 +182,21 @@ class Cpsn
155
182
 
156
183
  def _get_friend_status(friend)
157
184
  @log.debug("Loading friend status for #{friend}")
158
- page = @agent.get($json_url + friend)
159
- data = JSON.parse(page.body)
185
+ page = @agent.get("http://us.playstation.com/playstation/psn/profile/" + friend + "?id=0.12343", nil, "http://us.playstation.com/myfriends")
160
186
 
161
- @log.debug(data)
187
+ friend = {:name => friend,
188
+ :status => 'offline',
189
+ :playing => '',
190
+ }
162
191
 
163
- friend = {:name => data["userName"]}
192
+ status = page.search("div.oStatus")[0]
164
193
 
165
- if data["onlineStatus"] == nil
166
- return nil
167
- end
194
+ if status.search("div")[0].attributes['class'].to_s == "onlineStatus online"
195
+ friend[:status] = "online"
196
+
197
+ playing = page.search("span._iamplaying_")
198
+ friend[:playing] = playing[0].text.strip
168
199
 
169
- if data["onlineStatus"]["extensionStatus"] != nil
170
- friend[:status] = 'online'
171
- friend[:playing] = data["onlineStatus"]["extensionStatus"]["title"]
172
- friend[:game_status] = data["onlineStatus"]["extensionStatus"]["status"]
173
- else
174
- friend[:status] = 'offline'
175
- friend[:playing] = ""
176
- friend[:game_status] = ""
177
200
  end
178
201
 
179
202
  return friend
@@ -237,7 +260,7 @@ for friend_name in friend_names
237
260
 
238
261
  if friend
239
262
  if friend[:status] != "offline" or options[:offline]
240
- puts friend[:status] + "\t" + friend[:name] + "\t" + friend[:playing] + "\t" + friend[:game_status]
263
+ puts friend[:status] + "\t" + friend[:name] + "\t" + friend[:playing]
241
264
  end
242
265
  else
243
266
  puts "Error: no access to " + friend_name
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpsn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ hash: 3
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - James Bowes
@@ -9,29 +15,40 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-23 00:00:00 -05:00
13
- default_executable: cpsn
18
+ date: 2011-11-21 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: mechanize
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 61
29
+ segments:
30
+ - 0
31
+ - 9
32
+ - 3
23
33
  version: 0.9.3
24
- version:
34
+ type: :runtime
35
+ version_requirements: *id001
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: json
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
30
41
  requirements:
31
42
  - - ">="
32
43
  - !ruby/object:Gem::Version
44
+ hash: 29
45
+ segments:
46
+ - 1
47
+ - 1
48
+ - 7
33
49
  version: 1.1.7
34
- version:
50
+ type: :runtime
51
+ version_requirements: *id002
35
52
  description: "\n Query PSN friend status from the CLI. Shows useful information like the\n game being played, and what mode or map your friend is playing\n (if available).\n "
36
53
  email: jbowes@repl.ca
37
54
  executables:
@@ -41,37 +58,41 @@ extensions: []
41
58
  extra_rdoc_files: []
42
59
 
43
60
  files:
44
- - .gitignore
45
61
  - README.mkd
46
62
  - Rakefile
47
63
  - TODO
48
64
  - VERSION
49
65
  - bin/cpsn
50
- has_rdoc: true
51
66
  homepage: http://github.com/jbowes/cpsn
52
67
  licenses: []
53
68
 
54
69
  post_install_message:
55
- rdoc_options:
56
- - --charset=UTF-8
70
+ rdoc_options: []
71
+
57
72
  require_paths:
58
73
  - bin
59
74
  required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
60
76
  requirements:
61
77
  - - ">="
62
78
  - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
63
82
  version: "0"
64
- version:
65
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
66
85
  requirements:
67
86
  - - ">="
68
87
  - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
69
91
  version: "0"
70
- version:
71
92
  requirements: []
72
93
 
73
94
  rubyforge_project:
74
- rubygems_version: 1.3.5
95
+ rubygems_version: 1.8.10
75
96
  signing_key:
76
97
  specification_version: 3
77
98
  summary: Query PSN friend status from the CLI
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- *.sw?
2
- pkg