Skip to content

Instantly share code, notes, and snippets.

@cmitu
Created April 16, 2019 17:29
Show Gist options
  • Save cmitu/8d6ce71acd744a4b7fe450509dcd4d1a to your computer and use it in GitHub Desktop.
Save cmitu/8d6ce71acd744a4b7fe450509dcd4d1a to your computer and use it in GitHub Desktop.
Gamelist video parser
#!/usr/bin/env bash
system=$1
echo Analyzing `echo $system | tr [a-z] [A-Z]`...
if [ -f "$HOME/RetroPie/roms/$system/gamelist.xml" ]; then
echo "* found gamelist in ROM folder"
gamelist="$HOME/RetroPie/roms/$system/gamelist.xml"
else
echo "* found gamelist in default location"
# TODO: check if the file exists
gamelist="$HOME/.emulationstation/gamelists/$system/gamelist.xml"
fi
declare -a games
declare -a videos
_IFS=$IFS; IFS=$'\n'
# Loop through the gamelist and find out which games have videos
for game in `xmlstarlet sel -T -t -m "/gameList/game[video !='' ]" -v "path" -n "$gamelist"`; do
games+=("$game")
done
for video in `xmlstarlet sel -T -t -m "/gameList/game[video !='' ]" -v "video" -n "$gamelist"`; do
videos+=("$video")
done
# Restore IFS
IFS=$_IFS
# List the files and the videos
if [ ${#games[@]} -eq 0 ]; then
echo "! No videos found for $system"
else
for i in "${!games[@]}" ; do
echo " - '${games[$i]}' has video '${videos[$i]}'"
# TODO: check if file exists (can also be a folder) then perform action on video
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment