elpendor / ES-scraper

A scraper for EmulationStation
47 stars 41 forks source link

idea: extract thegamesdb ID from filename #39

Open solygen opened 10 years ago

solygen commented 10 years ago

Wouldn't it be nice to use the unique thegameddb ID to guarantee the right game is selected. Perhaps we could use brackets:

super mario world [136].snes

It might be a good idea to have a search without a identified id as fallback.

Spitz4478 commented 10 years ago

I second this notion, but would offer up an alternative solution...

When the -m switch is used with ES-scraper, number the results according to their unique thegamesdb.net ID. Then allow the user to enter the corresponding game ID - to include one that is not on the list, in case there are no valid results. This gives the user much more control, and will hopefully eliminate any more "mismatched title" issues on git :).

I'm sure you already know this, but a query by game ID can be accomplished using http://thegamesdb.net/api/GetGame.php and passing only the correct 'id' parameter.

It may also be helpful if the -m result sets were truncated to a list that could actually fit on-screen (i.e. the first 20 results or so). Titles that include the word "super", for example, can end up returning hundreds of results - most of which are not even close to what you were looking for. Then you have to scroll back up to find the search name and the first entries in the list. If I don't find my game within the first 10 results or so, it's typically because it's just not in thegamesdb.net database (or it's because of the problem noted in Issue https://github.com/elpendor/ES-scraper/issues/38).

lessthannano commented 10 years ago

still new to emulation on rpi, but I modified the scraper to look for "id=[gameid]" as the last part of the filename before the ext. below is the getGameInfo method that I modified. It's really only 7 lines that I modified starting with the "gameid=" line. I can take the time to write a patch (new to that too) if anyone finds this useful.

def getGameInfo(file,platformID): title=re.sub(r'[.?]|(.?)', '', os.path.splitext(os.path.basename(file))[0]).strip() print "Title: %s" % title if args.crc: crcvalue=crc(file) if args.v: try: print "CRC for %s: %s" % (os.path.basename(file), crcvalue) except zlib.error as e: print e.strerror URL = "http://api.archive.vg/2.0/Game.getInfoByCRC/xml/7TTRM4MNTIKR2NNAGASURHJOZJ3QXQC5/%s" % crcvalue values={} else: URL = "http://thegamesdb.net/api/GetGame.php" platform = getPlatformName(platformID) if platform == "Arcade": title = getRealArcadeTitle(title)

    if args.fix:
        try:                
            fixreq = urllib2.Request("http://thegamesdb.net/api/GetGamesList.php", urllib.urlencode({'name' : title, 'platform' : platform}), headers={'User-Agent' : "RetroPie Scraper Browser"})
            fixdata=ET.parse(urllib2.urlopen(fixreq)).getroot()
            if fixdata.find("Game") is not None:            
                values={ 'id': fixdata.findall("Game/id")[chooseResult(fixdata)].text if args.m else fixdata.find("Game/id").text }
        except:
            return None
    else:
        values={'name':title,'platform':platform}

try:
    gameid=os.path.splitext(os.path.basename(file))[0].split("id=")[1]
    if gameid != None:
        print "gameid: %s" % gameid
        URL=URL + "?id=" + gameid
        req = urllib2.Request(URL,None, headers={'User-Agent' : "RetroPie Scraper Browser"})
    else:
        req = urllib2.Request(URL,urllib.urlencode(values), headers={'User-Agent' : "RetroPie Scraper Browser"}) 
    remotedata = urllib2.urlopen( req )
    data=ET.parse(remotedata).getroot()
except ET.ParseError:
    print "Malformed XML found, skipping game.. (source: {%s})" % URL
    return None

try:
    if args.crc:
        result = data.find("games/game")
        if result is not None and result.find("title").text is not None:
            return result
    elif data.find("Game") is not None:
        return data.findall("Game")[chooseResult(data)] if args.m else data.find("Game")
    else:
        return None
except Exception, err:
    print "Skipping game..(%s)" % str(err)
    return None

nsion.

solygen commented 10 years ago

Would be nice if you could provide a patch... a pull request would also be nice. Thanks for your efforts!

e0da commented 8 years ago

Or maybe just let you enter the ID into the interface somewhere? Is there some workaround for adding titles which can't be found by searching? I'd manually edit the database if I knew where to start. Thanks!