\r
## Installation guide\r
\r
-To run make sure to have a python interpreter.\r
+To install clone the repository and use pip to install it.\r
```sh\r
-pip install -r requirements.txt\r
-python announcer.pyw\r
+git clone https://github.com/IHasPeks/peks-announcer\r
+cd peks-announcer\r
+pip install .\r
+```\r
+\r
+If developing on this, install it using editable mode instead\r
+```sh\r
+pip install -e .\r
```\r
+++ /dev/null
-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_())
--- /dev/null
+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,
+}
--- /dev/null
+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
--- /dev/null
+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()
--- /dev/null
+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()
+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
--- /dev/null
+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/**"],
+ }
+)