Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bburky
Last active October 26, 2019 02:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bburky/43e666b2f6bb6db4c42b5ecd93f7af38 to your computer and use it in GitHub Desktop.
Save bburky/43e666b2f6bb6db4c42b5ecd93f7af38 to your computer and use it in GitHub Desktop.
Import Installed Discord Games Playnite Extension
$discordApplications = Invoke-RestMethod "https://discordapp.com/api/v6/applications"
function InstalledDiscordGames {
# Some reason GetUnistallProgramsList has duplicates, is that normal?
foreach ($program in [Playnite.Common.System.Programs]::GetUnistallProgramsList()) {
if ($program.UninstallString -match "cmd /c start discord:///library/(\d+)/uninstall") {
$id = $matches[1]
$game = [Playnite.SDK.Models.Game]::new($program.DisplayName)
$game.Source = "Discord"
$game.GameId = $id
$game.InstallDirectory = $program.InstallLocation
$game.IsInstalled = $true
$game.PlayAction = [Playnite.SDK.Models.GameAction]::new()
$game.PlayAction.Type = [Playnite.SDK.Models.GameActionType]::URL
$game.PlayAction.Path = "discord:///library/{0}/launch" -f $id
[Playnite.SDK.Models.Game]$game
}
}
}
function AddMetadataToGames {
Param (
[parameter(ValueFromPipeline)]
[Playnite.SDK.Models.Game]$game
)
process {
$application = $discordApplications | Where-Object Id -eq $game.GameId | Select-Object -First 1
# The data in $application is also returned in the sku metadata as $metadata.application
$url = "https://discordapp.com/api/v6/store/published-listings/skus/{0}" -f ($application.primary_sku_id)
$metadata = Invoke-RestMethod $url
$game.Name = $metadata.sku.name
# TODO: description is Markdown, need to format to HTML
$game.Description = $metadata.description
$game.ReleaseDate = [DateTime]$metadata.sku.release_date
$game.Developers = $application.developers | Select-Object -ExpandProperty name
$game.Publishers = $application.publishers | Select-Object -ExpandProperty name
# TODO: figure out genre ids
# The Discord app uses icon urls like this:
# https://cdn.discordapp.com/app-icons/460940655984771072/d67e75e6c9c274109b40921670075773.webp?size=128&keep_aspect_ratio=false
# But it will actually return images of any filetype (not just webp) if you change the extension.
$game.Icon = "https://cdn.discordapp.com/app-icons/{0}/{1}.png" -f $game.GameId, $application.icon
# Image urls look like this, ?size=1024 is required or you get a tiny image
# https://cdn.discordapp.com/app-assets/535869836748783616/store/540232519434502199.png?size=1024
# Sizes of at least 1024 and 2048 seem to be available
# Maybe we should parse the image's mime_type, but Discord will generate the correct filetype depending on the extension
# $extension = $metadata.header_background.mime_type -split "/" | Select-Object -Last 1
$game.CoverImage = "https://cdn.discordapp.com/app-assets/{0}/store/{1}.png?size=2048" -f $game.GameId, $metadata.thumbnail.id
# hero_background looks better than header_background for this, header_background is very wide and short
$game.BackgroundImage = "https://cdn.discordapp.com/app-assets/{0}/store/{1}.png?size=2048" -f $game.GameId, $metadata.hero_background.id
$discordLink = "https://discordapp.com/store/skus/{0}/{1}" -f $metadata.sku.id, $metadata.sku.slug
$game.links = [Playnite.SDK.Models.Link[]]@(
[Playnite.SDK.Models.Link]::new("Discord", $discordLink)
)
# Discord may have info on the game from other stores including Steam
$steam = $application.third_party_skus | Where-Object distributor -eq "steam" | Select-Object -First 1
if ($steam) {
# both id and sku are present, but are the same for Steam skus
$steamLink = "https://store.steampowered.com/app/{0}" -f $steam.id
$game.Links.Add([Playnite.SDK.Models.Link]::new("Steam", $steamLink))
}
$game
}
}
function Import-InstalledDiscordGames {
$games = InstalledDiscordGames | Sort-Object | Get-Unique | AddMetadataToGames
$games | ForEach-Object { $PlayniteApi.Database.AddGame($_) }
$PlayniteApi.Dialogs.ShowMessage("Imported $($games.count) installed games from Discord Store.", "Discord Import Complete")
}
Name: Discord Store
Author: Blake Burkhart
Version: 0.1.0
Module: discord.ps1
Type: Script
Functions:
- Description: Import Installed Discord Games
FunctionName: Import-InstalledDiscordGames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment