Skip to content

Commit

Permalink
Merge pull request #8 from milouk/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
milouk authored Oct 17, 2024
2 parents f0a0103 + ec89626 commit 3ea19dc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 52 deletions.
30 changes: 15 additions & 15 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,25 @@
"dir": "CPS1",
"id": "6",
"name": "Capcom Play System",
"box": "/mnt/mmc/MUOS/info/catalogue/CPS1/box/",
"preview": "/mnt/mmc/MUOS/info/catalogue/CPS1/preview/",
"synopsis": "/mnt/mmc/MUOS/info/catalogue/CPS1/text/"
"box": "/mnt/mmc/MUOS/info/catalogue/Arcade/box/",
"preview": "/mnt/mmc/MUOS/info/catalogue/Arcade/preview/",
"synopsis": "/mnt/mmc/MUOS/info/catalogue/Arcade/text/"
},
{
"dir": "CPS2",
"id": "7",
"name": "Capcom Play System 2",
"box": "/mnt/mmc/MUOS/info/catalogue/CPS2/box/",
"preview": "/mnt/mmc/MUOS/info/catalogue/CPS2/preview/",
"synopsis": "/mnt/mmc/MUOS/info/catalogue/CPS2/text/"
"box": "/mnt/mmc/MUOS/info/catalogue/Arcade/box/",
"preview": "/mnt/mmc/MUOS/info/catalogue/Arcade/preview/",
"synopsis": "/mnt/mmc/MUOS/info/catalogue/Arcade/text/"
},
{
"dir": "CPS3",
"id": "8",
"name": "Capcom Play System 3",
"box": "/mnt/mmc/MUOS/info/catalogue/CPS3/box/",
"preview": "/mnt/mmc/MUOS/info/catalogue/CPS3/preview/",
"synopsis": "/mnt/mmc/MUOS/info/catalogue/CPS3/text/"
"box": "/mnt/mmc/MUOS/info/catalogue/Arcade/box/",
"preview": "/mnt/mmc/MUOS/info/catalogue/Arcade/preview/",
"synopsis": "/mnt/mmc/MUOS/info/catalogue/Arcade/text/"
},
{
"dir": "DAPHNE",
Expand Down Expand Up @@ -268,7 +268,7 @@
"synopsis": "/mnt/mmc/MUOS/info/catalogue/FBNEO/text/"
},
{
"dir": "FC",
"dir": "NES",
"id": "3",
"name": "NES (Famicom)",
"box": "/mnt/mmc/MUOS/info/catalogue/Nintendo NES-Famicom/box/",
Expand Down Expand Up @@ -375,9 +375,9 @@
"dir": "MAME",
"id": "75",
"name": "Mame 2000",
"box": "/mnt/mmc/MUOS/info/catalogue/MAME/box/",
"preview": "/mnt/mmc/MUOS/info/catalogue/MAME/preview/",
"synopsis": "/mnt/mmc/MUOS/info/catalogue/MAME/text/"
"box": "/mnt/mmc/MUOS/info/catalogue/Arcade/box/",
"preview": "/mnt/mmc/MUOS/info/catalogue/Arcade/preview/",
"synopsis": "/mnt/mmc/MUOS/info/catalogue/Arcade/text/"
},
{
"dir": "MAME2003PLUS",
Expand All @@ -404,7 +404,7 @@
"synopsis": "/mnt/mmc/MUOS/info/catalogue/MBA/text/"
},
{
"dir": "MD",
"dir": "MEGADRIVE",
"id": "1",
"name": "Sega Genesis (Mega Drive)",
"box": "/mnt/mmc/MUOS/info/catalogue/Sega Mega Drive - Genesis/box/",
Expand Down Expand Up @@ -684,7 +684,7 @@
"synopsis": "/mnt/mmc/MUOS/info/catalogue/Atari 7800/text/"
},
{
"dir": "SFC",
"dir": "SNES",
"id": "4",
"name": "Super Nintendo (SNES)",
"box": "/mnt/mmc/MUOS/info/catalogue/Nintendo SNES-SFC/box/",
Expand Down
92 changes: 55 additions & 37 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import concurrent.futures
import json
import logging
import os
Expand All @@ -21,7 +22,7 @@
get_user_data,
)

VERSION = "1.0.3"
VERSION = "1.0.4"

selected_position = 0
roms_selected_position = 0
Expand Down Expand Up @@ -59,7 +60,15 @@ def load_config(self, config_file):
with open(config_file, "r") as file:
file_contents = file.read()

self.config = json.loads(file_contents)
try:
self.config = json.loads(file_contents)
except json.JSONDecodeError as e:
logger.log_error(f"Error loading config file: {e}")
self.gui.draw_log("Your config.json file is not a valid json file...")
self.gui.draw_paint()
time.sleep(self.LOG_WAIT)
sys.exit()

self.roms_path = self.config.get("roms")
self.systems_logo_path = self.config.get("logos")
self.colors = self.config.get("colors")
Expand All @@ -72,6 +81,7 @@ def load_config(self, config_file):
self.preview_enabled = self.content["preview"]["enabled"]
self.synopsis_enabled = self.content["synopsis"]["enabled"]
self.threads = self.config.get("threads")
self.get_user_threads()
for system in self.config["screenscraper"]["systems"]:
self.systems_mapping[system["dir"].lower()] = system

Expand Down Expand Up @@ -180,7 +190,7 @@ def load_emulators(self) -> None:

self.gui.draw_clear()
self.gui.draw_rectangle_r([10, 40, 630, 440], 15)
self.gui.draw_text((320, 20), "Artie Scraper v1.0.2", anchor="mm")
self.gui.draw_text((320, 20), f"Artie Scraper v{VERSION}", anchor="mm")

if not Path(self.roms_path).exists() or not any(Path(self.roms_path).iterdir()):
self.gui.draw_log("Wrong Roms path, check config.json")
Expand Down Expand Up @@ -262,7 +272,6 @@ def is_valid_rom(self, rom):
def save_file_to_disk(self, data, destination):
check_destination(destination)
destination.write_bytes(data)
self.gui.draw_log("Scraping completed!")
logger.log_debug(f"Saved file to {destination}")
return True

Expand Down Expand Up @@ -303,6 +312,19 @@ def scrape(self, rom, system_id):

return scraped_box, scraped_preview, scraped_synopsis

def process_rom(self, rom, system_id, box_dir, preview_dir, synopsis_dir):
scraped_box, scraped_preview, scraped_synopsis = self.scrape(rom, system_id)
if scraped_box:
destination: Path = box_dir / f"{rom.name}.png"
self.save_file_to_disk(scraped_box, destination)
if scraped_preview:
destination: Path = preview_dir / f"{rom.name}.png"
self.save_file_to_disk(scraped_preview, destination)
if scraped_synopsis:
destination: Path = synopsis_dir / f"{rom.name}.txt"
self.save_file_to_disk(scraped_synopsis.encode("utf-8"), destination)
return scraped_box, scraped_preview, scraped_synopsis, rom.name

def load_roms(self) -> None:
global selected_position, current_window, roms_selected_position, skip_input_check, selected_system

Expand Down Expand Up @@ -379,20 +401,15 @@ def load_roms(self) -> None:
self.gui.draw_log("Scraping...")
self.gui.draw_paint()
rom = roms_to_scrape[roms_selected_position]
scraped_box, scraped_preview, scraped_synopsis = self.scrape(rom, system_id)
if scraped_box:
destination: Path = box_dir / f"{rom.name}.png"
self.save_file_to_disk(scraped_box, destination)
if scraped_preview:
destination: Path = preview_dir / f"{rom.name}.png"
self.save_file_to_disk(scraped_preview, destination)
if scraped_synopsis:
destination: Path = synopsis_dir / f"{rom.name}.txt"
self.save_file_to_disk(scraped_synopsis.encode("utf-8"), destination)
scraped_box, scraped_preview, scraped_synopsis, _ = self.process_rom(
rom, system_id, box_dir, preview_dir, synopsis_dir
)

if not scraped_box and not scraped_preview and not scraped_synopsis:
self.gui.draw_log("Scraping failed!")
logger.log_error(f"Failed to get screenshot for {rom.name}")
else:
self.gui.draw_log("Scraping completed!")
self.gui.draw_paint()
time.sleep(self.LOG_WAIT)
exit_menu = True
Expand All @@ -402,30 +419,31 @@ def load_roms(self) -> None:
failure: int = 0
self.gui.draw_log(f"Scraping {progress} of {len(roms_to_scrape)}")
self.gui.draw_paint()
for rom in roms_to_scrape:
scraped_box, scraped_preview, scraped_synopsis = self.scrape(
rom, system_id
)
if scraped_box:
destination: Path = box_dir / f"{rom.name}.png"
self.save_file_to_disk(scraped_box, destination)
if scraped_preview:
destination: Path = preview_dir / f"{rom.name}.png"
self.save_file_to_disk(scraped_preview, destination)
if scraped_synopsis:
destination: Path = synopsis_dir / f"{rom.name}.txt"
self.save_file_to_disk(
scraped_synopsis.encode("utf-8"), destination
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
logger.log_debug(f"Available threads: {self.threads}")
futures = {
executor.submit(
self.process_rom,
rom,
system_id,
box_dir,
preview_dir,
synopsis_dir,
): rom
for rom in roms_to_scrape
}
for future in concurrent.futures.as_completed(futures):
scraped_box, scraped_preview, scraped_synopsis, rom_name = (
future.result()
)
if scraped_box or scraped_preview or scraped_synopsis:
success += 1
else:
self.gui.draw_log("Scraping failed!")
logger.log_error(f"Failed to get screenshot for {rom.name}")
failure += 1
progress += 1
self.gui.draw_log(f"Scraping {progress} of {len(roms_to_scrape)}")
self.gui.draw_paint()
if scraped_box or scraped_preview or scraped_synopsis:
success += 1
else:
logger.log_error(f"Failed to get screenshot for {rom_name}")
failure += 1
progress += 1
self.gui.draw_log(f"Scraping {progress} of {len(roms_to_scrape)}")
self.gui.draw_paint()
self.gui.draw_log(
f"Scraping completed! Success: {success} Errors: {failure}"
)
Expand Down

0 comments on commit 3ea19dc

Please sign in to comment.