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