first commit
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
import argparse
|
||||
import json
|
||||
import time
|
||||
import pprint
|
||||
import random
|
||||
import requests
|
||||
import datetime
|
||||
import glob
|
||||
import threading
|
||||
# import keyboard
|
||||
from pynput import keyboard
|
||||
from threading import Thread, Semaphore
|
||||
from streamlink import Streamlink
|
||||
from fake_useragent import UserAgent
|
||||
from rich.console import Console
|
||||
from rich.live import Live
|
||||
from rich.prompt import Prompt
|
||||
from rich.spinner import Spinner
|
||||
from rich.table import Table
|
||||
from rich.text import Text
|
||||
import subprocess
|
||||
import pty
|
||||
|
||||
|
||||
#import from local file 4 main class
|
||||
from fonction.first_class import RecordTwitch
|
||||
from fonction.first_class import Subtitle_translation
|
||||
from fonction.first_class import IA_generator
|
||||
from fonction.first_class import messageTwitch
|
||||
|
||||
#import from local file secondary fonction
|
||||
from fonction.second_fonction import *
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
os.system('killall python')
|
||||
sys.exit(0)
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
console = Console()
|
||||
|
||||
|
||||
def send_message(tw_acc_pseudo, tw_acc_token, channel_name, Message_text):
|
||||
hprint("green","start send_message")
|
||||
|
||||
command = '-pseudo "'+tw_acc_pseudo+'" -token "'+tw_acc_token+'" -twitchname "'+channel_name+'" -message " Kappa '+Message_text+'"'
|
||||
message_tosend = 'python send_message.py '+command
|
||||
hprint("yellow",f"send message = "+str(message_tosend))
|
||||
#subprocess.run(message_tosend, shell=True)
|
||||
hprint("yellow",f"Finnish send message")
|
||||
|
||||
|
||||
def stop_all():
|
||||
hprint("blue", "Arrêt d'enregistrement twitch.")
|
||||
recordTw.stop()
|
||||
sb_translation.stop()
|
||||
|
||||
def print_help():
|
||||
hprint("PURPLE", "Touche h : pour afficher les commandes")
|
||||
hprint("PURPLE", "Touche q : pour quitter le sript")
|
||||
hprint("PURPLE", "Touche c : Clear le terminal")
|
||||
hprint("PURPLE", "Touche s : envoie un message dans le tchat twitch avec la derniere génération")
|
||||
|
||||
hprint("PURPLE", "Touche u : pour stopper lenregistrement twitch")
|
||||
# hprint("PURPLE", "Touche j : pour start lenregistrement twitch") # pas set
|
||||
|
||||
# hprint("PURPLE", "Touche i : pour start la traduction en text du record") # pas set
|
||||
hprint("PURPLE", "Touche p : pour stopper la traduction en text du record")
|
||||
hprint("PURPLE", "Touche o : liste tout les sous titre créé")
|
||||
|
||||
hprint("PURPLE", "Touche k : lancer une generation de reponse avec ia depuis les traduction")
|
||||
hprint("PURPLE", "Touche l : liste toute les génération")
|
||||
hprint("PURPLE", "Touche m : change le prompt a donner a l'ia")
|
||||
|
||||
def on_press(key):
|
||||
try:
|
||||
if key.char == 'h':
|
||||
hprint("cyan", "Touche 'h' détectée. Help")
|
||||
print_help()
|
||||
elif key.char == 'q': # Si la touche 'q' est pressée, arrête l'écoute
|
||||
hprint("cyan", "Touche 'q' détectée. Fin du programme.")
|
||||
main_loop = False
|
||||
stop_all()
|
||||
return False # Cela arrêtera l'écouteur
|
||||
elif key.char == 'c':
|
||||
hprint("cyan", "Touche 'c' clear terminal")
|
||||
clear_screen()
|
||||
elif key.char == 'u':
|
||||
hprint("cyan", "Touche 'u' détectée. Arrêt de l'enregistrement.")
|
||||
recordTw.stop() # Arrêter l'enregistrement
|
||||
elif key.char == 'p':
|
||||
hprint("cyan", "Touche 'p' détectée. Arrêt de la traduction en text.")
|
||||
sb_translation.stop() # Arrêter l'enregistrement
|
||||
elif key.char == 'k':
|
||||
hprint("cyan", "Touche 'k' imagination réponse")
|
||||
generation_responce()
|
||||
elif key.char == 's':
|
||||
hprint("cyan", "Touche 's' Envoie du message")
|
||||
Message_text = ask_text.getlast_generation()
|
||||
#send_message(tw_acc_pseudo, tw_acc_token, args.twitchname, Message_text)
|
||||
elif key.char == 'o':
|
||||
hprint("cyan", "Touche 'o'liste sous titre")
|
||||
sb_translation.print_allsubtitle()
|
||||
elif key.char == 'l':
|
||||
hprint("cyan", "Touche 'l' liste génération")
|
||||
ask_text.print_allgeneration()
|
||||
elif key.char == 'x':
|
||||
hprint("cyan", "Touche 'x' reload json")
|
||||
ask_text.reload_json()
|
||||
sb_translation.reload_json()
|
||||
elif key.char == 'm':
|
||||
hprint("cyan", "Touche 'm' change prompt ia")
|
||||
ask_text.change_prompt()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
def generation_responce():
|
||||
text_streamer = sb_translation.get_lasttext()
|
||||
hprint("blue", "start IA_generator")
|
||||
ask_text.main_ask(text_streamer)
|
||||
|
||||
def start_keyboard_listener():
|
||||
with keyboard.Listener(on_press=on_press) as listener:
|
||||
listener.join()
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
main_loop = True
|
||||
|
||||
work_directory = "working_bot"
|
||||
os.chdir(work_directory)
|
||||
|
||||
with open("../config/config.json", 'r') as file:
|
||||
config = json.load(file)
|
||||
tw_acc_pseudo = get_value_json("tw_acc_pseudo", config)
|
||||
tw_acc_token = get_value_json("tw_acc_token", config)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-threads', type=int, default=10, help='Number of threads')
|
||||
parser.add_argument('-recordtime', type=int, default=60, help='Time to record')
|
||||
parser.add_argument('-twitchname', type=str, required=True, help='Twitch channel name')
|
||||
args = parser.parse_args()
|
||||
|
||||
hprint("blue", "start loop RecordTwitch")
|
||||
recordTw = RecordTwitch(channel_name=args.twitchname, recordtime=args.recordtime)
|
||||
recordTw.start_recording()
|
||||
|
||||
hprint("blue", "start loop Subtitle_translation")
|
||||
sb_translation = Subtitle_translation("../config/config.json")
|
||||
sb_translation.start_main_loop()
|
||||
|
||||
ask_text = IA_generator("../config/config.json")
|
||||
ask_text.start_main_loop()
|
||||
|
||||
controluser = messageTwitch(args.twitchname)
|
||||
|
||||
print_help()
|
||||
listener_thread = threading.Thread(target=start_keyboard_listener)
|
||||
listener_thread.start() # mise en thread de l'écoute des appuye touche
|
||||
|
||||
|
||||
time.sleep(25)
|
||||
last_generaton = ""
|
||||
while main_loop:
|
||||
hprint("blue", "start main_loop main script")
|
||||
text_streamer = sb_translation.get_lasttext()
|
||||
ask_text.setnew_streamer_word_text(text_streamer)
|
||||
new_genration = ask_text.getlast_generation()
|
||||
|
||||
if new_genration != "" and new_genration != last_generaton:
|
||||
hprint("blue", "Send message -> "+new_genration)
|
||||
# send_message(tw_acc_pseudo, tw_acc_token, args.twitchname, new_genration)
|
||||
controluser.send_message(new_genration)
|
||||
controluser.change_user()
|
||||
last_generaton = new_genration
|
||||
|
||||
time.sleep(25)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user