Code cleanup and fix cover image rename regex
This commit is contained in:
@@ -17,10 +17,11 @@
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
from hashlib import md5
|
||||
from json import JSONDecodeError
|
||||
from re import sub
|
||||
from time import time
|
||||
|
||||
from src import shared
|
||||
@@ -35,20 +36,18 @@ class RetroarchSourceIterator(SourceIterator):
|
||||
|
||||
def generator_builder(self) -> SourceIterationResult:
|
||||
added_time = int(time())
|
||||
bad_playlists = set()
|
||||
|
||||
# Get all playlist files, ending in .lpl
|
||||
playlist_files = self.source.config_location["playlists"].glob("*.lpl")
|
||||
|
||||
bad_playlists = set()
|
||||
|
||||
for playlist_file in playlist_files:
|
||||
try:
|
||||
with open(
|
||||
self.source.config_location["playlists"] / playlist_file,
|
||||
with playlist_file.open(
|
||||
encoding="utf-8",
|
||||
) as open_file:
|
||||
playlist_json = json.load(open_file)
|
||||
except (JSONDecodeError, OSError, KeyError):
|
||||
except (JSONDecodeError, OSError):
|
||||
logging.warning("Cannot read playlist file: %s", str(playlist_file))
|
||||
continue
|
||||
|
||||
@@ -68,7 +67,7 @@ class RetroarchSourceIterator(SourceIterator):
|
||||
continue
|
||||
|
||||
# Build game
|
||||
game_id = hashlib.md5(item["path"].encode("utf-8")).hexdigest()
|
||||
game_id = md5(item["path"].encode("utf-8")).hexdigest()
|
||||
|
||||
values = {
|
||||
"source": self.source.id,
|
||||
@@ -82,12 +81,11 @@ class RetroarchSourceIterator(SourceIterator):
|
||||
}
|
||||
|
||||
game = Game(values)
|
||||
additional_data = {}
|
||||
|
||||
# Get boxart
|
||||
boxart_image_name = item["label"] + ".png"
|
||||
boxart_image_name = boxart_image_name.replace("&", "_")
|
||||
boxart_folder_name = playlist_file.name.split(".", 1)[0]
|
||||
boxart_image_name = sub(r"[&\*\/:`<>\?\\\|]", "_", boxart_image_name)
|
||||
boxart_folder_name = playlist_file.stem
|
||||
image_path = (
|
||||
self.source.config_location["thumbnails"]
|
||||
/ boxart_folder_name
|
||||
|
||||
@@ -33,13 +33,13 @@ from src import shared
|
||||
from src.details_window import DetailsWindow
|
||||
from src.game import Game
|
||||
from src.importer.importer import Importer
|
||||
from src.importer.sources.retroarch_source import RetroarchSource
|
||||
from src.importer.sources.bottles_source import BottlesSource
|
||||
from src.importer.sources.flatpak_source import FlatpakSource
|
||||
from src.importer.sources.heroic_source import HeroicSource
|
||||
from src.importer.sources.itch_source import ItchSource
|
||||
from src.importer.sources.legendary_source import LegendarySource
|
||||
from src.importer.sources.lutris_source import LutrisSource
|
||||
from src.importer.sources.retroarch_source import RetroarchSource
|
||||
from src.importer.sources.steam_source import SteamSource
|
||||
from src.logging.setup import log_system_info, setup_logging
|
||||
from src.preferences import PreferencesWindow
|
||||
|
||||
Reference in New Issue
Block a user