Created
April 16, 2019 17:29
-
-
Save cmitu/8d6ce71acd744a4b7fe450509dcd4d1a to your computer and use it in GitHub Desktop.
Gamelist video parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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