Playnite Forums
  • Playnite Web
  • Rules
  • Members
  • Team
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Playnite Forums Playnite General Scripting (Powerscript) Question

Scripting (Powerscript) Question
Xuiwert
Offline

#1
12-18-2021, 04:17 PM
Hi,

I am looking at updating the LibraryExporter Powershell Script, and I can get it to run fine.  However it exports Collection name for those fields which are collections, and I am wondering if there is a way to get the data from those collections.  So at the moment it is showing:
,,"System.Collections.Generic.List`1[Playnite.SDK.Models.Platform]",,,,,"False"
Where it should be showing:
,,"PC (Windows)",,,,,"False"

I had simply updated the psm1 to:
$PlayniteApi.Database.Games | Select Name, Series, SortingName, Source, ReleaseDate, Added, CompletionStatus, ReleaseYear, Description, Devlopers, Publishers, Genres, Notes, Platforms, UserScore, Version, CoverImage, BackGroundImage, Hidden | ConvertTo-Csv | Out-File $path -Encoding utf8

Thanks
mbeemer
Offline

#2
01-07-2022, 09:19 PM
I am doing the same thing and am still experimenting with it but I think I have found a solution.  For every column you want to export based on a key into a collection, replace the field name with this expression:

@{Name="<your column name here>"; Expression={$_.<Playnite field name here> -join ', ' }}

For example, I use the Categories field to check which OSes a game is available for.  With the expression

@{Name="Categories"; Expression={$_.Categories -join ', ' }}

I get a column result of "Linux, OS2, Win".  Without the -join they are separated by spaces.  I have other columns like tags that you wouldn't be able to tell the difference between single and multiple word tags.
Xuiwert
Offline

#3
01-08-2022, 04:28 PM
(01-07-2022, 09:19 PM)mbeemer Wrote: I am doing the same thing and am still experimenting with it but I think I have found a solution.  For every column you want to export based on a key into a collection, replace the field name with this expression:

@{Name="<your column name here>"; Expression={$_.<Playnite field name here> -join ', ' }}

For example, I use the Categories field to check which OSes a game is available for.  With the expression

@{Name="Categories"; Expression={$_.Categories -join ', ' }}

I get a column result of "Linux, OS2, Win".  Without the -join they are separated by spaces.  I have other columns like tags that you wouldn't be able to tell the difference between single and multiple word tags.

Thanks for finding that out.  I currently just stuck with my Excel grid and some scripting on that, but maybe one day I will look at Playnite again.  I really would have expected that first functionality of any database frontend would be import/export of data, however this doesn't seem to be the case.
Xuiwert
Offline

#4
07-17-2022, 02:43 PM (This post was last modified: 07-17-2022, 02:45 PM by Xuiwert.)
Hi,

Just wanted to say thanks again to @mbeemer for providing the collections help with the export script.  I include the export script I use to extract the data I want into CSV.  And here is a direct link to the Playnite API Games Class which shows the various variables you can use (in case there is something I have not included that you want).
https://playnite.link/docs/api/Playnite.....Game.html

Steps:
1) In playnite get the Library Exporter Extension via Add-ons menu, Browse Generic, and find it in the list.
2) Locate the psm1 file, should be in ...\Extensions\LibraryExporterPS_Builtin
3) Replace the text using notepad or similar with the below text.
4) In Playnite, reload scripts, then run the Export Library option from Extensions. 
5) Supply a filename and location and your CSV should appear in that location.

LibraryExporter.psm1:
function ExportLibrary()
{
    param(
        $scriptMainMenuItemActionArgs
    )

    $path = $PlayniteApi.Dialogs.SaveFile("CSV|*.csv|Formated TXT|*.txt")
    if ($path)
    {
        if ($path -match ".csv$")
        {
            $PlayniteApi.Database.Games | Select Name, @{Name="Series"; Expression={$_.Series -join '~' }}, SortingName, Id, Source, ReleaseDate, Added, CompletionStatus, ReleaseYear, Description, Devlopers, @{Name="Publishers"; Expression={$_.Publishers -join '~' }}, @{Name="Genres"; Expression={$_.Genres -join '~' }}, Notes, @{Name="Platforms"; Expression={$_.Platforms -join '~' }}, UserScore, Version, CoverImage, BackGroundImage, Hidden | ConvertTo-Csv | Out-File $path -Encoding utf8
        }
        else
        {          
            $PlayniteApi.Database.Games | Select Name, @{Name="Series"; Expression={$_.Series -join '~' }}, SortingName, Id, Source, ReleaseDate, Added, CompletionStatus, ReleaseYear, Description, Devlopers, @{Name="Publishers"; Expression={$_.Publishers -join '~' }}, @{Name="Genres"; Expression={$_.Genres -join '~' }}, Notes, @{Name="Platforms"; Expression={$_.Platforms -join '~' }}, UserScore, Version, CoverImage, BackGroundImage, Hidden | Format-Table -AutoSize | Out-File $path -Encoding utf8
        }
       
        $PlayniteApi.Dialogs.ShowMessage("Library exported successfully.");
    }
}

function GetMainMenuItems()
{
    param(
        $menuArgs
    )

    $menuItem = New-Object Playnite.SDK.Plugins.ScriptMainMenuItem
    $menuItem.Description = "Export Library"
    $menuItem.FunctionName = "ExportLibrary"
    $menuItem.MenuSection = "@"
    return $menuItem
}

Hope that helps.
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode