Python Script to create Media Directories in RocketLaunch for Pause

beano38

New member
Let me start by saying I'm not a coder. This is my attempt to easily create directories in the Hyperlaunch/RocketLauncher media folder for all of the media that is used in HyperPause. This does nothing but create the folders.

It first looks into the HyperSpin databases directory and checks all subdirectories for XML files. If it exists it saves that as a variable and then opens the XML file and creates the directory name (from the game name) for each of the media directories - Artwork, Backgrounds, Bezels, Fade, Guides, Manuals, MultiGame, Music, Videos

It does simple error checking for if the XML file exists in the database directory, if the XML is proper and if the directory it's trying to create exists. There are error log outputs for each of these checks.

If the XML File does not exist it dumps info into dberror.txt
If the XML File does exist but does not meet minimum criteria, it dumps info into xmlerror.txt
If the directory it's trying to create exists, it dumps info into the mderror.txt (you will get errors in here if because many of the MAME names are duplicates)

The python file can exist anywhere on your computer, there are two variables that need to be set at the very beginning of the file.

set your RocketLauncher/HyperLaunch path to the variable rlPath
example: rlPath = 'D:\\Arcade\RocketLauncher\\'
equals: D:\Arcade\RocketLauncher\

set your HyperSpin path to the variable hsPath
example: hsPath = 'D:\\Arcade\\Hyperspin\\'
typical install: hsPath = 'C:\\HyperSpin\\'
if you were weird and put in several subdirectories: hspath = 'C:\\dir1\\dir2\\dir3\\dir4\\HyperSpin\\' (you get the idea)

Make sure you set the full path with the drive letter, also leave in the single quotes (') and the double slashes (\\). I


I used python 3.5 to write the file, download available here - https://www.python.o...ase/python-350/
I used the Windows x86-64 executable installer version

Feel free to edit the file to suit your needs and please provide feedback if this works for you or if you think there's ways to optimize this .

Next on the list is to take the content I downloaded from EmuMovies FTP site and create a python script to auto rename and put the files in the proper directories that this one creates.

WARNING WARNING WARNING

This will create directories in the paths that you set. If you set them wrong, the directories will be created anyway.
I have not tried this using HyperLaunch, although the only difference related to this script is the directory name. Upgrade to RocketLauncher already . . .
I have only tested with official HyperSpin databases found at http://www.hyperlist.hyperspin-fe.com/

Code:
import xml.etree.ElementTree as ET
import os

rlPath = 'D:\\Arcade\\RocketLauncher\\' #set your RocketLauncher Path here
hsPath = 'D:\\Arcade\\Hyperspin\\' #set your HyperSpin Path here

def xmlparse(xml, Path):
    xml = ET.parse(xml)
    root = xml.getroot()
    sysname = (root[0][0].text)

    for game in root.findall('game'):
        name = game.get('name')
        dirs = ('Artwork', 'Backgrounds', 'Bezels', 'Fade', 'Guides', 'Manuals', 'MultiGame', 'Music', 'Videos')
        for dir in dirs:
            directory = rlPath + 'Media\\' + dir + '\\' + sysname + '\\' + name
            #directory = 'Media\\' + dir + '\\' + sysname + '\\' + name
            try:
                os.makedirs(directory)
            except:
                file = open('mderror.txt', 'a')
                mderror = 'ERROR directory ' + directory + ', exists \n'
                file.write(mderror)
                file.close()

path = hsPath + 'Databases'
systems = os.listdir(path)

for system in systems:
    database = path + '\\' + system + '\\' + system + '.xml'
    #print(database)
    if os.path.isfile(database):
        try:
            xmlparse(database, rlPath)
        except:
            file = open('xmlerror.txt', 'a')
            xmlerror = 'Malformed XML Document for ' + database + '\n'
            file.write(xmlerror)
            file.close()
    else:
        file = open('dberror.txt', 'a')
        error = database + ', does not exist \n'
        file.write(error)
        file.close()

# test = 'D:\Arcade\HyperSpin\Databases\MAME\MAME.xml'
# xmlparse(test, rlPath)
 
Top