def _get_games_giant_bomb(self) -> list: ''' Returns a list of PS2Game objects with id, name, and path Used if the user chooses to pull from Giant Bomb database The first result is used and only call for id and name, in json format, limited to 1 result ''' self._get_rom_names() for rom in self.roms: if rom in self.plugin.persistent_cache: logging.debug("DEV: Value was in cache - %s", rom) cached_results = json.loads( self.plugin.persistent_cache.get(rom)) id = cached_results.get("id") name = cached_results.get("name") else: self.plugin.config.cfg.read( os.path.expandvars(config.CONFIG_LOC)) url = QUERY_URL.format( self.plugin.config.cfg.get("Method", "api_key"), urllib.parse.quote(rom)) with urllib.request.urlopen(url) as response: search_results = json.loads(response.read()) logging.debug("DEV: Search results from url request - %s", search_results) id = search_results["results"][0]["id"] name = search_results["results"][0]["name"] self.plugin.persistent_cache[rom] = {"id": id, "name": name} self.games.append( PS2Game(str(id), str(name), str(self.roms.get(rom)))) self.plugin.push_cache() return self.games
def _get_games_giant_bomb(self) -> list: ''' Returns a list of PS2Game objects with id, name, and path Used if the user chooses to pull from Giant Bomb database The first result is used and only call for id and name, in json format, limited to 1 result ''' self._get_rom_names() # Disabled caching until I find a fix for rom in self.roms: #if rom not in self.plugin.persistent_cache: self.plugin.config.cfg.read(os.path.expandvars(config.CONFIG_LOC)) url = QUERY_URL.format( self.plugin.config.cfg.get("Method", "api_key"), urllib.parse.quote(rom)) with urllib.request.urlopen(url) as response: search_results = json.loads(response.read()) logging.debug("search_results from url request are %s", search_results) #self.plugin.persistent_cache[rom] = { "id" : search_results["results"][0]["id"], "name" : search_results["results"][0]["name"] } #logging.debug("Cache value is %s", self.plugin.persistent_cache[rom]) id = search_results["results"][0][ "id"] #self.plugin.persistent_cache[rom]["id"] name = search_results["results"][0][ "name"] #self.plugin.persistent_cache[rom]["name"] self.games.append( PS2Game(str(id), str(name), str(self.roms.get(rom)))) #self.plugin.push_cache() return self.games
def _get_games_database(self) -> list: ''' Returns a list of PS2Game objects with id, name, and path Used if the user chooses to pull from the PCSX2 games database by matching their files' names with the db ''' database_records = self._parse_dbf(False) self._get_rom_names() for rom in self.roms: for key in database_records: if (rom == database_records.get(key).replace(":", "")): self.games.append( PS2Game(str(key), str(database_records.get(key)), str(self.roms.get(rom)))) return self.games
def _get_games_read_iso(self) -> list: ''' Returns a list of PS2Game objects with id, name, and path Use this to read serials from iso's and match them to a name from the db ''' database_records = self._parse_dbf(True) iso = pycdlib.PyCdlib() # Get the serials by reading the iso's directly self.plugin.config.cfg.read(os.path.expandvars(config.CONFIG_LOC)) for root, dirs, files in os.walk(self.plugin.config.cfg.get("Paths", "roms_path")): for file in files: if file.lower().endswith(".iso"): path = os.path.join(root, file) try: iso.open(path) except: logging.exception("DEV: ISO could not be opened - %s", path) continue for child in iso.list_children(iso_path='/'): string = child.file_identifier().decode("utf-8") if re.search(r"\w{4}_\d{3}\.\d{2}|$", string)[0]: parsed_serial = string.replace("_", "-").replace(".", "").replace(";1", "") self.games.append( PS2Game( str(parsed_serial), "", str(path) ) ) break iso.close() # Match the serials to names for game in self.games: for key in database_records: if(game.id == key): game.name = str(database_records.get(key)) return self.games