Fix game name prettifying for abbreviated game names (e.g. R.O.V.E.R).
This commit is contained in:
parent
02ccdfd863
commit
ee52278399
|
@ -1,6 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import string
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from enum import Enum
|
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):
|
if re.search("|".join(BLACKLISTED), pre.dirname, flags=re.IGNORECASE):
|
||||||
raise ParseError("Contains blacklisted word")
|
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)),
|
game_name, *stopwords = re.split("[._-]({})".format("|".join(STOPWORDS + TAGS + HIGHLIGHTS)),
|
||||||
rls_name, flags=re.IGNORECASE)
|
rls_name, flags=re.IGNORECASE)
|
||||||
|
|
||||||
# Prettify game name by substituting word delimiters with spaces and capitalizing each word.
|
# Prettify game name by substituting word delimiters with spaces
|
||||||
game_name = string.capwords(re.sub("[_-]", " ", game_name))
|
game_name = re.sub("[_-]", " ", game_name)
|
||||||
# Dots separated by fewer than two letters are not substituted to allow titles like "R.O.V.E.R."
|
# Only dots separated by at least two character on either side are 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))
|
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
|
tags = [stopword
|
||||||
for stopword in stopwords
|
for stopword in stopwords
|
||||||
if re.match("|".join(TAGS), stopword, flags=re.IGNORECASE)]
|
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("Offline: %s %s : %s - %s", platform, rls_type, game_name, group)
|
||||||
logger.info("Tags: %s. Highlights: %s", tags, highlights)
|
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(
|
release = Release(
|
||||||
dirname=pre.dirname,
|
dirname=pre.dirname,
|
||||||
nfo_link=pre.nfo_link,
|
nfo_link=pre.nfo_link,
|
||||||
|
@ -192,13 +185,22 @@ def parse_pre(pre: Pre) -> Release:
|
||||||
game_name=game_name,
|
game_name=game_name,
|
||||||
type=rls_type,
|
type=rls_type,
|
||||||
platform=platform,
|
platform=platform,
|
||||||
store_links=store_links,
|
|
||||||
tags=tags,
|
tags=tags,
|
||||||
highlights=highlights
|
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 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:
|
try:
|
||||||
steam.update_info(release)
|
steam.update_info(release)
|
||||||
except Exception as e: # a lot of stuff can go wrong with Steam's API, better catch everything
|
except Exception as e: # a lot of stuff can go wrong with Steam's API, better catch everything
|
||||||
|
|
|
@ -163,13 +163,12 @@ class ParseDirnameTestCase(unittest.TestCase):
|
||||||
self.assertEqual(ReleaseType.GAME, p.type)
|
self.assertEqual(ReleaseType.GAME, p.type)
|
||||||
self.assertIn("store.steampowered.com/bundle/232", p.store_links["Steam"])
|
self.assertIn("store.steampowered.com/bundle/232", p.store_links["Steam"])
|
||||||
|
|
||||||
def test_steam_denuvo(self):
|
def test_denuvo_in_steam_eula(self):
|
||||||
# "denuvo" occurs in the Steam EULA
|
|
||||||
pre = Pre("Deus.Ex.Mankind.Divided-CPY", "nfo_link", datetime.now())
|
pre = Pre("Deus.Ex.Mankind.Divided-CPY", "nfo_link", datetime.now())
|
||||||
p = parsing.parse_pre(pre)
|
p = parsing.parse_pre(pre)
|
||||||
self.assertEqual(["DENUVO"], p.highlights)
|
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())
|
pre = Pre("Yakuza.0-FAKE", "nfo_link", datetime.now())
|
||||||
p = parsing.parse_pre(pre)
|
p = parsing.parse_pre(pre)
|
||||||
self.assertEqual(["DENUVO"], p.highlights)
|
self.assertEqual(["DENUVO"], p.highlights)
|
||||||
|
@ -196,6 +195,21 @@ class ParseDirnameTestCase(unittest.TestCase):
|
||||||
p = parsing.parse_pre(pre)
|
p = parsing.parse_pre(pre)
|
||||||
self.assertIn("store.steampowered.com/app/971120", p.store_links["Steam"])
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Reference in a new issue