elpendor / ES-scraper

A scraper for EmulationStation
47 stars 41 forks source link

Fix for Emulation Station 2.x (es_systems.cfg in XML format) #51

Open ultimoistante opened 9 years ago

ultimoistante commented 9 years ago

Hi, I've just written a new readConfig function to correctly parse the es_systems.cfg file, now in XML format. Just replace the function readConfig with this:

def readConfig(file):
    systems=[]
    config = ET.parse(file)
    configroot = config.getroot()
    for child in configroot:
        name = child.find('name').text
        path = child.find('path').text
        ext = child.find('extension').text
        pid = child.find('platformid').text
        if not pid:
            continue
        else:
            system=(name,path,ext,pid)
            systems.append(system)
            print name, path, ext, pid
    return systems

Note: you need to add the subnode in all the nodes, like this:

    <system>
        <fullname>Nintendo Entertainment System</fullname>
        <name>nes</name>
        <path>/media/usb/roms/nes</path>
        <extension>.nes .NES</extension>
        <command>..... </command>
        <platform>nes</platform>
        <platformid>7</platformid>
        <theme>nes</theme>
    </system>
sgtstadanko commented 9 years ago

I get an error when running after the change:

pi@raspberrypi:~$ python /home/pi/scraper.py Traceback (most recent call last): File "/home/pi/scraper.py", line 427, in ES_systems=readConfig(config) File "/home/pi/scraper.py", line 31, in readConfig config = ET.parse(file) File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1183, in parse tree.parse(source, parser) File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse parser.feed(data) File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1643, in feed self._raiseerror(v) File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1507, in _raiseerror raise err xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 92, column 237

murphjm commented 9 years ago

@sgtstadanko: This means your XML isn't well-formed. In other words, something is syntactically incorrect in your es_systems.cfg file.

I'd recommend you trim this file down to just the emulators you're actually using, and make sure you have a closing tag for all opening tags and they're properly nested.

<platformid>7</platformid>

etc.