Skip to content

Commit

Permalink
Do not download artwork if artwork is already downloaded to increase …
Browse files Browse the repository at this point in the history
…speed and reduce network traffic
  • Loading branch information
DrgnFireYellow committed Dec 28, 2023
1 parent bef2f47 commit cec6de2
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,26 @@ def make_player(gamefile, system, htmlname):
gamedisplayname += " "
logging.info(f"Creating page for {game}")
make_player(gamepath, system, game)
logging.info(f"Checking for artwork for {game}")
artworkpath = os.path.join("artwork", f"{game}.png")
if downloadartwork:
if system in artworksoups:
try:
logging.info(f"Downloading artwork for {game}")
artworkurl = (
artworksoups[system]
.find(string=re.compile(rf"{gamedisplayname}"))
.parent["href"]
)
with open(f"artwork/{game}.png", "wb") as artworkfile:
artworkfile.write(
requests.get(
ARTWORKURLS[system] + artworkurl, timeout=60
).content
if not os.path.exists(artworkpath):
try:
logging.info(f"Downloading artwork for {game}")
artworkurl = (
artworksoups[system]
.find(string=re.compile(rf"{gamedisplayname}"))
.parent["href"]
)
except (TypeError, AttributeError, requests.Timeout):
logging.error(f"Unable to download artwork for {game}")
logging.info(f"Checking for artwork for {game}")
artworkpath = os.path.join("artwork", f"{game}.png")
with open(f"artwork/{game}.png", "wb") as artworkfile:
artworkfile.write(
requests.get(
ARTWORKURLS[system] + artworkurl, timeout=60
).content
)
except (TypeError, AttributeError, requests.Timeout):
logging.error(f"Unable to download artwork for {game}")
logging.info(f"Adding {game} to index")
gamelisttable.add_row(gamedisplayname, game, system)
if os.path.isfile(artworkpath):
Expand Down

0 comments on commit cec6de2

Please sign in to comment.