diff --git a/dailyreleases/parsing.py b/dailyreleases/parsing.py index b7fca13..043d868 100644 --- a/dailyreleases/parsing.py +++ b/dailyreleases/parsing.py @@ -1,6 +1,5 @@ import logging import re -import string from dataclasses import dataclass, field from datetime import datetime, timedelta from enum import Enum @@ -124,7 +123,7 @@ BLACKLISTED = ( ) -def parse_pre(pre: Pre) -> Release: +def parse_pre(pre: Pre, offline=False) -> Release: if re.search("|".join(BLACKLISTED), pre.dirname, flags=re.IGNORECASE): raise ParseError("Contains blacklisted word") @@ -141,12 +140,13 @@ def parse_pre(pre: Pre) -> Release: game_name, *stopwords = re.split("[._-]({})".format("|".join(STOPWORDS + TAGS + HIGHLIGHTS)), rls_name, flags=re.IGNORECASE) - # Prettify game name by substituting word delimiters with spaces and capitalizing each word. - game_name = string.capwords(re.sub("[_-]", " ", game_name)) - # Dots separated by fewer than two letters are not substituted to allow titles like "R.O.V.E.R." - game_name = string.capwords(re.sub("[.]([a-zA-Z]{2,}|[0-9]+)", " \g<1>", game_name)) + # Prettify game name by substituting word delimiters with spaces + game_name = re.sub("[_-]", " ", game_name) + # Only dots separated by at least two character on either side are substituted to allow titles like "R.O.V.E.R." + game_name = re.sub("[.](\w{2,})", " \g<1>", game_name) + game_name = re.sub("(\w{2,})[.]", "\g<1> ", game_name) - # Some stopwords distinguishes two, otherwise identical, releases (e.g. x86/x64) - we call these tags + # Some stopwords distinguishes two otherwise identical releases (e.g. x86/x64) - we call these tags tags = [stopword for stopword in stopwords if re.match("|".join(TAGS), stopword, flags=re.IGNORECASE)] @@ -176,13 +176,6 @@ def parse_pre(pre: Pre) -> Release: logger.info("Offline: %s %s : %s - %s", platform, rls_type, game_name, group) logger.info("Tags: %s. Highlights: %s", tags, highlights) - # Find store links - store_links = stores.find_store_links(game_name) - - # No store link? Probably software and not a game - if not store_links: - raise ParseError("No store link: probably software") - release = Release( dirname=pre.dirname, nfo_link=pre.nfo_link, @@ -192,13 +185,22 @@ def parse_pre(pre: Pre) -> Release: game_name=game_name, type=rls_type, platform=platform, - store_links=store_links, tags=tags, highlights=highlights ) + if offline: + return release + + # Find store links + release.store_links = stores.find_store_links(game_name) + + # No store link? Probably software and not a game + if not release.store_links: + raise ParseError("No store link: probably software") + # If one of the store links we found is to Steam, use their API to get (better) information about the game. - if "Steam" in store_links: + if "Steam" in release.store_links: try: steam.update_info(release) except Exception as e: # a lot of stuff can go wrong with Steam's API, better catch everything diff --git a/tests/test_parse_dirname.py b/tests/test_parse_dirname.py index 1935b45..d8b4bd1 100644 --- a/tests/test_parse_dirname.py +++ b/tests/test_parse_dirname.py @@ -163,13 +163,12 @@ class ParseDirnameTestCase(unittest.TestCase): self.assertEqual(ReleaseType.GAME, p.type) self.assertIn("store.steampowered.com/bundle/232", p.store_links["Steam"]) - def test_steam_denuvo(self): - # "denuvo" occurs in the Steam EULA + def test_denuvo_in_steam_eula(self): pre = Pre("Deus.Ex.Mankind.Divided-CPY", "nfo_link", datetime.now()) p = parsing.parse_pre(pre) self.assertEqual(["DENUVO"], p.highlights) - # "denuvo" occurs in the Steam DRM notice + def test_denuvo_in_steam_drm_notice(self): pre = Pre("Yakuza.0-FAKE", "nfo_link", datetime.now()) p = parsing.parse_pre(pre) self.assertEqual(["DENUVO"], p.highlights) @@ -196,6 +195,21 @@ class ParseDirnameTestCase(unittest.TestCase): p = parsing.parse_pre(pre) self.assertIn("store.steampowered.com/app/971120", p.store_links["Steam"]) + def test_abbreviated_name(self): + pre = Pre("R.O.V.E.R.The.Game-HOODLUM", "nfo_link", datetime.now()) + p = parsing.parse_pre(pre, offline=True) + self.assertEqual("R.O.V.E.R The Game", p.game_name) + + def test_abbreviated_name_splits_single_letter(self): + pre = Pre("Tick.Tock.A.Tale.for.Two-DARKSiDERS", "nfo_link", datetime.now()) + p = parsing.parse_pre(pre, offline=True) + self.assertEqual("Tick Tock A Tale for Two", p.game_name) + + def test_abbreviated_name_splits_single_number(self): + pre = Pre("GTA.5.The.Complete.Edition-TEST", "nfo_link", datetime.now()) + p = parsing.parse_pre(pre, offline=True) + self.assertEqual("GTA 5 The Complete Edition", p.game_name) + if __name__ == '__main__': unittest.main()