-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
Hello All.
I had found that Scraper does not work with PortMaster games and cannot properly find tile names or screenshots.
I had created my own python script to extract data from ports.json and use screenshot from game folder.
So there are 2 problems:
- I'm not sure how to integrate it to the tool itself, but I've tested it as an independent script, and it works. ( see below )
- What is the proper value for the
PORTMASTER_DIR
import os
import json
import xml.etree.ElementTree as ET
import xml.dom.minidom
UNKNOWN_STRING = "<Unknown>"
PORTMASTER_DIR = "~/ports/"
GAMELIST_XML_PATH = f"{PORTMASTER_DIR}/gamelist.xml"
games = []
# Fill in details for each game
for entry in os.listdir(PORTMASTER_DIR):
if "images" == entry or "PortMaster" == entry:
continue
dir_path = os.path.join(PORTMASTER_DIR, entry)
if os.path.isdir(dir_path):
json_path = os.path.join(dir_path, "port.json")
if not os.path.isfile(json_path):
print(f"Missing JSON file in {dir_path}")
continue
screenshot_file = next((f for f in os.listdir(dir_path) if f.startswith("screenshot")), None)
with open(json_path, "r") as f:
try:
data = json.load(f)
game_elem = ET.Element("game")
ET.SubElement(game_elem, "path").text = f"./{next((f for f in data.get("items") if f.endswith('.sh')), None)}"
ET.SubElement(game_elem, "name").text = data.get("attr", {}).get("title", UNKNOWN_STRING)
ET.SubElement(game_elem, "desc").text = data.get("attr", {}).get("desc", UNKNOWN_STRING)
ET.SubElement(game_elem, "image").text = f"./{entry}/{screenshot_file}" if screenshot_file else UNKNOWN_STRING
genres = data.get("attr", {}).get("genres", [])
ET.SubElement(game_elem, "genre").text = ", ".join(genres) if genres else UNKNOWN_STRING
games.append(game_elem)
except json.JSONDecodeError as e:
print(f"Error parsing JSON in {json_path}: {e}")
# Write XML file
root = ET.Element("gameList")
for game in games:
root.append(game)
tree = ET.ElementTree(root)
tree.write(GAMELIST_XML_PATH, encoding="utf-8", xml_declaration=True)
xml_str = ET.tostring(root, encoding="utf-8")
# Pretty print the generated XML
pretty_xml = xml.dom.minidom.parseString(xml_str).toprettyxml(indent=" ")
with open(GAMELIST_XML_PATH, "w", encoding="utf-8") as f:
f.write(pretty_xml)
print(f"Generated {GAMELIST_XML_PATH} with {len(games)} games.")Metadata
Metadata
Assignees
Labels
No labels