-
Notifications
You must be signed in to change notification settings - Fork 6
/
sort-pc-games.ps1
78 lines (68 loc) · 2.59 KB
/
sort-pc-games.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
71
72
73
74
75
76
77
78
<#
.NOTES
Author: Justin Perdok (@JustinPerdok), https://justin-p.me.
License: MIT
Small mock-up script to sort your totally not pirated game collection by gerne.
The gerne is currently checked using the igdb.com API.
Using this I was able to sort 250ish games, about 20 games where sorted incorrectly, probally duo name mismatch.
Todo/things to test
- make a list of prefered genres instead of just using the first genre listed from igdb.com
- incorperate something like https://github.com/gravejester/Communary.PASM to check game names instead of just using the first result listed from igdb.com
- use SteamKit https://github.com/SteamRE/SteamKit instead of igdb
.LINK
https://github.com/justin-p/PowerShell/blob/master/sort-pc-games.ps1
#>
$baseurl = "API URL"
$apikey = "API KEY"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.add("user-key", "$apikey")
# location of unsorted games
$unsortedlocation = "Z:\games\PC"
# location of sorted games
$sortedlocation = "Z:\games\PC Sorted\"
# list of gernes used on igdb.com
$gernes = @('Point-and-click',
'Fighting',
'Shooter',
'Music',
'Platform',
'Puzzle',
'Racing',
'Real Time Strategy (RTS)',
'Role-playing (RPG)',
'Simulator',
'Sport',
'Strategy',
'Turn-based strategy (TBS)',
'Tactical',
'Hack and slashBeatem up',
'QuizTrivia',
'Pinball',
'Adventure',
'Indie',
'Arcade')
# create a folder for each gerne
ForEach ($genretype in $genres)
{
mkdir -Path $sortedlocation\$genretype
}
# get a list of local games.
# this script expects that the game is in a folder.
# I.E. 'Star.Wars.Battlefront.II.iso' is in a folder named 'Star Wars Battlefront II'
$listofgamestosort = Get-ChildItem -Directory -LiteralPath $Path | sort name
ForEach ($game in $listofgamestosort)
{
# search igdb for a list of games like $gamename
$gamename = $game.Name
$url = $baseurl + "/games/?search=$gamename&fields=name,genres"
$request_game = Invoke-RestMethod -Uri $url -Headers $headers
# use the result from above and select the first game and its first gerne
# check which gerne this is
$genre = $request_game[0].genres[0]
$url = $baseurl + "/genres/$genre"
$request_gerne = Invoke-RestMethod -Uri $url -Headers $headers
# remove any slashes and move the game to the gerne folder.
$gamegerne = $request_gerne.name
$gamegerne = $gamegerne -replace "\\",""
Move-Item -LiteralPath "$path\$gamename" -Destination "$sortedlocation\$gamegerne\$gamename"
}