Skip to content

Instantly share code, notes, and snippets.

@keb
Last active June 24, 2021 00:21
Show Gist options
  • Save keb/b686170958866a7c40bf613f421d93ca to your computer and use it in GitHub Desktop.
Save keb/b686170958866a7c40bf613f421d93ca to your computer and use it in GitHub Desktop.
$rawGames = $PlayniteApi.Database.Games
$count = $PlayniteApi.Database.Games.Count
[System.Collections.ArrayList]$games = @()
foreach ($game in $rawGames) {
if ($game.Source.Name) {
$gameObj = @{
"name" = $game.Name # adding the game name to the JSON breaks things
"store" = $game.Source.Name
}
$games.Add($gameObj)
}
}
$payload = @{
"count" = $count
"games" = $games
}
$json = $payload | ConvertTo-Json -Compress
$headers = @{
"Accept" = "application/vnd.github.v3+json"
"Content-Type" = "application/json"
"Authorization" = "token $token"
"Charset" = "UTF-8"
}
$body = @{
"description" = "PlayniteGistLib"
"public" = $True
"files" = @{
"library.json" = @{
"filename" = "library.json"
"content" = $json
}
}
} | ConvertTo-Json -Compress
$response = Invoke-WebRequest -Method "POST" -Headers $headers -Body $body -Uri "https://api.github.com/gists"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment