Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,48 @@ Quick script written in Python that uses various online sources to scrape artwor

If you haven't done so, please update ES before running this script.

For image resizing to work, you need to install PIL:
For image resizing to work, you need to install Pillow:
```
sudo apt-get install python-imaging
sudo pip install Pillow
```

Usage
=====================
* Open your systems config file ($HOME/.emulationstation/es_systems.cfg) and append the corresponding [platform ID](#platform-list) to each system:

```
NAME=NES
DESCNAME=Nintendo Entertainment System
PATH=~/ROMS/NES/
EXTENSION=.nes
COMMAND=retroarch -L /path/to/core %ROM%
PLATFORMID=7
<systemList>
<!-- Here's an example system to get you started. -->
<system>
<!-- A short name, used internally. -->
<name>snes</name>

<!-- A "pretty" name, displayed in the menus and such. This one is optional. -->
<fullname>Super Nintendo Entertainment System</fullname>

<!-- The path to start searching for ROMs in. '~' will be expanded to $HOME or %HOMEPATH%, depending on platform.
All subdirectories (and non-recursive links) will be included. -->
<path>~/ROMS/SNES</path>

<!-- A list of extensions to search for, delimited by any of the whitespace characters (", \r\n\t").
You MUST include the period at the start of the extension! It's also case sensitive. -->
<extension>.smc .sfc .SMC .SFC</extension>

<!-- The shell command executed when a game is selected. A few special tags are replaced if found in a command, like %ROM% (see below). -->
<command>snesemulator %ROM%</command>
<!-- This example would run the bash command "snesemulator /home/user/roms/snes/Super\ Mario\ World.sfc". -->

<!-- The platform(s) to use when scraping. You can see the full list of accepted platforms in src/PlatformIds.cpp.
It's case sensitive, but everything is lowercase. This tag is optional.
You can use multiple platforms too, delimited with any of the whitespace characters (", \r\n\t"), eg: "genesis, megadrive" -->
<platform>snes</platform>

<!-- The theme to load from the current theme set. See THEMES.md for more information.
This tag is optional; if not set, it will use the value of <name>. -->
<theme>snes</theme>
<platformid>6</platformid>
</system>
</systemList>
```

* Run the script.
Expand Down
78 changes: 56 additions & 22 deletions scraper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python
import os, imghdr, urllib, urllib2, sys, Image, argparse, zlib, unicodedata, re
import os, imghdr, urllib, urllib2, sys, argparse, zlib, unicodedata, re, time
import difflib
from xml.etree import ElementTree as ET
from xml.etree.ElementTree import Element, SubElement
from PIL import Image

SCUMMVM = False

Expand All @@ -27,26 +28,20 @@ def fixExtension(file):
return newfile

def readConfig(file):
lines=config.read().splitlines()
systems=[]
for line in lines:
if not line.strip() or line[0]=='#':
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:
if "NAME=" in line:
name=line.split('=')[1]
if "PATH=" in line:
path=line.split('=')[1]
elif "EXTENSION" in line:
ext=line.split('=')[1]
elif "PLATFORMID" in line:
pid=line.split('=')[1]
if not pid:
continue
else:
system=(name,path,ext,pid)
systems.append(system)
config.close()
system=(name,path,ext,pid)
systems.append(system)
print name, path, ext, pid
return systems

def crc(fileName):
Expand Down Expand Up @@ -212,6 +207,18 @@ def getRelDate(nodes):
else:
return getText(nodes.find("ReleaseDate"))

def getRating(nodes):
if args.crc:
return None
else:
return getText(nodes.find("Rating"))

def getPlayers(nodes):
if args.crc:
return None
else:
return getText(nodes.find("Players"))

def getPublisher(nodes):
if args.crc:
return None
Expand Down Expand Up @@ -267,6 +274,17 @@ def chooseResult(nodes):
return int(raw_input("Select a result (or press Enter to skip): "))
else:
return 0

def ToXMLDate(d):
if d is not None:
if len(d) == 10 :
return time.strftime('%Y%m%dT%H%M%S', time.strptime(d, '%m/%d/%Y'))
elif len(d) == 4:
return time.strftime('%Y%m%dT%H%M%S', time.strptime('01/01/' + d, '%m/%d/%Y'))
else:
return None
else:
return None


def autoChooseBestResult(nodes,t):
Expand Down Expand Up @@ -358,10 +376,12 @@ def scanFiles(SystemInfo):
str_title=getTitle(result)
str_des=getDescription(result)
str_img=getImage(result)
str_rd=getRelDate(result)
str_rating=getRating(result)
str_rd=ToXMLDate(getRelDate(result))
str_pub=getPublisher(result)
str_dev=getDeveloper(result)
lst_genres=getGenres(result)
str_players=getPlayers(result)

if str_title is not None:
game = SubElement(gamelist, 'game')
Expand All @@ -370,9 +390,11 @@ def scanFiles(SystemInfo):
desc = SubElement(game, 'desc')
image = SubElement(game, 'image')
releasedate = SubElement(game, 'releasedate')
rating = SubElement(game, 'rating')
publisher=SubElement(game, 'publisher')
developer=SubElement(game, 'developer')
genres=SubElement(game, 'genres')
#genres=SubElement(game, 'genres')
players=SubElement(game, 'players')

path.text=filepath
name.text=str_title
Expand All @@ -399,19 +421,31 @@ def scanFiles(SystemInfo):
except:
print "Image resize error"


if str_rating is not None:
flt_rating = float(str_rating) / 10.0
rating.text = "%.6f" % flt_rating
else:
rating.text = "0.000000"

if str_rd is not None:

releasedate.text=str_rd

if str_pub is not None:
publisher.text=str_pub

if str_dev is not None:
developer.text=str_dev

if str_players is not None:
players.text=str_players

if lst_genres is not None:
for genre in lst_genres:
newgenre = SubElement(genres, 'genre')
newgenre = SubElement(game, 'genre')
newgenre.text=genre.strip()
break;
except KeyboardInterrupt:
print "Ctrl+C detected. Closing work now..."
except Exception as e:
Expand Down Expand Up @@ -456,4 +490,4 @@ def scanFiles(SystemInfo):
for i,v in enumerate(ES_systems):
scanFiles(ES_systems[i])

print "All done!"
print "All done!"