-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetch_game_data.ps1
70 lines (62 loc) · 1.99 KB
/
fetch_game_data.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<#
.SYNOPSIS
Fetch Call of Duty stats of a player
.DESCRIPTION
Fetch Call of Duty stats of a player and output json, can fail if the user doesn't allow the share of his stats with the other
.EXAMPLE
PS> .\fetch_bo4_data.ps1 -UserName ATE48 -Platform xbl
Saving data https://my.callofduty.com/api/papi-client/crm/cod/v2/title/bo4/platform/xbl/gamer/ATE48/profile/type/mp/ to output_account/xbl_ATE48_mp.json...
Saving data https://my.callofduty.com/api/papi-client/crm/cod/v2/title/bo4/platform/xbl/gamer/ATE48/profile/type/blackout/ to output_account/xbl_ATE48_blackout.json...
Saving data https://my.callofduty.com/api/papi-client/crm/cod/v2/title/bo4/platform/xbl/gamer/ATE48/profile/type/zombies/ to output_account/xbl_ATE48_zombies.json...
.PARAMETER UserName
The username of the player
.PARAMETER Platform
The platform of the user
.PARAMETER Session
The session to connect, null to generate a new one
#>
param(
[string]
$UserName,
[ValidateSet("xbl", "battle", "steam", "psn")]
[string]
$Platform,
[ValidateSet("bo4", "bo3", "cw", "mw", "iw", "ww2")]
$title = "cw",
$Session
)
if ("bo4" -eq $title) {
$Modes = @(
"mp", "blackout", "zombies"
)
}
elseif ("cw" -eq $title -or "bo3" -eq $title) {
$Modes = @(
"mp", "zombies"
)
}
elseif ("mw" -eq $title) {
$Modes = @(
"wz", "mp"
)
}
else {
$Modes = @(
"mp"
)
}
if ($null -eq $Session) {
$Session = ./build_sso_websession.ps1 -CookieDomain "my.callofduty.com"
if ($null -eq $Session) {
Write-Error "Can't get session"
Exit -1
}
}
New-Item -ItemType Directory "output_account/$title" -Force > $null
foreach ($Mode in $Modes) {
$name = "output_account/$title/$($Platform)_$($Username)_$Mode.json"
$uri = "https://my.callofduty.com/api/papi-client/stats/cod/v1/title/$title/platform/$Platform/gamer/$UserName/profile/type/$Mode/"
Write-Host "Saving data $uri to $name..."
$json = (Invoke-WebRequest -Uri $uri -WebSession $Session).Content | ConvertFrom-Json -Depth 8
$json | ConvertTo-Json -Depth 8 | Out-File -Encoding utf8 $name > $null
}