misc: Use immutable types for constants

This commit is contained in:
Michael Manganiello
2024-12-23 10:57:43 -03:00
parent f3c5e82aa9
commit e38819b916
4 changed files with 63 additions and 57 deletions

View File

@@ -8,7 +8,7 @@ from config.config_manager import config_manager as cm
TAG_REGEX = re.compile(r"\(([^)]+)\)|\[([^]]+)\]")
EXTENSION_REGEX = re.compile(r"\.(([a-z]+\.)*\w+)$")
LANGUAGES = [
LANGUAGES = (
("Ar", "Arabic"),
("Da", "Danish"),
("De", "German"),
@@ -27,9 +27,9 @@ LANGUAGES = [
("Sv", "Swedish"),
("Zh", "Chinese"),
("nolang", "No Language"),
]
)
REGIONS = [
REGIONS = (
("A", "Australia"),
("AS", "Asia"),
("B", "Brazil"),
@@ -57,13 +57,13 @@ REGIONS = [
("UNK", "Unknown"),
("UNL", "Unlicensed"),
("W", "World"),
]
)
REGIONS_BY_SHORTCODE = {region[0].lower(): region[1] for region in REGIONS}
REGIONS_NAME_KEYS = [region[1].lower() for region in REGIONS]
REGIONS_NAME_KEYS = frozenset(region[1].lower() for region in REGIONS)
LANGUAGES_BY_SHORTCODE = {lang[0].lower(): lang[1] for lang in LANGUAGES}
LANGUAGES_NAME_KEYS = [lang[1].lower() for lang in LANGUAGES]
LANGUAGES_NAME_KEYS = frozenset(lang[1].lower() for lang in LANGUAGES)
class CoverSize(Enum):

View File

@@ -36,23 +36,27 @@ from .base_handler import (
FSHandler,
)
# list of known compressed file MIME types
COMPRESSED_MIME_TYPES: Final = [
"application/zip",
"application/x-tar",
"application/x-gzip",
"application/x-7z-compressed",
"application/x-bzip2",
]
# Known compressed file MIME types
COMPRESSED_MIME_TYPES: Final = frozenset(
(
"application/x-7z-compressed",
"application/x-bzip2",
"application/x-gzip",
"application/x-tar",
"application/zip",
)
)
# list of known file extensions that are compressed
COMPRESSED_FILE_EXTENSIONS = [
".zip",
".tar",
".gz",
".7z",
".bz2",
]
# Known file extensions that are compressed
COMPRESSED_FILE_EXTENSIONS = frozenset(
(
".7z",
".bz2",
".gz",
".tar",
".zip",
)
)
FILE_READ_CHUNK_SIZE = 1024 * 8

View File

@@ -721,7 +721,7 @@ class TwitchAuth(MetadataHandler):
return token
PLATFORMS_FIELDS = [
PLATFORMS_FIELDS = (
"id",
"name",
"category",
@@ -730,9 +730,9 @@ PLATFORMS_FIELDS = [
"platform_family.name",
"platform_family.slug",
"platform_logo.url",
]
)
GAMES_FIELDS = [
GAMES_FIELDS = (
"id",
"name",
"slug",
@@ -782,9 +782,9 @@ GAMES_FIELDS = [
"similar_games.cover.url",
"age_ratings.rating",
"videos.video_id",
]
)
SEARCH_FIELDS = ["game.id", "name"]
SEARCH_FIELDS = ("game.id", "name")
# Generated from the following code on https://www.igdb.com/platforms/:
# Array.from(document.querySelectorAll(".media-body a")).map(a => ({
@@ -792,7 +792,7 @@ SEARCH_FIELDS = ["game.id", "name"]
# name: a.innerText
# }))
IGDB_PLATFORM_LIST = [
IGDB_PLATFORM_LIST = (
{"slug": "visionos", "name": "visionOS"},
{"slug": "meta-quest-3", "name": "Meta Quest 3"},
{"slug": "atari2600", "name": "Atari 2600"},
@@ -1009,7 +1009,7 @@ IGDB_PLATFORM_LIST = [
{"slug": "onlive-game-system", "name": "OnLive Game System"},
{"slug": "vc", "name": "Virtual Console"},
{"slug": "airconsole", "name": "AirConsole"},
]
)
IGDB_PLATFORM_CATEGORIES: dict[int, str] = {
0: "Unknown",

View File

@@ -20,34 +20,36 @@ from models.platform import Platform
from models.rom import Rom
from models.user import User
NON_HASHABLE_PLATFORMS = [
"pc",
"win",
"mac",
"linux",
"switch",
"ps3",
"ps4",
"ps4--1",
"ps5",
"wiiu",
"xbox-360",
"xboxone",
"series-x",
"android",
"ios",
"ipad",
"amazon-alexa",
"amazon-fire-tv",
"gear-vr",
"meta-quest-2",
"meta-quest-3",
"oculus-go",
"oculus-quest",
"oculus-rift",
"psvr",
"psvr2",
]
NON_HASHABLE_PLATFORMS = frozenset(
(
"amazon-alexa",
"amazon-fire-tv",
"android",
"gear-vr",
"ios",
"ipad",
"linux",
"mac",
"meta-quest-2",
"meta-quest-3",
"oculus-go",
"oculus-quest",
"oculus-rift",
"pc",
"ps3",
"ps4",
"ps4--1",
"ps5",
"psvr",
"psvr2",
"series-x",
"switch",
"wiiu",
"win",
"xbox-360",
"xboxone",
)
)
class ScanType(Enum):