From 6f3e9bf3db704acfed4ce88784ef39afb642ebaa Mon Sep 17 00:00:00 2001 From: Georgios Atheridis Date: Sat, 14 Jan 2023 23:55:11 +0000 Subject: [PATCH] Refactored code. Added setup.py installation script. Implemented logging. --- README.md | 12 +- announcer.pyw | 312 ------------------ announcer/__init__.py | 0 announcer/constants.py | 84 +++++ announcer/events.py | 210 ++++++++++++ announcer/main.py | 22 ++ .../sounds}/peks/AllyAce/allyace.mp3 | Bin .../peks/AllyDeath/anallyhasbeenslain1.mp3 | Bin .../peks/AllyDeath/anallyhasbeenslain2.mp3 | Bin .../peks/AllyDoubleKill/doublekill1.mp3 | Bin .../peks/AllyDoubleKill/doublekill2.mp3 | Bin .../yourteamhasdestroyedaninhibitor1.mp3 | Bin .../yourteamhasdestroyedaninhibitor2.mp3 | Bin .../yourinhibitorhasrespawned.mp3 | Bin .../yourinhibitorisrespawningsoon.mp3 | Bin .../peks/AllyKill/anenemyhasbeenslain1.mp3 | Bin .../peks/AllyKill/anenemyhasbeenslain2.mp3 | Bin .../peks/AllyKill/anenemyhasbeenslain3.mp3 | Bin .../sounds}/peks/AllyPentaKill/pentakill1.mp3 | Bin .../sounds}/peks/AllyPentaKill/pentakill2.mp3 | Bin .../peks/AllyQuadraKill/quadrakill.mp3 | Bin .../peks/AllyTripleKill/triplekill.mp3 | Bin .../yourteamhasdestroyedaturret.mp3 | Bin .../sounds}/peks/Defeat/defeat.mp3 | Bin .../sounds}/peks/EnemyAce/enemyace.mp3 | Bin .../peks/EnemyDoubleKill/enemydoublekill.mp3 | Bin .../yourinhibitorhasbeendestroyed1.mp3 | Bin .../yourinhibitorhasbeendestroyed2.mp3 | Bin .../enemyinhibitorhasrespawned.mp3 | Bin .../enemyinhibitorisrespawningsoon.mp3 | Bin .../peks/EnemyPentaKill/enemypentakill.mp3 | Bin .../peks/EnemyQuadraKill/enemyquadrakill.mp3 | Bin .../peks/EnemyTripleKill/enemytriplekill.mp3 | Bin .../yourturrethasbeendestroyed1.mp3 | Bin .../yourturrethasbeendestroyed2.mp3 | Bin .../sounds}/peks/Executed/executed1.mp3 | Bin .../sounds}/peks/Executed/executed2.mp3 | Bin .../sounds}/peks/Executed/executed3.mp3 | Bin .../sounds}/peks/FirstBlood/firstblood.mp3 | Bin .../MinionsSpawning/minionshavespawned.mp3 | Bin .../30secondsuntilminionsspawn.mp3 | Bin .../peks/PlayerDeath/youhavebeenslain1.mp3 | Bin .../peks/PlayerDeath/youhavebeenslain2.mp3 | Bin .../peks/PlayerKill/youhaveslainanenemy1.mp3 | Bin .../peks/PlayerKill/youhaveslainanenemy2.mp3 | Bin .../peks/PlayerKill/youhaveslainanenemy3.mp3 | Bin .../sounds}/peks/Victory/victory.mp3 | Bin .../peks/Welcome/welcometosummonersrift.mp3 | Bin announcer/window.py | 108 ++++++ requirements.txt | 6 +- setup.py | 20 ++ 51 files changed, 457 insertions(+), 317 deletions(-) delete mode 100644 announcer.pyw create mode 100644 announcer/__init__.py create mode 100644 announcer/constants.py create mode 100644 announcer/events.py create mode 100644 announcer/main.py rename {sounds => announcer/sounds}/peks/AllyAce/allyace.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyDeath/anallyhasbeenslain1.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyDeath/anallyhasbeenslain2.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyDoubleKill/doublekill1.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyDoubleKill/doublekill2.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyKill/anenemyhasbeenslain1.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyKill/anenemyhasbeenslain2.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyKill/anenemyhasbeenslain3.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyPentaKill/pentakill1.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyPentaKill/pentakill2.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyQuadraKill/quadrakill.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyTripleKill/triplekill.mp3 (100%) rename {sounds => announcer/sounds}/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 (100%) rename {sounds => announcer/sounds}/peks/Defeat/defeat.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyAce/enemyace.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyDoubleKill/enemydoublekill.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyPentaKill/enemypentakill.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyQuadraKill/enemyquadrakill.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyTripleKill/enemytriplekill.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 (100%) rename {sounds => announcer/sounds}/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 (100%) rename {sounds => announcer/sounds}/peks/Executed/executed1.mp3 (100%) rename {sounds => announcer/sounds}/peks/Executed/executed2.mp3 (100%) rename {sounds => announcer/sounds}/peks/Executed/executed3.mp3 (100%) rename {sounds => announcer/sounds}/peks/FirstBlood/firstblood.mp3 (100%) rename {sounds => announcer/sounds}/peks/MinionsSpawning/minionshavespawned.mp3 (100%) rename {sounds => announcer/sounds}/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 (100%) rename {sounds => announcer/sounds}/peks/PlayerDeath/youhavebeenslain1.mp3 (100%) rename {sounds => announcer/sounds}/peks/PlayerDeath/youhavebeenslain2.mp3 (100%) rename {sounds => announcer/sounds}/peks/PlayerKill/youhaveslainanenemy1.mp3 (100%) rename {sounds => announcer/sounds}/peks/PlayerKill/youhaveslainanenemy2.mp3 (100%) rename {sounds => announcer/sounds}/peks/PlayerKill/youhaveslainanenemy3.mp3 (100%) rename {sounds => announcer/sounds}/peks/Victory/victory.mp3 (100%) rename {sounds => announcer/sounds}/peks/Welcome/welcometosummonersrift.mp3 (100%) create mode 100644 announcer/window.py create mode 100644 setup.py diff --git a/README.md b/README.md index 1ede429..8d2e247 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,14 @@ Changes the default League of Legends announcer using Live Client Data API. Note ## Installation guide -To run make sure to have a python interpreter. +To install clone the repository and use pip to install it. ```sh -pip install -r requirements.txt -python announcer.pyw +git clone https://github.com/IHasPeks/peks-announcer +cd peks-announcer +pip install . +``` + +If developing on this, install it using editable mode instead +```sh +pip install -e . ``` diff --git a/announcer.pyw b/announcer.pyw deleted file mode 100644 index b581336..0000000 --- a/announcer.pyw +++ /dev/null @@ -1,312 +0,0 @@ -import requests -import time -import urllib3 -import audioplayer -import os -import sys -import random -import tkinter -import tkinter.ttk -import threading -from PyQt5 import QtCore, QtGui, QtWidgets - - -if os.name == "posix": - if "XDG_CONFIG_HOME" in os.environ and "XDG_CACHE_HOME" in os.environ: - LOGS_DIR = os.path.join(os.environ["XDG_CACHE_HOME"], "announcer") - elif "HOME" in os.environ: - LOGS_DIR = os.path.join(os.environ["HOME"], ".cache/announcer") - else: - print( - "HOME environment variable is not set, something must be very wrong.", - file=sys.stderr, - ) - sys.exit(1) -elif os.name == "nt": - if "APPDATA" in os.environ: - LOGS_DIR = os.path.join(os.environ["APPDATA"], "announcer") - else: - print( - "APPDATA is not set, something must be very wrong.", - file=sys.stderr, - ) - sys.exit(1) -else: - print("Your OS is not supported", file=sys.stderr) - sys.exit(1) - -SOUNDS_FOLDER = "sounds/" -SOUND_PACKS = os.listdir(SOUNDS_FOLDER) -volume = 100 - - -def play_event_sound(event: str): - global sound_pack - event_sounds = os.path.join(SOUNDS_FOLDER, sound_pack.get(), event) - sound = random.choice(os.listdir(event_sounds)) - ap = audioplayer.AudioPlayer(os.path.join(event_sounds, sound)) - ap.volume = volume - ap.play(block=True) - - -def update_volume(v): - global volume - volume = int(v) - - -def mute(): - global volume_slider - volume_slider.set(0) - - -def play_random_sound(): - global sound_pack - sound_pack_dir = os.path.join(SOUNDS_FOLDER, sound_pack.get()) - events = os.listdir(sound_pack_dir) - event = random.choice(events) - threading.Thread( - target=play_event_sound, - args=(event,), - ).start() - - -def close_script(): - gui.quit() - gui.destroy() - os._exit(0) - - -# Ignore the Unverified HTTPS request warning. -urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - -previous_game_time = 0 -game_time = 0 -previous_event_count = 0 -event_count = 0 - -# Get event count so if the program is started in the middle of the match -# it doesn't play every announcement sound which happened until that point. -try: - # Get all data from the game in JSON format. - all_game_data = requests.get( - 'https://127.0.0.1:2999/liveclientdata/allgamedata', - verify=False - ).json() - events = all_game_data["events"]["Events"] - event_count = len(events) - previous_event_count = event_count -except: - pass - - -def announcer_loop(): - global stop - # File for logging exceptions. - os.makedirs(LOGS_DIR, exist_ok=True) - log_file = open(os.path.join(LOGS_DIR, "logs.txt"), "w") - - global previous_game_time - global game_time - global previous_event_count - global event_count - - global sound_pack - - while True: - try: - # Get all data from the game in JSON format. - all_game_data = requests.get( - 'https://127.0.0.1:2999/liveclientdata/allgamedata', - verify=False - ).json() - - game_time = all_game_data["gameData"]["gameTime"] - events = all_game_data["events"]["Events"] - - # TODO: move some things to only update once per game. - player_name = all_game_data["activePlayer"]["summonerName"] - player_team = "" - team_order_players = [] - team_chaos_players = [] - ally_team_players = [] - enemy_team_players = [] - - # Populate team chaos and team order players lists - # and figure out which team the player is on. - for player in all_game_data["allPlayers"]: - if player["team"] == "ORDER": - team_order_players.append(player["summonerName"]) - if player["summonerName"] == player_name: - player_team = "ORDER" - elif player["team"] == "CHAOS": - team_chaos_players.append(player["summonerName"]) - if player["summonerName"] == player_name: - player_team = "CHAOS" - - # Populate ally and enemy team player lists. - if player_team == "ORDER": - ally_team_players = team_order_players - enemy_team_players = team_chaos_players - elif player_team == "CHAOS": - ally_team_players = team_chaos_players - enemy_team_players = team_order_players - - # Welcome announcement. - if game_time >= 26 and previous_game_time < 26 and game_time < 28: - play_event_sound("Welcome") - # Minions spawning soon. - if game_time >= 36 and previous_game_time < 36 and game_time < 38: - play_event_sound("MinionsSpawningSoon") - - event_count = len(events) - - # Loop over all new events. - for event_index in range(previous_event_count, event_count): - event = events[event_index] - event_name = event["EventName"] - - # Someone got first blood. - if event_name == "ChampionKill" and event_index < event_count - 1 and events[event_index + 1]["EventName"] == "FirstBlood": - play_event_sound("FirstBlood") - event_index += 1 - # Someone got a multikill. - elif event_name == "ChampionKill" and event_index < event_count - 1 and events[event_index + 1]["EventName"] == "Multikill": - multikill = events[event_index + 1]["KillStreak"] - # Ally got a multikill. - if event["KillerName"] in ally_team_players: - if multikill == 2: - play_event_sound("AllyDoubleKill") - elif multikill == 3: - play_event_sound("AllyTripleKill") - elif multikill == 4: - play_event_sound("AllyQuadraKill") - elif multikill == 5: - play_event_sound("AllyPentaKill") - # Enemy got a multikill. - elif event["KillerName"] in enemy_team_players: - if multikill == 2: - play_event_sound("EnemyDoubleKill") - elif multikill == 3: - play_event_sound("EnemyTripleKill") - elif multikill == 4: - play_event_sound("EnemyQuadraKill") - elif multikill == 5: - play_event_sound("EnemyPentaKill") - event_index += 1 - # Someone got a kill. - elif event_name == "ChampionKill": - # Player got a kill. - if event["KillerName"] == player_name: - play_event_sound("PlayerKill") - # Ally got a kill. - elif event["KillerName"] in ally_team_players: - play_event_sound("AllyKill") - # Enemy got a kill. - elif event["KillerName"] in enemy_team_players: - # Player was killed. - if event["VictimName"] == player_name: - play_event_sound("PlayerDeath") - # Ally was killed. - else: - play_event_sound("AllyDeath") - # Someone got executed. - else: - play_event_sound("Executed") - # A team scored an ace. - elif event_name == "Ace": - # Ally team scored an ace. - if event["AcingTeam"] == player_team: - play_event_sound("AllyAce") - # Enemy team scored an ace. - else: - play_event_sound("EnemyAce") - # A turret was killed. - elif event_name == "TurretKilled": - turret_name = event["TurretKilled"] - # Ally team got a turret kill. - if turret_name[7:9] == "T2" and player_team == "ORDER" or turret_name[7:9] == "T1" and player_team == "CHAOS": - play_event_sound("AllyTurretKill") - # Enemy team got a turret kill. - elif turret_name[7:9] == "T1" and player_team == "ORDER" or turret_name[7:9] == "T2" and player_team == "CHAOS": - play_event_sound("EnemyTurretKill") - # A turret was killed. - elif event_name == "InhibKilled": - inhib_name = event["InhibKilled"] - # Ally team got a turret kill. - if inhib_name[9:11] == "T2" and player_team == "ORDER" or inhib_name[9:11] == "T1" and player_team == "CHAOS": - play_event_sound("AllyInhibitorKill") - # Enemy team got a turret kill. - elif inhib_name[9:11] == "T1" and player_team == "ORDER" or inhib_name[9:11] == "T2" and player_team == "CHAOS": - play_event_sound("EnemyInhibitorKill") - # An inhibitor is respawning soon. - elif event_name == "InhibRespawningSoon": - inhib_name = event["InhibRespawningSoon"] - # Ally team's inhibitor is respawning soon. - if inhib_name[9:11] == "T1" and player_team == "ORDER" or inhib_name[9:11] == "T2" and player_team == "CHAOS": - play_event_sound("AllyInhibitorRespawningSoon") - # Enemy team's inhibitor is respawning soon. - elif inhib_name[9:11] == "T2" and player_team == "ORDER" or inhib_name[9:11] == "T1" and player_team == "CHAOS": - play_event_sound("EnemyInhibitorRespawningSoon") - # An inhibitor has respawned. - elif event_name == "InhibRespawned": - inhib_name = event["InhibRespawned"] - # Ally team's inhibitor has respawned. - if inhib_name[9:11] == "T1" and player_team == "ORDER" or inhib_name[9:11] == "T2" and player_team == "CHAOS": - play_event_sound("AllyInhibitorRespawned") - # Enemy team's inhibitor has respawned. - elif inhib_name[9:11] == "T2" and player_team == "ORDER" or inhib_name[9:11] == "T1" and player_team == "CHAOS": - play_event_sound("EnemyInhibitorRespawned") - # Minions have spawned. - elif event_name == "MinionsSpawning": - play_event_sound("MinionsSpawning") - # Game has ended. - elif event_name == "GameEnd": - # Victory - if event["Result"] == "Win": - play_event_sound("Victory") - # Defeat - elif event["Result"] == "Lose": - play_event_sound("Defeat") - # TODO: killing streaks - previous_game_time = game_time - previous_event_count = event_count - except Exception as e: - # Probably not in game or some other catastrophic error. - print(e) - log_file.write(repr(e) + "\n") - log_file.flush() - time.sleep(5) - -class MainWindow(QtWidgets.QMainWindow): - def __init__(self): - super().__init__() - self.setWindowTitle("Peks Announcer") - self.setFixedSize(250, 150) - self.volume_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self) - self.mute_button = QtWidgets.QPushButton("Mute", self) - self.test_volume_button = QtWidgets.QPushButton("Test sound", self) - self.headerlabel = QtWidgets.QLabel("Hello World", self) - self.vollabel = QtWidgets.QLabel("Volume", self) - self.packlabel = QtWidgets.QLabel("Sound Pack:", self) - self.sound_pack = QtWidgets.QComboBox(self) - self.sound_pack.addItems(SOUND_PACKS) - self.central_widget = QtWidgets.QWidget(self) - self.setCentralWidget(self.central_widget) - self.layout = QtWidgets.QGridLayout(self.central_widget) - self.layout.addWidget(self.headerlabel, 0,1) - self.layout.addWidget(self.vollabel, 1,1) - self.layout.addWidget(self.volume_slider, 2,1) - self.layout.addWidget(self.mute_button, 1,0) - self.layout.addWidget(self.test_volume_button, 1,2) - self.layout.addWidget(self.packlabel, 3,0) - self.layout.addWidget(self.sound_pack, 3,1) - def setup_connections(self): - self.volume_slider.valueChanged.connect(update_volume) - self.mute_button.clicked.connect(mute) - self.test_volume_button.clicked.connect(play_random_sound) -if __name__ == '__main__': - app = QtWidgets.QApplication(sys.argv) - window = MainWindow() - window.setup_connections() - window.show() - sys.exit(app.exec_()) diff --git a/announcer/__init__.py b/announcer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/announcer/constants.py b/announcer/constants.py new file mode 100644 index 0000000..15d87aa --- /dev/null +++ b/announcer/constants.py @@ -0,0 +1,84 @@ +import os +import sys + +DIR_NAME = "lol-announcer" + +if os.name == "posix": + if "XDG_CONFIG_HOME" in os.environ and "XDG_CACHE_HOME" in os.environ: + LOGS_DIR = os.path.join(os.environ["XDG_CACHE_HOME"], DIR_NAME, "logs") + SOUNDS_DIR_LOCAL = os.path.join(os.environ["XDG_CONFIG_HOME"], DIR_NAME, "sounds") + elif "HOME" in os.environ: + HOME = os.environ["HOME"] + LOGS_DIR = os.path.join(HOME, ".cache", DIR_NAME, "logs") + SOUNDS_DIR_LOCAL = os.path.join(HOME, ".config", DIR_NAME, "sounds") + else: + print("HOME environment variable is not set.", file=sys.stderr) + sys.exit(1) +elif os.name == "nt": + if "APPDATA" in os.environ: + APPDATA = os.environ["APPDATA"] + LOGS_DIR = os.path.join(APPDATA, DIR_NAME) + LOGS_DIR = os.path.join(APPDATA, DIR_NAME, "logs") + else: + print("APPDATA is not set.", file=sys.stderr) + sys.exit(1) +else: + print("Your OS is not supported.", file=sys.stderr) + sys.exit(1) + + +os.makedirs(LOGS_DIR, exist_ok=True) +os.makedirs(SOUNDS_DIR_LOCAL, exist_ok=True) +SOUNDS_DIR_GLOBAL = os.path.join(os.path.dirname(__file__), "sounds/") + + +SOUND_PACKS = dict() + +for dir in os.listdir(os.path.join(os.path.dirname(__file__), "sounds/")): + SOUND_PACKS[dir] = os.path.join(os.path.dirname(__file__), "sounds/", dir) + +for dir in os.listdir(SOUNDS_DIR_LOCAL): + SOUND_PACKS[dir] = os.path.join(SOUNDS_DIR_LOCAL, dir) + + +LOGS_FILE = os.path.join(LOGS_DIR, "announcer.log") +LOGGING_DICT = { + "version": 1, + "formatters": { + "brief": { + "format": "[%(levelname)s] %(filename)s:%(lineno)d; %(message)s", + }, + "precise": { + "format": "%(asctime)s.%(msecs)03dZ %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s", + "datefmt": "%Y-%m-%dT%H:%M:%S", + }, + }, + "handlers": { + "console": { + "class": "logging.StreamHandler", + "level": "INFO", + "formatter": "brief", + "stream": "ext://sys.stdout", + }, + "file": { + "class": "logging.handlers.RotatingFileHandler", + "level": "WARNING", + "formatter": "precise", + "filename": LOGS_FILE, + "maxBytes": 32 * 1024, + "backupCount": 3, + }, + }, + "loggers": { + "basicLogger": { + "level": "DEBUG", + "handlers": ["console", "file"], + "propagate": "no", + } + }, + "root": { + "level": "DEBUG", + "handlers": ["console", "file"], + }, + "disable_existing_loggers": False, +} diff --git a/announcer/events.py b/announcer/events.py new file mode 100644 index 0000000..8e235a6 --- /dev/null +++ b/announcer/events.py @@ -0,0 +1,210 @@ +import requests +import urllib3 +import urllib3.exceptions +import logging +import time + +logger = logging.getLogger(__name__) + +# Ignore the Unverified HTTPS request warning. +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + + +class Event: + ENDPOINT = "liveclientdata/allgamedata" + + def __init__(self, ip: str = "127.0.0.1", port: int = 2999): + self.ip = ip + self.port = port + self.previous_event_count: int = 0 + self.previous_game_time: int = 0 + self.game_data: dict | None = None + self.new_events: list[str] = [] + + # If the Event class initializes while a game is running + # get all events up till that point, so that we don't send + # events that have already happened. + self._update_events() + + def _update_events(self): + try: + game_data = requests.get( + f"https://{self.ip}:{self.port}/{Event.ENDPOINT}", + verify=False, + ) + except requests.exceptions.ConnectionError as e: + # logger.exception(f"Unable to Connect to League Game. {e}") + self.game_data = None + time.sleep(3) + else: + logger.info("Connected to League Game") + self.game_data = game_data.json() + + @property + def events(self) -> list: + if not self.game_data: + return [] + return self.game_data["events"]["Events"] + + @property + def event_count(self) -> int: + return len(self.events) + + @property + def game_time(self) -> int: + if not self.game_data: + return 0 + return self.game_data["gameData"]["gameTime"] + + def event_polling(self) -> list[str]: + self.new_events = [] + self._update_events() + if not self.game_data: + logger.warning("Polling without game data") + return [] + self.player_name = self.game_data["activePlayer"]["summonerName"] + self.player_team = "" + self.team_order_players = [] + self.team_chaos_players = [] + self.ally_team_players = [] + self.enemy_team_players = [] + + # Populate team chaos and team order players lists + # and figure out which team the player is on. + for player in self.game_data["allPlayers"]: + if player["team"] == "ORDER": + self.team_order_players.append(player["summonerName"]) + if player["summonerName"] == self.player_name: + self.player_team = "ORDER" + elif player["team"] == "CHAOS": + self.team_chaos_players.append(player["summonerName"]) + if player["summonerName"] == self.player_name: + self.player_team = "CHAOS" + + # Populate ally and enemy team player lists. + if self.player_team == "ORDER": + self.ally_team_players = self.team_order_players + self.enemy_team_players = self.team_chaos_players + elif self.player_team == "CHAOS": + self.ally_team_players = self.team_chaos_players + self.enemy_team_players = self.team_order_players + + # Welcome announcement. + if self.game_time >= 26 and self.previous_game_time < 26 and self.game_time < 28: + self.new_events.append("Welcome") + # Minions spawning soon. + if self.game_time >= 36 and self.previous_game_time < 36 and self.game_time < 38: + self.new_events.append("MinionsSpawningSoon") + + # Loop over all new events. + for event_index in range(self.previous_event_count, self.event_count): + event = self.events[event_index] + event_name = event["EventName"] + + # Someone got first blood. + if event_name == "ChampionKill" and event_index < self.event_count - 1 and self.events[event_index + 1]["EventName"] == "FirstBlood": + event_index += 1 + self.new_events.append("FirstBlood") + # Someone got a multikill. + elif event_name == "ChampionKill" and event_index < self.event_count - 1 and self.events[event_index + 1]["EventName"] == "Multikill": + multikill = self.events[event_index + 1]["KillStreak"] + # Ally got a multikill. + if event["KillerName"] in self.ally_team_players: + if multikill == 2: + self.new_events.append("AllyDoubleKill") + elif multikill == 3: + self.new_events.append("AllyTripleKill") + elif multikill == 4: + self.new_events.append("AllyQuadraKill") + elif multikill == 5: + self.new_events.append("AllyPentaKill") + # Enemy got a multikill. + elif event["KillerName"] in self.enemy_team_players: + if multikill == 2: + self.new_events.append("EnemyDoubleKill") + elif multikill == 3: + self.new_events.append("EnemyTripleKill") + elif multikill == 4: + self.new_events.append("EnemyQuadraKill") + elif multikill == 5: + self.new_events.append("EnemyPentaKill") + event_index += 1 + # Someone got a kill. + elif event_name == "ChampionKill": + # Player got a kill. + if event["KillerName"] == self.player_name: + self.new_events.append("PlayerKill") + # Ally got a kill. + elif event["KillerName"] in self.ally_team_players: + self.new_events.append("AllyKill") + # Enemy got a kill. + elif event["KillerName"] in self.enemy_team_players: + # Player was killed. + if event["VictimName"] == self.player_name: + self.new_events.append("PlayerDeath") + # Ally was killed. + else: + self.new_events.append("AllyDeath") + # Someone got executed. + else: + self.new_events.append("Executed") + # A team scored an ace. + elif event_name == "Ace": + # Ally team scored an ace. + if event["AcingTeam"] == self.player_team: + self.new_events.append("AllyAce") + # Enemy team scored an ace. + else: + self.new_events.append("EnemyAce") + # A turret was killed. + elif event_name == "TurretKilled": + turret_name = event["TurretKilled"] + # Ally team got a turret kill. + if turret_name[7:9] == "T2" and self.player_team == "ORDER" or turret_name[7:9] == "T1" and self.player_team == "CHAOS": + self.new_events.append("AllyTurretKill") + # Enemy team got a turret kill. + elif turret_name[7:9] == "T1" and self.player_team == "ORDER" or turret_name[7:9] == "T2" and self.player_team == "CHAOS": + self.new_events.append("EnemyTurretKill") + # A turret was killed. + elif event_name == "InhibKilled": + inhib_name = event["InhibKilled"] + # Ally team got a turret kill. + if inhib_name[9:11] == "T2" and self.player_team == "ORDER" or inhib_name[9:11] == "T1" and self.player_team == "CHAOS": + self.new_events.append("AllyInhibitorKill") + # Enemy team got a turret kill. + elif inhib_name[9:11] == "T1" and self.player_team == "ORDER" or inhib_name[9:11] == "T2" and self.player_team == "CHAOS": + self.new_events.append("EnemyInhibitorKill") + # An inhibitor is respawning soon. + elif event_name == "InhibRespawningSoon": + inhib_name = event["InhibRespawningSoon"] + # Ally team's inhibitor is respawning soon. + if inhib_name[9:11] == "T1" and self.player_team == "ORDER" or inhib_name[9:11] == "T2" and self.player_team == "CHAOS": + self.new_events.append("AllyInhibitorRespawningSoon") + # Enemy team's inhibitor is respawning soon. + elif inhib_name[9:11] == "T2" and self.player_team == "ORDER" or inhib_name[9:11] == "T1" and self.player_team == "CHAOS": + self.new_events.append("EnemyInhibitorRespawningSoon") + # An inhibitor has respawned. + elif event_name == "InhibRespawned": + inhib_name = event["InhibRespawned"] + # Ally team's inhibitor has respawned. + if inhib_name[9:11] == "T1" and self.player_team == "ORDER" or inhib_name[9:11] == "T2" and self.player_team == "CHAOS": + self.new_events.append("AllyInhibitorRespawned") + # Enemy team's inhibitor has respawned. + elif inhib_name[9:11] == "T2" and self.player_team == "ORDER" or inhib_name[9:11] == "T1" and self.player_team == "CHAOS": + self.new_events.append("EnemyInhibitorRespawned") + # Minions have spawned. + elif event_name == "MinionsSpawning": + self.new_events.append("MinionsSpawning") + # Game has ended. + elif event_name == "GameEnd": + # Victory + if event["Result"] == "Win": + self.new_events.append("Victory") + # Defeat + elif event["Result"] == "Lose": + self.new_events.append("Defeat") + # TODO: killing streaks + self.previous_game_time = self.game_time + self.previous_event_count = self.event_count + logger.debug(self.new_events) + return self.new_events diff --git a/announcer/main.py b/announcer/main.py new file mode 100644 index 0000000..dc6df37 --- /dev/null +++ b/announcer/main.py @@ -0,0 +1,22 @@ +import sys +import logging +import logging.config +from .window import MainWindow +from .constants import LOGGING_DICT, SOUND_PACKS +from PyQt5 import QtWidgets + +logging.config.dictConfig(LOGGING_DICT) +logger = logging.getLogger(__name__) + + +def main(): + logger.info(SOUND_PACKS) + app = QtWidgets.QApplication(sys.argv) + window = MainWindow() + window.setup_connections() + window.show() + sys.exit(app.exec_()) + + +if __name__ == "__main__": + main() diff --git a/sounds/peks/AllyAce/allyace.mp3 b/announcer/sounds/peks/AllyAce/allyace.mp3 similarity index 100% rename from sounds/peks/AllyAce/allyace.mp3 rename to announcer/sounds/peks/AllyAce/allyace.mp3 diff --git a/sounds/peks/AllyDeath/anallyhasbeenslain1.mp3 b/announcer/sounds/peks/AllyDeath/anallyhasbeenslain1.mp3 similarity index 100% rename from sounds/peks/AllyDeath/anallyhasbeenslain1.mp3 rename to announcer/sounds/peks/AllyDeath/anallyhasbeenslain1.mp3 diff --git a/sounds/peks/AllyDeath/anallyhasbeenslain2.mp3 b/announcer/sounds/peks/AllyDeath/anallyhasbeenslain2.mp3 similarity index 100% rename from sounds/peks/AllyDeath/anallyhasbeenslain2.mp3 rename to announcer/sounds/peks/AllyDeath/anallyhasbeenslain2.mp3 diff --git a/sounds/peks/AllyDoubleKill/doublekill1.mp3 b/announcer/sounds/peks/AllyDoubleKill/doublekill1.mp3 similarity index 100% rename from sounds/peks/AllyDoubleKill/doublekill1.mp3 rename to announcer/sounds/peks/AllyDoubleKill/doublekill1.mp3 diff --git a/sounds/peks/AllyDoubleKill/doublekill2.mp3 b/announcer/sounds/peks/AllyDoubleKill/doublekill2.mp3 similarity index 100% rename from sounds/peks/AllyDoubleKill/doublekill2.mp3 rename to announcer/sounds/peks/AllyDoubleKill/doublekill2.mp3 diff --git a/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 b/announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 similarity index 100% rename from sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 rename to announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 diff --git a/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 b/announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 similarity index 100% rename from sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 rename to announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 diff --git a/sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 b/announcer/sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 similarity index 100% rename from sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 rename to announcer/sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 diff --git a/sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 b/announcer/sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 similarity index 100% rename from sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 rename to announcer/sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 diff --git a/sounds/peks/AllyKill/anenemyhasbeenslain1.mp3 b/announcer/sounds/peks/AllyKill/anenemyhasbeenslain1.mp3 similarity index 100% rename from sounds/peks/AllyKill/anenemyhasbeenslain1.mp3 rename to announcer/sounds/peks/AllyKill/anenemyhasbeenslain1.mp3 diff --git a/sounds/peks/AllyKill/anenemyhasbeenslain2.mp3 b/announcer/sounds/peks/AllyKill/anenemyhasbeenslain2.mp3 similarity index 100% rename from sounds/peks/AllyKill/anenemyhasbeenslain2.mp3 rename to announcer/sounds/peks/AllyKill/anenemyhasbeenslain2.mp3 diff --git a/sounds/peks/AllyKill/anenemyhasbeenslain3.mp3 b/announcer/sounds/peks/AllyKill/anenemyhasbeenslain3.mp3 similarity index 100% rename from sounds/peks/AllyKill/anenemyhasbeenslain3.mp3 rename to announcer/sounds/peks/AllyKill/anenemyhasbeenslain3.mp3 diff --git a/sounds/peks/AllyPentaKill/pentakill1.mp3 b/announcer/sounds/peks/AllyPentaKill/pentakill1.mp3 similarity index 100% rename from sounds/peks/AllyPentaKill/pentakill1.mp3 rename to announcer/sounds/peks/AllyPentaKill/pentakill1.mp3 diff --git a/sounds/peks/AllyPentaKill/pentakill2.mp3 b/announcer/sounds/peks/AllyPentaKill/pentakill2.mp3 similarity index 100% rename from sounds/peks/AllyPentaKill/pentakill2.mp3 rename to announcer/sounds/peks/AllyPentaKill/pentakill2.mp3 diff --git a/sounds/peks/AllyQuadraKill/quadrakill.mp3 b/announcer/sounds/peks/AllyQuadraKill/quadrakill.mp3 similarity index 100% rename from sounds/peks/AllyQuadraKill/quadrakill.mp3 rename to announcer/sounds/peks/AllyQuadraKill/quadrakill.mp3 diff --git a/sounds/peks/AllyTripleKill/triplekill.mp3 b/announcer/sounds/peks/AllyTripleKill/triplekill.mp3 similarity index 100% rename from sounds/peks/AllyTripleKill/triplekill.mp3 rename to announcer/sounds/peks/AllyTripleKill/triplekill.mp3 diff --git a/sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 b/announcer/sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 similarity index 100% rename from sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 rename to announcer/sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 diff --git a/sounds/peks/Defeat/defeat.mp3 b/announcer/sounds/peks/Defeat/defeat.mp3 similarity index 100% rename from sounds/peks/Defeat/defeat.mp3 rename to announcer/sounds/peks/Defeat/defeat.mp3 diff --git a/sounds/peks/EnemyAce/enemyace.mp3 b/announcer/sounds/peks/EnemyAce/enemyace.mp3 similarity index 100% rename from sounds/peks/EnemyAce/enemyace.mp3 rename to announcer/sounds/peks/EnemyAce/enemyace.mp3 diff --git a/sounds/peks/EnemyDoubleKill/enemydoublekill.mp3 b/announcer/sounds/peks/EnemyDoubleKill/enemydoublekill.mp3 similarity index 100% rename from sounds/peks/EnemyDoubleKill/enemydoublekill.mp3 rename to announcer/sounds/peks/EnemyDoubleKill/enemydoublekill.mp3 diff --git a/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 b/announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 similarity index 100% rename from sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 rename to announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 diff --git a/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 b/announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 similarity index 100% rename from sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 rename to announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 diff --git a/sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 b/announcer/sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 similarity index 100% rename from sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 rename to announcer/sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 diff --git a/sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 b/announcer/sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 similarity index 100% rename from sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 rename to announcer/sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 diff --git a/sounds/peks/EnemyPentaKill/enemypentakill.mp3 b/announcer/sounds/peks/EnemyPentaKill/enemypentakill.mp3 similarity index 100% rename from sounds/peks/EnemyPentaKill/enemypentakill.mp3 rename to announcer/sounds/peks/EnemyPentaKill/enemypentakill.mp3 diff --git a/sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3 b/announcer/sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3 similarity index 100% rename from sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3 rename to announcer/sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3 diff --git a/sounds/peks/EnemyTripleKill/enemytriplekill.mp3 b/announcer/sounds/peks/EnemyTripleKill/enemytriplekill.mp3 similarity index 100% rename from sounds/peks/EnemyTripleKill/enemytriplekill.mp3 rename to announcer/sounds/peks/EnemyTripleKill/enemytriplekill.mp3 diff --git a/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 b/announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 similarity index 100% rename from sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 rename to announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 diff --git a/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 b/announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 similarity index 100% rename from sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 rename to announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 diff --git a/sounds/peks/Executed/executed1.mp3 b/announcer/sounds/peks/Executed/executed1.mp3 similarity index 100% rename from sounds/peks/Executed/executed1.mp3 rename to announcer/sounds/peks/Executed/executed1.mp3 diff --git a/sounds/peks/Executed/executed2.mp3 b/announcer/sounds/peks/Executed/executed2.mp3 similarity index 100% rename from sounds/peks/Executed/executed2.mp3 rename to announcer/sounds/peks/Executed/executed2.mp3 diff --git a/sounds/peks/Executed/executed3.mp3 b/announcer/sounds/peks/Executed/executed3.mp3 similarity index 100% rename from sounds/peks/Executed/executed3.mp3 rename to announcer/sounds/peks/Executed/executed3.mp3 diff --git a/sounds/peks/FirstBlood/firstblood.mp3 b/announcer/sounds/peks/FirstBlood/firstblood.mp3 similarity index 100% rename from sounds/peks/FirstBlood/firstblood.mp3 rename to announcer/sounds/peks/FirstBlood/firstblood.mp3 diff --git a/sounds/peks/MinionsSpawning/minionshavespawned.mp3 b/announcer/sounds/peks/MinionsSpawning/minionshavespawned.mp3 similarity index 100% rename from sounds/peks/MinionsSpawning/minionshavespawned.mp3 rename to announcer/sounds/peks/MinionsSpawning/minionshavespawned.mp3 diff --git a/sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 b/announcer/sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 similarity index 100% rename from sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 rename to announcer/sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 diff --git a/sounds/peks/PlayerDeath/youhavebeenslain1.mp3 b/announcer/sounds/peks/PlayerDeath/youhavebeenslain1.mp3 similarity index 100% rename from sounds/peks/PlayerDeath/youhavebeenslain1.mp3 rename to announcer/sounds/peks/PlayerDeath/youhavebeenslain1.mp3 diff --git a/sounds/peks/PlayerDeath/youhavebeenslain2.mp3 b/announcer/sounds/peks/PlayerDeath/youhavebeenslain2.mp3 similarity index 100% rename from sounds/peks/PlayerDeath/youhavebeenslain2.mp3 rename to announcer/sounds/peks/PlayerDeath/youhavebeenslain2.mp3 diff --git a/sounds/peks/PlayerKill/youhaveslainanenemy1.mp3 b/announcer/sounds/peks/PlayerKill/youhaveslainanenemy1.mp3 similarity index 100% rename from sounds/peks/PlayerKill/youhaveslainanenemy1.mp3 rename to announcer/sounds/peks/PlayerKill/youhaveslainanenemy1.mp3 diff --git a/sounds/peks/PlayerKill/youhaveslainanenemy2.mp3 b/announcer/sounds/peks/PlayerKill/youhaveslainanenemy2.mp3 similarity index 100% rename from sounds/peks/PlayerKill/youhaveslainanenemy2.mp3 rename to announcer/sounds/peks/PlayerKill/youhaveslainanenemy2.mp3 diff --git a/sounds/peks/PlayerKill/youhaveslainanenemy3.mp3 b/announcer/sounds/peks/PlayerKill/youhaveslainanenemy3.mp3 similarity index 100% rename from sounds/peks/PlayerKill/youhaveslainanenemy3.mp3 rename to announcer/sounds/peks/PlayerKill/youhaveslainanenemy3.mp3 diff --git a/sounds/peks/Victory/victory.mp3 b/announcer/sounds/peks/Victory/victory.mp3 similarity index 100% rename from sounds/peks/Victory/victory.mp3 rename to announcer/sounds/peks/Victory/victory.mp3 diff --git a/sounds/peks/Welcome/welcometosummonersrift.mp3 b/announcer/sounds/peks/Welcome/welcometosummonersrift.mp3 similarity index 100% rename from sounds/peks/Welcome/welcometosummonersrift.mp3 rename to announcer/sounds/peks/Welcome/welcometosummonersrift.mp3 diff --git a/announcer/window.py b/announcer/window.py new file mode 100644 index 0000000..9db5be0 --- /dev/null +++ b/announcer/window.py @@ -0,0 +1,108 @@ +import os +import random +import logging + +from .constants import SOUND_PACKS +from .events import Event + +from PyQt5 import QtWidgets +from PyQt5.QtCore import QObject, QThread, QUrl, Qt, pyqtSignal +from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent + + +logger = logging.getLogger(__name__) + + +class EventPlayer(QObject): + # finished = pyqtSignal() + progress = pyqtSignal(str) + + def poll_league(self): + self.lol_events = Event() + while True: + events_in_string = ";".join(self.lol_events.event_polling()) + self.progress.emit(events_in_string) + # self.finished.emit() + + +class MainWindow(QtWidgets.QMainWindow): + def __init__(self): + super().__init__() + self.setWindowTitle("Peks Announcer") + self.setFixedSize(250, 150) + + self.volume_slider = QtWidgets.QSlider(Qt.Horizontal) + self.mute_button = QtWidgets.QPushButton("Mute") + self.test_volume_button = QtWidgets.QPushButton("Test sound") + self.headerlabel = QtWidgets.QLabel("Hello World") + self.vollabel = QtWidgets.QLabel("Volume") + self.packlabel = QtWidgets.QLabel("Sound Pack:") + self.sound_pack = QtWidgets.QComboBox() + self.sound_pack.addItems(SOUND_PACKS) + self.central_widget = QtWidgets.QWidget() + self.setCentralWidget(self.central_widget) + + self.layout = QtWidgets.QGridLayout(self.central_widget) + self.layout.addWidget(self.headerlabel, 0, 1) + self.layout.addWidget(self.vollabel, 1, 1) + self.layout.addWidget(self.volume_slider, 2, 1) + self.layout.addWidget(self.mute_button, 1, 0) + self.layout.addWidget(self.test_volume_button, 1, 2) + self.layout.addWidget(self.packlabel, 3, 0) + self.layout.addWidget(self.sound_pack, 3, 1) + + self.media_player = QMediaPlayer() + + self.event_player = EventPlayer() + self.event_player_thread = QThread() + self.event_player.moveToThread(self.event_player_thread) + + self.event_player_thread.started.connect(self.event_player.poll_league) + # self.event_player.finished.connect(self.thread.quit) + # self.event_player.finished.connect(self.worker.deleteLater) + self.event_player_thread.finished.connect(self.event_player_thread.deleteLater) + self.event_player.progress.connect(self.play_events_sound) + + self.event_player_thread.start() + + def setup_connections(self): + self.volume_slider.valueChanged.connect(self.update_volume) + self.mute_button.clicked.connect(self.mute) + self.test_volume_button.clicked.connect(self.play_random_sound) + + def mute(self): + pass + + def update_volume(self): + pass + + def play_random_sound(self): + sound_pack_dir = SOUND_PACKS[self.sound_pack.currentText()] + events = os.listdir(sound_pack_dir) + try: + event = random.choice(events) + except IndexError as e: + logger.exception(e) + return + self.play_event_sound(event) + + def play_events_sound(self, events: str): + logger.debug(events) + for event in events.split(";"): + if not event: + break + self.play_event_sound(event) + + def play_event_sound(self, event: str): + event_sounds = os.path.join(SOUND_PACKS[self.sound_pack.currentText()], event) + try: + sound = random.choice(os.listdir(event_sounds)) + except IndexError as e: + logger.exception(e) + return + sound_path = os.path.join(event_sounds, sound) + logger.debug(sound_path) + url = QUrl.fromLocalFile(sound_path) + content = QMediaContent(url) + self.media_player.setMedia(content) + self.media_player.play() diff --git a/requirements.txt b/requirements.txt index 9ad84a7..919780d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,10 @@ +announcer==0.0.1 audioplayer==0.6 certifi==2022.12.7 charset-normalizer==3.0.1 idna==3.4 -pycairo==1.23.0 -PyGObject==3.42.2 +PyQt5==5.15.7 +PyQt5-Qt5==5.15.2 +PyQt5-sip==12.11.0 requests==2.28.2 urllib3==1.26.14 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..5c9a5bf --- /dev/null +++ b/setup.py @@ -0,0 +1,20 @@ +from setuptools import setup + +setup( + name="announcer", + version="0.0.1", + packages=["announcer"], + entry_points={ + "console_scripts": [ + "announcer=announcer.main:main", + ], + }, + install_requires=[ + "PyQT5", + "requests", + "audioplayer", + ], + package_data={ + "announcer": ["sounds/**"], + } +) -- 2.30.2