diff --git a/test/image.png b/test/image.png new file mode 100644 index 0000000..6d9e4d8 Binary files /dev/null and b/test/image.png differ diff --git a/test/main.py b/test/main.py index 01b59cb..3db1529 100644 --- a/test/main.py +++ b/test/main.py @@ -8,6 +8,8 @@ import asyncio class NouvelleFenetre: + is_live = False + client_id = '6h883my3p6ndqozotnl6nsbllyyr3h' # id de l'app oauth_token ='z11zvdhgxvemn2l8kjl1dvczgiyelt' # token de validation, à changer selon l'utilisateur @@ -125,28 +127,36 @@ class NouvelleFenetre: cur.close() cnx.close() - # On configure OBS pour Twitch async def configure_obs_for_twitch(self, twitch_key_from_database): try: if twitch_key_from_database is not None: - print("Connexion à OBS via Websocket avec les paramètres suivants :") - print("Host:", self.obs_host) - print("Port:", self.obs_port) - print("Password:", self.obs_password) - print("Twitch Stream Key:", twitch_key_from_database) + if not self.is_live: + print("Connexion à OBS via Websocket avec les paramètres suivants :") + print("Host:", self.obs_host) + print("Port:", self.obs_port) + print("Password:", self.obs_password) + print("Twitch Stream Key:", twitch_key_from_database) - self.obs_ws = obsws(self.obs_host, self.obs_port, self.obs_password) - self.obs_ws.connect() + self.obs_ws = obsws(self.obs_host, self.obs_port, self.obs_password) + self.obs_ws.connect() - # Démarre le streaming sur Twitch - start_stream_request = obsrequests.StartStreaming(stream_key=twitch_key_from_database) - self.obs_ws.call(start_stream_request) + # Démarre le streaming sur Twitch + start_stream_request = obsrequests.StartStreaming(stream_key=twitch_key_from_database) + self.obs_ws.call(start_stream_request) + + self.is_live = True + else: + # Si déjà en live, arrêter le streaming + print("Arrêt du streaming Twitch.") + self.obs_ws.call(obsrequests.StopStreaming()) + self.obs_ws.disconnect() + self.is_live = False else: print("La clé Twitch est manquante.") - except Exception as e: print(f"Une erreur s'est produite lors de la configuration d'OBS pour Twitch : {e}") + async def initialize_twitch(self): try: twitch = TwitchHelix(self.client_id, self.oauth_token)