[gnome-games] tools: Get supported controllers from psxdatacenter.com
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] tools: Get supported controllers from psxdatacenter.com
- Date: Fri, 2 Sep 2016 22:50:52 +0000 (UTC)
commit 84c015d2279d5f484116b12434ace63de83f1161
Author: Adrien Plazas <kekun plazas laposte net>
Date: Fri Sep 2 20:30:03 2016 +0200
tools: Get supported controllers from psxdatacenter.com
This allow to know the available controllers for PlayStation games.
https://bugzilla.gnome.org/show_bug.cgi?id=770192
tools/gameinfo/gameinfo/__init__.py | 20 +++++++++++++++
tools/gameinfo/psxdatacenter-gameinfo.py | 39 ++++++++++++++++++++++++-----
2 files changed, 52 insertions(+), 7 deletions(-)
---
diff --git a/tools/gameinfo/gameinfo/__init__.py b/tools/gameinfo/gameinfo/__init__.py
index 1cb5145..342b1b3 100644
--- a/tools/gameinfo/gameinfo/__init__.py
+++ b/tools/gameinfo/gameinfo/__init__.py
@@ -122,6 +122,18 @@ class Gameinfo:
titleE = ET.SubElement(game, '_title')
titleE.text = title
+ def set_game_controllers(self, game, controllers):
+ if not game in self.games:
+ return
+
+ for c in game.findall('controllers'):
+ game.remove(c)
+
+ controllers_node = ET.SubElement(game, 'controllers')
+ for controller in controllers:
+ controller_node = ET.SubElement(controllers_node, 'controller')
+ controller_node.set('type', controller)
+
def set_disc_title_for_disc_id(self, disc_id, title):
disc = self.find('games/game/discs/disc[@id="' + disc_id + '"]')
if disc is None:
@@ -140,6 +152,7 @@ class Gameinfo:
for game in games:
Gameinfo._sort_game_titles(game)
Gameinfo._sort_game_discs(game)
+ Gameinfo._sort_game_controllers(game)
title = game.findtext('_title')
data.append((title, game))
@@ -179,3 +192,10 @@ class Gameinfo:
for disc_id, discs_node in data:
game.remove(discs_node)
game.append(discs_node)
+
+ def _sort_game_controllers(game):
+ controllers_nodes = game.findall('controllers')
+
+ for controllers_node in controllers_nodes:
+ game.remove(controllers_node)
+ game.append(controllers_node)
diff --git a/tools/gameinfo/psxdatacenter-gameinfo.py b/tools/gameinfo/psxdatacenter-gameinfo.py
index 349fdca..741c5bd 100755
--- a/tools/gameinfo/psxdatacenter-gameinfo.py
+++ b/tools/gameinfo/psxdatacenter-gameinfo.py
@@ -61,7 +61,7 @@ class GamesListScrapper:
includes = re.sub('<span.*?>', '', includes)
discs_node.set('includes', includes.strip())
- def fetch_tmp_gameinfo():
+ def fetch_tmp_gameinfo(verbose):
gameinfo = Gameinfo()
game_lists = [
@@ -71,7 +71,7 @@ class GamesListScrapper:
for url in game_lists:
page = _fetch_page(url)
- GamesListScrapper._parse_game_list_page(page, gameinfo)
+ GamesListScrapper._parse_game_list_page(page, gameinfo, verbose)
return gameinfo
@@ -89,6 +89,21 @@ class GamePageScrapper:
return title
+ def _get_game_controllers(game_page):
+ classic_gamepad_search = 'Standard Controller'
+ allow_classic_gamepad = re.search(classic_gamepad_search, game_page, re.IGNORECASE)
+
+ analog_gamepad_search = 'Analog Controller'
+ allow_analog_gamepad = re.search(analog_gamepad_search, game_page, re.IGNORECASE)
+
+ controllers = []
+ if allow_classic_gamepad:
+ controllers.append ('classic-gamepad')
+ if allow_analog_gamepad:
+ controllers.append ('analog-gamepad')
+
+ return controllers
+
def parse_game_page(gameinfo, game, url):
game_page = _fetch_page(url)
@@ -96,20 +111,29 @@ class GamePageScrapper:
if not title:
return
+ controllers = GamePageScrapper._get_game_controllers(game_page)
+ if controllers and len(controllers) == 0:
+ controllers = None
+ if controllers and len(controllers) == 2:
+ if 'classic-gamepad' in controllers and 'analog-gamepad' in controllers:
+ controllers = None
+
print(title)
gameinfo.set_game_title(game, title)
+ if controllers is not None:
+ gameinfo.set_game_controllers(game, controllers)
class Scrapper:
_FILENAME = 'playstation.gameinfo.xml.in'
_TMP_FILENAME = _FILENAME + '.tmp'
- def _get_tmp_gameinfo():
+ def _get_tmp_gameinfo(verbose):
gameinfo_path = _outdir() + '/' + 'playstation.gameinfo.xml.in.tmp'
if exists(gameinfo_path):
return Gameinfo(gameinfo_path)
- gameinfo = GamesListScrapper.fetch_tmp_gameinfo()
+ gameinfo = GamesListScrapper.fetch_tmp_gameinfo(verbose)
if not exists(_outdir()):
makedirs(_outdir())
@@ -118,8 +142,8 @@ class Scrapper:
return gameinfo
- def scrap():
- gameinfo = Scrapper._get_tmp_gameinfo()
+ def scrap(verbose):
+ gameinfo = Scrapper._get_tmp_gameinfo(verbose)
gameinfo_path = _outdir() + '/' + 'playstation.gameinfo.xml.in.tmp'
if not exists(_outdir()):
@@ -146,4 +170,5 @@ class Scrapper:
gameinfo.save(gameinfo_path)
if __name__ == '__main__':
- Scrapper.scrap()
+ verbose = False
+ Scrapper.scrap(verbose)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]