PK!QS mdiscordrp_pcsx2/__init__.py"""Discord Rich Presence support for PCSX2. Usage: discordrp_pcsx2 [--path=] Options: --path= Path to your PCSX2 directory, optional. """ __version__ = '0.1.0' import getpass import time from docopt import docopt from pypresence import Presence from .utils import latest_game presence = Presence('540759287379525632') presence.connect() def main(): start = int(time.time()) arguments = docopt(__doc__, version=f'discordrp_pcsx2 {__version__}') path = arguments.get('--path') if path is None: path = f'/home/{getpass.getuser()}/.config/PCSX2' while True: game = latest_game(path) presence.update( large_image=game.image, large_text=game.description, small_image='pcsx2', small_text='PCSX2 Emulator', details=game.description, start=start ) time.sleep(15) PK!/4discordrp_pcsx2/utils.pyimport re from os import SEEK_END, SEEK_SET from typing import Optional game_pattern = re.compile(r'cdrom0:\\+([A-Z_0-9.]+);') meta_pattern = ''' Serial = {0} Name = (.*?) ''' class Game: """Class representing a displayed game.""" def __init__(self, path: str, line: Optional[str] = None): self.path = path self.image = 'pcsx2' self.description = 'Idle' if line is not None: if self.check_line(line): self.parse_line(line) def parse_line(self, line: str): """Get game data from a ROM log.""" game_id = '' match = game_pattern.search(line) if match is not None: game_id = match.group(1).replace('_', '-').replace('.', '') with open(f'{self.path}/bin/GameIndex.dbf') as file: metadata = file.read() match = re.search( meta_pattern.format(game_id), metadata ) if match is not None: name = match.group(1) self.description = name self.image = game_id.lower() @staticmethod def check_line(line: str) -> bool: """Check if a line contains a valid Game.""" return ( game_pattern.search(line) is not None ) def latest_game(path: str) -> Optional[Game]: "Find the latest loaded game from emuLog.txt." line = '' log_file = open(f'{path}/bin/logs/emuLog.txt') for block in _reverse_read(log_file): for char in block: if char == '\n' and line: if Game.check_line(line): return Game(line=line, path=path) line = '' line += char if Game.check_line(line): return Game(line=line, path=path) else: return Game(path=path) def _reverse_read(file): """Read file in reverse order.""" file.seek(0, SEEK_END) location = file.tell() while location > 0: delta = min(4096, location) location -= delta file.seek(location, SEEK_SET) yield file.read(delta) PK!HF4/80discordrp_pcsx2-0.1.0.dist-info/entry_points.txtN+I/N.,()J,N/J)*-H.0|<..PK!HڽTU%discordrp_pcsx2-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HW"(discordrp_pcsx2-0.1.0.dist-info/METADATARn0W,d6ڇ>Rȣ 1-o,$Fߵd8iKuX3(JJ|91̕:.}C2y,3Q>9C« s_gs8N 9~@F?U 2JW9nɏ`siWEh˻O9ޱibXx&(cੲ`/^v8W8der(×0x^-h Akf}D6sLs~[u.JS{pӋ>CIUJr\Xu7R"wxBTyxEw!=`^Ӻ8R9mM v迆a6* M]KTPK!Hڠ5&discordrp_pcsx2-0.1.0.dist-info/RECORDϻr@gA""% l\dIL?'$ۼm@&RfHJ>%JStmo\a#,)( Q/dG!"