gamelist generated by bash script

159 views
Skip to first unread message

Wes Hodges

unread,
Sep 5, 2014, 11:13:23 AM9/5/14
to cabrio...@googlegroups.com
So a while back, user Gabriel posted a bash script on here that I could never get working. Well I figured it out and I thought that I would post the process here so that someone seeking support (as I was when I stumbled upon this group) may find this helpful.

1.  match up all of your file-names between roms, screenshots/videos, logo, etc. exactly
2.  use a batch file renamer to then remove all the spaces from the file-names and also replace the '&' characters with 'and'  (ie BacktotheFutureIIandIII)
3.  place the script inside of the roms folder that you are using the list for and then edit the script with leafpad (or similar) to fit your needs
4.  in terminal, cd to rom directory and run the scipt


the generated list will populate inside of the roms folder you had the script placed in
also...i do all my renaming/gathering/downloading and planning on windows. if you do this too, then you will need to retype the script in Lubuntu (or whatever your using) to avoid a command error.

#!/bin/bash

for i in $( ls *.zip); do
    f="${i%.*}"
    echo $f
echo "      <game>
        <name>$f</name>
        <platform>platform type here</platform>
        <rom-image>/path/to/your/roms/$f.zip</rom-image>
        <images>
          <image>
            <type>logo</type>
            <image-file>/path/to/your/logos/$f.png</image-file>
          </image>
          <image>
            <type>screenshot</type>
            <image-file>/path/to/your/screenshots/$f.png</image-file>
          </image>
        </images>
      </game>">>gamelist.xml

done

OmahaVike

unread,
Sep 19, 2014, 8:36:22 PM9/19/14
to cabrio...@googlegroups.com
Here man, give this a whirl.  All you need to do is to edit the paths at the top of the script and everything else should fall into place (for MAME anyhow).  WARNING:  it WILL delete your gamelist.xml wherever you execute this, so backup backup backup.

ROMDIR=/path/to/roms
TITLESDIR=/path/to/your/titles
SNAPDIR=/path/to/your/snap

if [ -f gamelist.xml ]
then
echo "deleting gamelist.xml"
rm gamelist.xml
fi

for i in $( ls $ROMDIR/*.zip | xargs -n1 basename ); do

f="${i%.*}"
echo $f
echo " <game>
<name>$f</name>
        <platform>Arcade</platform>
<rom-image>$f.zip</rom-image>
<images>" >> gamelist.xml
if [ -f $TITLESDIR/$f.png ]
then
echo " <image>
<type>logo</type>
<image-file>$TITLESDIR/$f.png</image-file>
</image>" >> gamelist.xml
fi
if [ -f $SNAPDIR/$f.png ]
then
echo " <image>
<type>screenshot</type>
<image-file>$SNAPDIR/$f.png</image-file>
</image>" >> gamelist.xml
fi

echo " </images>
<categories>
<category>
<name>emulator</name>
<value>mame</value>
</category>
</categories>
</game>">>gamelist.xml


OmahaVike

unread,
Sep 19, 2014, 8:38:15 PM9/19/14
to cabrio...@googlegroups.com
forgot to mention that my script will only insert an image xml element if a screenshot was found.  if it didn't find a screenshot, it won't enter a tag.  same thing with the title.

Wes Hodges

unread,
Oct 28, 2014, 3:05:52 AM10/28/14
to cabrio...@googlegroups.com
had this fixed a bit ago but forgot to post it. here is a newer version on the script that allows for spaces. just pop this in place of the other

for f in *.zip ; do
  f="${i%.*}"
  echo "$if";

Eduardo Aguilera

unread,
Jan 13, 2015, 12:18:43 PM1/13/15
to cabrio...@googlegroups.com
Hi Wes Hodges,
I can't make your script work if there are spaces in the filename...could you please post the complete fixed script? Thanks!

Wes Hodges

unread,
Feb 2, 2015, 4:07:22 PM2/2/15
to cabrio...@googlegroups.com
this is the entire scripting I run to generate my lists. This script does work with filename spaces, but I also run a secondary script to take them out because mednafen emulator cannot recognize anything with spaces.
This is the exact script I run so obviously, your filepaths within the script may be different.

sudo bash renamer.sh && bash list-builder.sh

this first script renamer.sh removes all the spaces and parentheses from the filenames:
#!/bin/bash

echo
......removing spaces......
for f in /home/gamer/.cabrio/roms/gb/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/roms/gba/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/roms/gbc/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/roms/genesis/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/logos/gb/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/logos/gba/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/logos/gbc/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/logos/genesis/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/videos/gb/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/videos/gba/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/videos/gbc/*; do mv "$f" "${f// /_}"; done
for f in /home/gamer/.cabrio/videos/genesis/*; do mv "$f" "${f// /_}"; done
echo ......finished removing spaces......

echo ......removing parentheses......
for file in /home/gamer/.cabrio/roms/gb/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/roms/gba/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/roms/gbc/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/roms/genesis/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/logos/gb/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/logos/gba/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/logos/gbc/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/logos/genesis/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/videos/gb/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/videos/gba/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/videos/gbc/*; do mv "$file" "${file/_(*)/}"; done
for file in /home/gamer/.cabrio/videos/genesis/*; do mv "$file" "${file/_(*)/}"; done
echo ......finished removing parentheses......

exit

the second script list-builder.sh loops through the parent directories and then creates individual xml files for each directory (emulator/system). it then combines the individual lists into a master list and adds lines at the beginning and end to make the master list well-formed. then it removes the now unnecessary individual lists.:
#!/bin/bash

set -e
#this creates the individual game-list files according to whats in the rom directories
echo
......building game lists......

for dir in /home/gamer/.cabrio/roms/*; do
    for i in $dir/*; do
        dir="${dir##*/
}"
        i="
${i##*/}"
        i
="${i%.*}"
        echo
"$i";

echo
"      <game>
        <name>$i</name>
        <platform>$dir</platform>
        <rom-image>/home/gamer/.cabrio/roms/$dir/$i.zip</rom-image>
        <video>/home/gamer/.cabrio/videos/$dir/$i.flv</video>

        <images>
          <image>
            <type>logo</type>
            <image-file>/home/gamer/.cabrio/logos/$dir/$i.png</image-file>
          </image>
        </images>
      </game>"
>>/home/gamer/.cabrio/"$dir"-list.xml

   
done
done
#this combines all the generated game-lists into 1 .xml file and then appends and prepends text to the file, then removes unnecessary .xml files
cat
/home/gamer/.cabrio/*-list.xml >> /home/gamer/.cabrio/master-gamelist.xml
sed -i '1s/^/<cabrio-config>\n/' /home/gamer/.cabrio/master-gamelist.xml
sed -i '2s/^/  <game-list>\n/' /home/gamer/.cabrio/master-gamelist.xml
sed -i '3s/^/    <games>\n/' /home/gamer/.cabrio/master-gamelist.xml
echo '    </games>' >> /home/gamer/.cabrio/master-gamelist.xml
echo '  </game-list>' >> /home/gamer/.cabrio/master-gamelist.xml
echo '</cabrio-config>' >> /home/gamer/.cabrio/master-gamelist.xml
sed -i -e 's/&/&amp;/g' /home/gamer/.cabrio/master-gamelist.xml

shopt -s extglob
rm /home/gamer/.cabrio/!(master-gamelist.xml|config.xml)
shopt -u extglob

echo ......finished building game lists......
exit

it may not be pretty, as I am pretty new to bash, but it gets it done.

acid...@gmail.com

unread,
Oct 9, 2016, 8:36:01 AM10/9/16
to Cabrio FE Development
du -h --max-depth=0 *  | sed 's/\(.zip\|.rar\|.nds\|.gz\|.7z\)//g' > ~/gamelist.txt
Reply all
Reply to author
Forward
0 new messages