Hello friends.
I just found the Playnite project, and it seems quite nice, but once I started using it I found that there didn't seem to be any easy way to import existing Retroarch .lpl playlists.
I spent the morning bodging this together for my own use but I thought I should register and post it here in case other people want to take it and use it or extend it.
It's not perfect!
Known problems and stuff to know:
That being said if you are OK with the caveats it should be useful for folks! Just drop these files into a new folder in the extensions directory and run it with Extensions->Retroach Playlist Importer.
I just found the Playnite project, and it seems quite nice, but once I started using it I found that there didn't seem to be any easy way to import existing Retroarch .lpl playlists.
I spent the morning bodging this together for my own use but I thought I should register and post it here in case other people want to take it and use it or extend it.
It's not perfect!
Known problems and stuff to know:
- Its set up so you can only import one .lpl file at a time. This is because I am using MAME for several platforms and rather than walking the supported platform list and matching up the correct platform I am letting them roll into the "Various" category (empty for me) and then just ctrl+a->edit to put them into the correct platform.
- For non MAME cores it will try to load the playlist into the right platform on its own and set the core appropriately.
- The cores are set manually in the script by playlist name. It would be nice to read the core name and use that instead if its in the playlist entry but for now no-go. I've tried to select the best in breed libretro cores for all the platforms I have content for but if you have a different preference or a new platform you will have to add the map entry to to the $supportedCore entry at the top of the script.
- It's a little slow if you have a lot of entries in a list.
- No de-duplication if you have multiple entries with different languages.
That being said if you are OK with the caveats it should be useful for folks! Just drop these files into a new folder in the extensions directory and run it with Extensions->Retroach Playlist Importer.
# RetroarchPlaylistImporter.ps1
$supportedCore = @{
"Atari - 2600" = "Stella" ;
"Atari - 5200" = "MAME" ;
"Atari - 7800" = "MAME" ;
"Atari - Lynx" = "Beetle Lynx" ;
"Bandai - WonderSwan Color" = "Beetle WonderSwan";
"Commodore - Amiga" = "PUAE";
"FBNeo - Arcade Games" = "MAME" ;
"MAME 2000" = "MAME" ;
"MAME 2010" = "MAME" ;
"MAME 2014" = "MAME" ;
"MAME 2016" = "MAME" ;
"Microsoft - MSX" = "blueMSX" ;
"Microsoft - MSX2" = "blueMSX" ;
"NEC - PC Engine - TurboGrafx 16" = "Beetle PCE" ;
"NEC - PC Engine CD - TurboGrafx-CD" = "Beetle PCE" ;
"NEC - PC Engine SuperGrafx" = "Beetle SuperGrafx" ;
"Nintendo - Family Computer Disk System" = "Mesen" ;
"Nintendo - Game Boy Advance" = "mGBA" ;
"Nintendo - Game Boy Color" = "SameBoy" ;
"Nintendo - Game Boy" = "SameBoy" ;
"Nintendo - GameCube" = "Dolphin" ;
"Nintendo - Nintendo 64" = "ParaLLEl N64" ;
"Nintendo - Nintendo DS" = "DeSmuME";
"Nintendo - Nintendo Entertainment System" = "Mesen";
"Nintendo - Satellaview" = "Mesen-S" ;
"Nintendo - Sufami Turbo" = "Mesen-S" ;
"Nintendo - Super Nintendo Entertainment System Hacks" = "Mesen-S" ;
"Nintendo - Super Nintendo Entertainment System" = "Mesen-S" ;
"Nintendo - Wii" = "Dolphin" ;
"Sega - 32X" = "PicoDrive" ;
"Sega - Dreamcast" = "Flycast" ;
"Sega - Game Gear" = "MAME" ;
"Sega - Master System - Mark III" = "MAME" ;
"Sega - Mega Drive - Genesis" = "Genesis Plus GX" ;
"Sega - Mega-CD - Sega CD" = "Genesis Plus GX" ;
"Sega - Saturn" = "Beetle Saturn" ;
"Sega - SG-1000" = "MAME" ;
"Sinclair - ZX Spectrum" = "81" ;
"SNK - Neo Geo Pocket Color" = "Beetle NeoPop" ;
"SNK - Neo Geo Pocket" = "Beetle NeoPop" ;
"Sony - PlayStation Portable (PSN)" = "PPSSPP" ;
"Sony - PlayStation Portable" = "PPSSPP" ;
"Sony - PlayStation" = "Beetle PSX HW" ;
"The 3DO Company - 3DO" = "Opera"
}
function GetMainMenuItems {
param(
$menuArgs
)
$menuItem1 = New-Object Playnite.SDK.Plugins.ScriptMainMenuItem
$menuItem1.Description = "Import Retroarch playlists from folder"
$menuItem1.FunctionName = "Import-Playlist"
$menuItem1.MenuSection = "@Retroarch Playlist Importer"
return $menuItem1
}
function Import-Playlist {
param (
$scriptMainMenuItemActionArgs
)
if (!($retroarchPath = $PlayniteApi.Dialogs.SelectFile("*.lpl|*.lpl"))) {
return
}
$retroarchEmulator = $PlayniteApi.Database.Emulators | Where { $_.Name -eq "Retroarch" } | Select-Object -First 1
if (!$retroarchEmulator) {
$PlayniteApi.Dialogs.ShowMessage("Couldn't find a Retroarch emulator configuration in Playnite. Make sure you have a Retroarch emulator configured.")
return
}
$imported = 0
$playlistName = [System.IO.Path]::GetFileNameWithoutExtension($retroarchPath)
if ($supportedCore[$playlistName]) {
$retroarchGames = Get-Content $retroarchPath -Raw | ConvertFrom-Json
$retroarchGames.items | ForEach {
if ($_.path) {
$gameName = $_.label
$game = New-Object "Playnite.SDK.Models.Game" $gameName
$game.GameImagePath = $_.path
$game.IsInstalled = $true
$playTask = New-Object "Playnite.SDK.Models.GameAction"
$playTask.Type = "Emulator"
$playTask.EmulatorId = $retroarchEmulator.Id
foreach ($profile in $retroarchEmulator.Profiles) {
if ($profile.Name -eq $supportedCore[$playlistName]) {
if ($PlayniteApi.Database.Games | Where-Object { ($_.Name -eq $gameName) -and ($game.PlatformId -eq $profile.Platforms[0]) }) {
# Skip existing games
break
}
$playTask.EmulatorProfileId = $profile.Id
$game.PlatformId = $profile.Platforms[0]
$game.PlayAction = $playTask
$PlayniteApi.Database.Games.Add($game)
$imported++
break
}
}
}
}
}
$PlayniteApi.Dialogs.ShowMessage("Imported $imported games from the selected playlists.", "Retroarch Playlist Importer")
$__logger.Info("Imported $imported games.")
}
# extension.yaml
Id: RetroarchPlaylistImporter_af768711-a433-428f-932e-207860c94fc9
Name: Retroarch Playlist Importer
Author: objaction
Version: 0.1
Module: RetroarchPlaylistImporter.ps1
Type: Script
Links:
- Name: Github
Url: https://github.com/
- Name: Playnite Forums thread
Url: https://playnite.link/forum/