Skip to content

Instantly share code, notes, and snippets.

@thingsiplay
Last active December 20, 2023 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thingsiplay/1f68e9125a1e2b2432c0ed58686b2008 to your computer and use it in GitHub Desktop.
Save thingsiplay/1f68e9125a1e2b2432c0ed58686b2008 to your computer and use it in GitHub Desktop.
RetroArch playlist key extractor - Dirty way of reading and printing values from .lpl playlist files
#!/usr/bin/bash
# RetroArch playlist key extractor
# Dirty way of reading and printing values from .lpl playlist files.
#
# EXAMPLES:
# lplpath
# lplpath "~/.config/retroarch/playlists/Nintendo - Game Boy.lpl"
KEY=path
#DEFAULT_FILE=~/.config/retroarch/content_favorites.lpl
DEFAULT_FILE=~/.config/retroarch/content_history.lpl
if [ "$#" -eq "0" ]
then
FILE=$DEFAULT_FILE
else
FILE=$1
fi
# grep: get all lines with path
# awk: get the filepath
# sed: remove surrounding quotes and comma
grep -E '\s*"'$KEY'":\s*' "$FILE" \
| awk -F: '{print $2}' \
| sed 's/",\s*//g' \
| sed 's/\s*"//g'
@milnak
Copy link

milnak commented Dec 20, 2023

jq (sudo apt install jq --yes) is your friend.

jq -r '.items[].path' content_favorites.lpl

@thingsiplay
Copy link
Author

thingsiplay commented Dec 20, 2023

At that time I didn't know about jq and didn't understood the file format. I actually plan on revisiting this soon, so it is good to know. Thanks for the reply, it's a great idea in case someone comes across this script. Edit: BTW I did it already it seems: https://gist.github.com/thingsiplay/21f92ab90cfbb75afc49a4624389c462

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment