2021-01-15 23:01:23 +02:00
# -*- coding: utf-8 -*-
import subprocess
2021-01-21 14:00:58 +02:00
import contextlib
import importlib
2021-01-15 23:01:23 +02:00
import time
import datetime
import os
import pathlib
import json
import getopt
import sys
from random import randint
from pathlib import Path
from datetime import datetime , date , timedelta
2021-01-21 14:00:58 +02:00
from functions import *
2021-01-15 23:01:23 +02:00
2021-01-21 14:00:58 +02:00
if getConfig ( " use_colors " ) :
from colors import *
2021-04-24 03:08:43 +03:00
appendLog ( ' Colors imported ' )
2021-01-21 14:00:58 +02:00
else :
RESET = ' '
BLACK = RED = GREEN = YELLOW = BLUE = MAGENTA = CYAN = WHITE = ' '
BBLACK = BRED = BGREEN = BYELLOW = BBLUE = BMAGENTA = BCYAN = BWHITE = ' '
ULINE = REVERSE = ' '
2021-04-24 03:08:43 +03:00
appendLog ( ' Loading without colors ' )
2021-01-15 23:01:23 +02:00
2021-04-30 03:25:36 +03:00
sysname = getOS ( )
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
clear ( )
setTitle ( " Загрузка daemon... " , sysname )
appendLog ( ' daemon.py start initialized ' , startup = True )
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
import libinstaller
import rpc
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
if sysname == " windows " :
import easygui
import tkinter
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
import keyboard
import ast
import inputimeout
import telegram_send
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
menu_choose = None
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
try :
from inputimeout import inputimeout , TimeoutOccurred
appendLog ( ' inputimeout imported ' )
except Exception as exp :
appendLog ( f ' Failed to import inputimeout: { exp } ' )
print ( f ' [ { YELLOW } WARN { RESET } ] Н е удалось импортировать классы " inputimeout " и " TimeoutOccurred " из модуля " inputimeout " ' )
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
def nowtime ( seconds = True , noice = True , color = True ) :
now = datetime . now ( )
if seconds == True :
justnow = now . strftime ( " % H: % M: % S " )
else :
justnow = now . strftime ( " % H: % M " )
if noice == True :
if not color :
beautiful = f ' [ { justnow } ] '
else :
beautiful = f ' [ { CYAN } { justnow } { RESET } ] '
else :
if not color :
beautiful = f ' { justnow } '
else :
beautiful = f ' { CYAN } { justnow } { RESET } '
return beautiful
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
def act ( x ) :
return x + 10
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
def waitStart ( runTime , action ) :
from datetime import datetime , time
from time import sleep
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
startTime = time ( * ( map ( int , runTime . split ( ' : ' ) ) ) )
while startTime > datetime . today ( ) . time ( ) :
sleep ( 2 )
return action
def getPair ( line ) :
key , sep , value = line . strip ( ) . partition ( " " )
return int ( key ) , value
2021-01-21 14:00:58 +02:00
2021-04-30 03:25:36 +03:00
def getLessons ( ) :
if not os . path . exists ( files_folder + ' lessons.json ' ) :
appendLog ( ' File lessons.json does not exist ' )
with open ( files_folder + ' lessons.json ' , ' w ' , encoding = " utf-8 " ) as f :
f . write ( " [] " )
f . close ( )
lessons_list = [ ]
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
appendLog ( f ' Created lessons.json ' )
else :
with open ( files_folder + ' lessons.json ' , encoding = " utf-8 " ) as json_file :
lessons_list = json . load ( json_file )
json_file . close ( )
appendLog ( ' File lessons.json loaded ' )
return lessons_list
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
def tgsend ( enabled , message ) :
if enabled :
if os . path . exists ( files_folder + ' telegram.conf ' ) :
tg_file = open ( files_folder + ' telegram.conf ' , ' r ' , encoding = " utf-8 " )
tg_text = tg_file . read ( )
if tg_text != ' Not Configured ' :
try :
telegram_send . send ( messages = [ f " { message } " ] , parse_mode = " markdown " , conf = files_folder + " telegram.conf " )
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
except Exception as excep :
appendLog ( f ' Failed to send TG message " { message } " : { exp } ' )
playSound ( " warning " , nowtime ( ) )
print ( f ' { nowtime ( ) } Н е удалось отправить Telegram сообщение " { message } " (Ошибка: { exp } ) ' )
2021-01-21 14:00:58 +02:00
2021-01-15 23:01:23 +02:00
def main ( source = ' deamon ' ) :
2021-04-06 01:32:55 +03:00
2021-04-30 03:25:36 +03:00
global sysname
2021-04-06 01:32:55 +03:00
##########################################
# Возможность профилей сделана для себя
# и не планируется как фича, однако
# вы можете присобачить сюда что хотите.
try :
from profile import profilename
except :
profilename = ' '
pass
##########################################
2021-01-15 23:01:23 +02:00
try :
2021-01-21 14:00:58 +02:00
import time
2021-01-15 23:01:23 +02:00
from main import mainMenu
clear ( )
2021-01-21 14:00:58 +02:00
2021-04-30 03:25:36 +03:00
setTitle ( " AutoZoom (Демон) " , sysname )
2021-04-24 03:08:43 +03:00
appendLog ( ' Main daemon opened ' )
2021-01-15 23:01:23 +02:00
import webbrowser
2021-01-22 14:53:33 +02:00
if ( getConfig ( " obs_core " ) or getConfig ( " obs_exe " ) ) == None :
2021-01-21 14:00:58 +02:00
clear ( )
2021-01-22 14:53:33 +02:00
while True :
obs_choice = input ( f ' { RESET } Хотите использовать запись через OBS? { RESET } ( { BGREEN } Да { RESET } / { BRED } Нет { RESET } ): ' )
2021-04-30 03:25:36 +03:00
if obs_choice . lower ( ) in yes_list :
2021-01-22 14:53:33 +02:00
with open ( f " { files_folder } config.json " , encoding = " utf-8 " ) as json_file :
config_list = json . load ( json_file )
2021-04-06 01:32:55 +03:00
json_file . close ( )
2021-01-22 14:53:33 +02:00
while True :
try :
filename = easygui . fileopenbox ( ' Выберите путь до obs32.exe или obs64.exe ' )
if filename . find ( " obs64.exe " ) != - 1 :
2021-04-30 03:25:36 +03:00
setConfig ( " obs_exe " , filename )
setConfig ( " obs_core " , filename [ : - 9 ] )
2021-01-22 14:53:33 +02:00
print ( f ' Сохранены пути для OBS: \n Приложение: { BRED } { filename } { RESET } \n Корневая папка: { BRED } { filename [ : - 9 ] } { RESET } ' )
time . sleep ( 3 )
break
elif filename . find ( " obs32.exe " ) != - 1 :
2021-04-30 03:25:36 +03:00
setConfig ( " obs_exe " , filename )
setConfig ( " obs_core " , filename [ : - 9 ] )
2021-01-22 14:53:33 +02:00
print ( f ' Сохранены пути для OBS: \n Приложение: { BRED } { filename } { RESET } \n Корневая папка: { BRED } { filename [ : - 9 ] } { RESET } ' )
time . sleep ( 3 )
break
elif filename . find ( " obs.exe " ) != - 1 :
2021-04-30 03:25:36 +03:00
setConfig ( " obs_exe " , filename )
setConfig ( " obs_core " , filename [ : - 7 ] )
2021-01-22 14:53:33 +02:00
print ( f ' Сохранены пути для OBS: \n Приложение: { BRED } { filename } { RESET } \n Корневая папка: { BRED } { filename [ : - 7 ] } { RESET } ' )
time . sleep ( 3 )
break
else :
easygui . msgbox ( " Неверный путь " )
2021-01-15 23:01:23 +02:00
break
2021-04-30 03:25:36 +03:00
2021-04-24 03:08:43 +03:00
except Exception as exp :
2021-01-22 14:53:33 +02:00
none = input ( ' Вы не выбрали верный путь для OBS. \n \n > ' )
2021-04-30 03:25:36 +03:00
setConfig ( " obs_exe " , " Disabled " )
setConfig ( " obs_core " , " Disabled " )
2021-04-24 03:08:43 +03:00
appendLog ( f ' Could not select path to OBS: { exp } ' )
2021-01-22 14:53:33 +02:00
clear ( )
2021-01-15 23:01:23 +02:00
break
2021-01-22 14:53:33 +02:00
break
2021-04-30 03:25:36 +03:00
elif obs_choice . lower ( ) in no_list :
setConfig ( " obs_exe " , " Disabled " )
setConfig ( " obs_core " , " Disabled " )
2021-04-06 01:32:55 +03:00
2021-01-22 14:53:33 +02:00
clear ( )
break
2021-04-30 03:25:36 +03:00
2021-01-22 14:53:33 +02:00
else :
clear ( )
continue
2021-01-15 23:01:23 +02:00
if not os . path . exists ( files_folder + ' telegram.conf ' ) :
2021-01-21 14:00:58 +02:00
clear ( )
2021-01-22 14:53:33 +02:00
tg_choice = input ( f ' { RESET } Хотите использовать Telegram бота? { RESET } ( { BGREEN } Да { RESET } / { BRED } Нет { RESET } ): ' )
2021-04-30 03:25:36 +03:00
if tg_choice . lower ( ) in yes_list :
2021-01-15 23:01:23 +02:00
clear ( )
2021-01-21 14:00:58 +02:00
print ( f ' Пожалуйста, прочтите инструкцию по установке Telegram бота в { BRED } README.txt { RESET } ' )
print ( f ' или в документации/инструкции что в разделе { CYAN } Помощь { RESET } главного меню ' )
print ( f ' чтобы хорошо понимать что сейчас от вас нужно. ' )
none = input ( ' \n > ' )
2021-01-15 23:01:23 +02:00
clear ( )
2021-01-21 14:00:58 +02:00
while True :
clear ( )
2021-04-24 03:08:43 +03:00
2021-01-21 14:00:58 +02:00
try :
telegram_send . configure ( files_folder + ' telegram.conf ' , channel = False , group = False , fm_integration = False )
break
2021-04-24 03:08:43 +03:00
except Exception as exp :
appendLog ( f ' Failed to configure Telegram Send: { exp } ' )
2021-01-21 14:00:58 +02:00
clear ( )
continue
2021-04-24 03:08:43 +03:00
2021-01-21 14:00:58 +02:00
telegram_send . send ( messages = [ f " 🎊 Конфигурация правильна, всё работает! " ] , parse_mode = " markdown " , conf = f " { files_folder } telegram.conf " )
2021-04-24 03:08:43 +03:00
appendLog ( ' Telegram Send successfully configured ' )
2021-01-21 14:00:58 +02:00
clear ( )
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
elif tg_choice . lower ( ) in no_list :
2021-01-21 14:00:58 +02:00
with open ( files_folder + ' telegram.conf ' , ' w ' , encoding = " utf-8 " ) as f :
f . write ( ' Not Configured ' )
2021-04-06 01:32:55 +03:00
f . close ( )
2021-04-24 03:08:43 +03:00
2021-01-15 23:01:23 +02:00
lessons_count = 0
try :
if getConfig ( " debug " ) :
2021-01-21 14:00:58 +02:00
print ( f ' { nowtime ( ) } Конфигурация импортирована \n ' )
2021-01-15 23:01:23 +02:00
except :
2021-01-21 14:00:58 +02:00
print ( f ' { nowtime ( ) } Конфигурация { BRED } отсутсвует { RESET } , выключаем отладку \n ' )
2021-01-15 23:01:23 +02:00
for les in getLessons ( ) :
2021-01-21 14:00:58 +02:00
try :
lessons_list = getLessons ( )
2021-01-15 23:01:23 +02:00
2021-01-21 14:00:58 +02:00
lesson_name = les [ " name " ]
lesson_date = les [ " date " ]
lesson_time = les [ " time " ]
lesson_url = les [ " link " ]
2021-04-24 03:08:43 +03:00
lesson_url_original = les [ " link " ]
2021-01-21 14:00:58 +02:00
lesson_obs = les [ " record " ]
lesson_repeat = les [ " repeat " ]
2021-04-24 03:08:43 +03:00
2021-01-21 14:00:58 +02:00
try :
lesson_repeat_day = les [ " repeat_day " ]
except :
lesson_repeat_day = ' Н е повторяется'
2021-01-15 23:01:23 +02:00
2021-01-21 14:00:58 +02:00
today = date . today ( ) . strftime ( " %d . % m. % Y " )
2021-01-15 23:01:23 +02:00
2021-05-08 01:28:41 +03:00
diff = ( ( datetime . strptime ( today , " %d . % m. % Y " ) - datetime . strptime ( lesson_date , " %d . % m. % Y " ) ) . days )
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Конференция { CYAN } { lesson_name } { RESET } : Разница дней { BRED } { diff } { RESET } , Повторение { BRED } { lesson_repeat } { RESET } . ' )
if diff > 0 and not lesson_repeat :
if getConfig ( " remove_old " ) :
del lessons_list [ lessons_list . index ( les ) ]
saveJson ( files_folder + ' lessons.json ' , lessons_list )
appendLog ( f ' Old lesson named { lesson_name } removed ' )
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Старая конференция { CYAN } { lesson_name } { RESET } за { CYAN } { lesson_date } { RESET } в { BRED } { lesson_time } { RESET } удалена. ' )
lessons_list = getLessons ( )
elif ( today == lesson_date ) or ( getDayNum ( today ) == lesson_repeat_day ) :
2021-01-21 14:00:58 +02:00
print ( f ' { BBLACK } ================================================ { RESET } \n ' )
2021-01-15 23:01:23 +02:00
2021-04-24 03:08:43 +03:00
print ( f ' { nowtime ( ) } Найдена конференция { CYAN } { lesson_name } { RESET } в { BRED } { lesson_time } { RESET } . Ждём начала... ' )
2021-01-21 14:00:58 +02:00
2021-04-30 03:25:36 +03:00
setTitle ( f ' Ждём начала " { lesson_name } " ' , sysname )
2021-01-21 14:00:58 +02:00
waiting_time_unix = int ( time . time ( ) )
rpc . waitLesson ( lesson_name , waiting_time_unix )
waitStart ( lesson_time , lambda : act ( 100 ) )
2021-04-07 23:57:02 +03:00
try :
2021-04-30 03:25:36 +03:00
if sysname == ' windows ' :
2021-04-07 23:57:02 +03:00
i = 0
2021-04-24 03:08:43 +03:00
if i == 0 :
lesson_url = lesson_url . replace ( f " https://zoom.us/j/ " , " zoommtg://zoom.us/join?action=join&confno= " )
2021-04-07 23:57:02 +03:00
while i < 10 :
lesson_url = lesson_url . replace ( f " https://us0 { i } web.zoom.us/j/ " , " zoommtg://zoom.us/join?action=join&confno= " )
i + = 1
lesson_url = lesson_url . replace ( " & " , " ^& " )
lesson_url = lesson_url . replace ( " ?pwd " , " ^&pwd " )
if getConfig ( " debug " ) :
2021-04-24 03:08:43 +03:00
print ( f ' { nowtime ( ) } Ориг. ссылка: { BRED } { lesson_url_original } { RESET } ' )
print ( f ' { nowtime ( ) } Измен. ссылка: { BRED } { lesson_url } { RESET } ' )
2021-04-30 03:25:36 +03:00
appendLog ( f ' Replaced link { lesson_url_original } with { lesson_url } ' )
2021-04-07 23:57:02 +03:00
os . system ( f ' start { lesson_url } ' )
else :
i = 0
2021-04-24 03:08:43 +03:00
if i == 0 :
lesson_url = lesson_url . replace ( f " https://zoom.us/j/ " , " zoommtg://zoom.us/join?action=join&confno= " )
2021-04-07 23:57:02 +03:00
while i < 10 :
lesson_url = lesson_url . replace ( f " https://us0 { i } web.zoom.us/j/ " , " zoommtg://zoom.us/join?action=join&confno= " )
i + = 1
lesson_url = lesson_url . replace ( " ?pwd= " , " &pwd= " )
if getConfig ( " debug " ) :
2021-04-24 03:08:43 +03:00
print ( f ' { nowtime ( ) } Ориг. ссылка: { BRED } { lesson_url_original } { RESET } ' )
print ( f ' { nowtime ( ) } Измен. ссылка: { BRED } { lesson_url } { RESET } ' )
2021-04-30 03:25:36 +03:00
appendLog ( f ' Replaced link { lesson_url_original } with { lesson_url } ' )
if sysname == " android " :
os . system ( f ' xdg-open " { lesson_url_original } " ' )
else :
os . system ( f ' xdg-open " { lesson_url } " ' )
2021-04-24 03:08:43 +03:00
except Exception as exep :
appendLog ( f ' Failed to open lesson { lesson_name } in Zoom: { exep } ' )
2021-04-07 23:57:02 +03:00
try :
2021-04-30 03:25:36 +03:00
webbrowser . open ( lesson_url_original )
2021-04-24 03:08:43 +03:00
except Exception as exp :
print ( f ' { nowtime ( ) } Открыть конференцию { CYAN } { lesson_name } { RESET } не удалось ни напрямую, ни в браузере. ' )
appendLog ( f ' Failed to open lesson { lesson_name } in both browser and Zoom: { exp } ' )
2021-04-07 23:57:02 +03:00
2021-01-21 14:00:58 +02:00
easteregg_number = randint ( 1 , 100000 )
2021-04-24 03:08:43 +03:00
2021-01-21 14:00:58 +02:00
if easteregg_number == 69420 :
2021-04-24 03:08:43 +03:00
appendLog ( ' Easteregg summoned ' )
2021-01-21 14:00:58 +02:00
webbrowser . open ( ' https://www.pornhub.com/view_video.php?viewkey=ph5f3eb1e206aa8 ' )
2021-04-24 03:08:43 +03:00
2021-01-21 14:00:58 +02:00
print ( f ' { nowtime ( ) } Ждём { BRED } 10 секунд { RESET } до отслеживания Zoom... ' )
time . sleep ( 10 )
2021-04-07 23:57:02 +03:00
retries = 0
2021-04-24 03:08:43 +03:00
destroy = False
2021-04-07 23:57:02 +03:00
2021-04-30 03:25:36 +03:00
if sysname == " windows " :
while not getState ( ) :
setTitle ( f ' Конференция " { lesson_name } " задерживается ' , sysname )
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Конференция задерживается, ждём... ( { getState ( ) } ) ' )
if retries == 1 :
appendLog ( ' Lesson delay found ' )
time . sleep ( 5 )
retries + = 1
if getConfig ( " debug " ) :
if retries == 2 :
playSound ( " warning " , nowtime ( ) )
tgsend ( getConfig ( " telegram_enabled " ) , f " ⚠ Задержка конференции * { lesson_name } * обнаружена { profilename } " )
if retries == 36 :
playSound ( " warning " , nowtime ( ) )
tgsend ( getConfig ( " telegram_enabled " ) , f " ⚠ Задержка конференции * { lesson_name } * превысила 3 минуты { profilename } " )
print ( f ' { nowtime ( ) } Задержка конференции { CYAN } { lesson_name } { RESET } превысила { BRED } 3 { RESET } минуты ' )
appendLog ( f ' Lesson delay exceeded: { retries } retries ' )
if retries == 120 :
playSound ( " warning " , nowtime ( ) )
tgsend ( getConfig ( " telegram_enabled " ) , f " ⚠ Задержка конференции * { lesson_name } * превысила 10 минут { profilename } " )
print ( f ' { nowtime ( ) } Задержка конференции { CYAN } { lesson_name } { RESET } превысила { BRED } 10 { RESET } минут ' )
appendLog ( f ' Lesson delay exceeded: { retries } retries ' )
if retries == 360 :
if getConfig ( " debug " ) :
playSound ( " warning " , nowtime ( ) )
tgsend ( getConfig ( " telegram_enabled " ) , f " ⚠ Задержка конференции * { lesson_name } * превысила 30 минут, конференция сбошена { profilename } " )
print ( f ' { nowtime ( ) } Задержка конференции { CYAN } { lesson_name } { RESET } превысила { BRED } 30 { RESET } минут, конференция сброшена ' )
else :
playSound ( " warning " , nowtime ( ) )
tgsend ( getConfig ( " telegram_enabled " ) , f " ⚠ Задержка конференции * { lesson_name } * превысила 30 минут, конференция сбошена { profilename } " )
print ( f ' { nowtime ( ) } Задержка конференции { CYAN } { lesson_name } { RESET } превысила { BRED } 30 { RESET } минут, конференция сброшена ' )
appendLog ( f ' Lesson delay exceeded: { retries } retries ' )
playSound ( " ended " , nowtime ( ) )
if lesson_obs :
record_now = False
time . sleep ( 3 )
try :
obs_process . terminate ( )
except Exception as exp :
appendLog ( f ' Failed to stop OBS process: { exp } ' )
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Н е удалось остановить процесс OBS. ' )
if not lesson_repeat :
del lessons_list [ lessons_list . index ( les ) ]
saveJson ( files_folder + ' lessons.json ' , lessons_list )
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Конференция { CYAN } { lesson_name } { RESET } в { BRED } { lesson_time } { RESET } удалена. ' )
print ( f ' \n { BBLACK } ================================================ { RESET } \n \n ' )
firstshow = True
lessons_count = lessons_count + 1
destroy = True
break
2021-04-07 23:57:02 +03:00
2021-04-30 03:25:36 +03:00
continue
record_now = False
lesson_duration = 0
firstshow = True
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
if lesson_obs and not destroy :
try :
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Импортированы клавиши старта и остановки записи ( { YELLOW } { getConfig ( " start " ) } { RESET } и { YELLOW } { getConfig ( " stop " ) } { RESET } ). ' )
start = getConfig ( " start " )
stop = getConfig ( " stop " )
except :
start = ' shift+f7 '
stop = ' shift+f8 '
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Используем стандартные клавиши старта и остановки записи ( { YELLOW } { start } { RESET } и { YELLOW } { stop } { RESET } ). ' )
i = 0
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
while True and not destroy :
while i < 3 :
if getState ( ) :
if firstshow :
try :
start_time_unix = int ( time . time ( ) )
lesson_start = datetime . now ( )
except :
pass
print ( f ' { nowtime ( ) } Захвачена текущая конференция в Zoom. ' )
setTitle ( f ' Идёт конференция " { lesson_name } " ' , sysname )
playSound ( " started " , nowtime ( ) )
tgsend ( getConfig ( " telegram_enabled " ) , f " ▶ Зашёл на конференцию * { lesson_name } * в * { nowtime ( False , False , False ) } * { profilename } " )
appendLog ( f ' Joined lesson { lesson_name } at { nowtime ( False , False , False ) } ' )
rpc . onLesson ( lesson_name , start_time_unix )
if lesson_obs :
try :
obs_process = subprocess . Popen ( getConfig ( " obs_exe " ) , cwd = getConfig ( " obs_core " ) )
appendLog ( f ' Sent instruction to open OBS ' )
time . sleep ( 5 )
except Exception as exp :
appendLog ( f ' Failed to open OBS: { exp } ' )
print ( f ' { nowtime ( ) } Н е удалось открыть OBS для записи. ' )
else :
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Н е включаем OBS для записи. ' )
firstshow = False
if lesson_obs :
if not record_now :
keyboard . press ( start )
time . sleep ( .25 )
keyboard . release ( start )
record_now = True
print ( f ' { nowtime ( ) } Сигнал записи OBS отправлен. ' )
playSound ( " recordstart " , nowtime ( ) )
lesson_duration = ( datetime . now ( ) - lesson_start ) . total_seconds ( )
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Zoom подключён. Конференция идёт уже { BGREEN } { str ( lesson_duration ) } сек { RESET } . ( { BGREEN } { str ( round ( lesson_duration / 60 , 2 ) ) } мин { RESET } .) ' )
time . sleep ( 5 )
continue
else :
i + = 1
appendLog ( f ' CptHost.exe not found, trying again in 10 seconds ' )
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } { BRED } Конференция не обнаружена! { RESET } Повторная проверка через { BRED } 10 { RESET } секунд... ' )
time . sleep ( 10 )
continue
2021-04-24 03:08:43 +03:00
if getConfig ( " debug " ) :
2021-04-30 03:25:36 +03:00
print ( f ' { nowtime ( ) } Zoom отключился. Процесс { BRED } CptHost.exe { RESET } более не существует. ' )
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
appendLog ( f ' CptHost.exe not found, Zoom disconnected ' )
2021-04-24 03:08:43 +03:00
2021-04-30 03:25:36 +03:00
setTitle ( f ' Конференция " { lesson_name } " завершилась ' , sysname )
if getConfig ( " debug " ) :
tgsend ( getConfig ( " telegram_enabled " ) , f " ◀ Конференция * { lesson_name } * длилась * { str ( round ( lesson_duration / 60 , 2 ) ) } * мин. " )
print ( f ' { nowtime ( ) } Конференция длилась { BGREEN } { str ( lesson_duration ) } сек { RESET } . ( { BGREEN } { str ( round ( lesson_duration / 60 , 2 ) ) } мин { RESET } .) ' )
else :
tgsend ( getConfig ( " telegram_enabled " ) , f " ◀ Конференция * { lesson_name } * длилась * { str ( int ( lesson_duration / 60 ) ) } * мин. " )
print ( f ' { nowtime ( ) } Конференция длилась { BGREEN } { str ( lesson_duration ) } сек { RESET } . ( { BGREEN } { str ( int ( lesson_duration / 60 ) ) } мин { RESET } .) ' )
appendLog ( f ' Lesson { lesson_name } duration was { str ( int ( lesson_duration / 60 ) ) } m. ( { str ( lesson_duration ) } s.) ' )
playSound ( " ended " , nowtime ( ) )
2021-04-24 03:08:43 +03:00
if lesson_obs :
2021-04-30 03:25:36 +03:00
keyboard . press ( stop )
time . sleep ( .25 )
keyboard . release ( stop )
print ( f ' { nowtime ( ) } Сигнал остановки записи через OBS отправлен. ' )
playSound ( " recordstop " , nowtime ( ) )
2021-04-24 03:08:43 +03:00
record_now = False
time . sleep ( 3 )
try :
obs_process . terminate ( )
except Exception as exp :
appendLog ( f ' Failed to stop OBS process: { exp } ' )
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Н е удалось остановить процесс OBS. ' )
if not lesson_repeat :
del lessons_list [ lessons_list . index ( les ) ]
saveJson ( files_folder + ' lessons.json ' , lessons_list )
2021-04-30 03:25:36 +03:00
appendLog ( f ' Lesson named { lesson_name } removed ' )
2021-04-24 03:08:43 +03:00
if getConfig ( " debug " ) :
print ( f ' { nowtime ( ) } Конференция { CYAN } { lesson_name } { RESET } в { BRED } { lesson_time } { RESET } удалена. ' )
print ( f ' \n { BBLACK } ================================================ { RESET } \n \n ' )
firstshow = True
lessons_count = lessons_count + 1
break
2021-04-30 03:25:36 +03:00
record_now = False
retries = 0
destroy = False
lessons_list = getLessons ( )
2021-04-07 23:57:02 +03:00
2021-04-30 03:25:36 +03:00
else :
playSound ( " started " , nowtime ( ) )
tgsend ( getConfig ( " telegram_enabled " ) , f " ▶ Присоединился к конференции * { lesson_name } * в * { nowtime ( False , False , False ) } * { profilename } " )
2021-01-21 14:00:58 +02:00
2021-04-30 03:25:36 +03:00
appendLog ( f ' Joined lesson { lesson_name } at { nowtime ( False , False , False ) } ' )
2021-01-15 23:01:23 +02:00
if not lesson_repeat :
2021-01-21 14:00:58 +02:00
del lessons_list [ lessons_list . index ( les ) ]
2021-01-15 23:01:23 +02:00
saveJson ( files_folder + ' lessons.json ' , lessons_list )
2021-04-24 03:08:43 +03:00
appendLog ( f ' Lesson named { lesson_name } removed ' )
2021-01-15 23:01:23 +02:00
2021-01-21 14:00:58 +02:00
if getConfig ( " debug " ) :
2021-04-24 03:08:43 +03:00
print ( f ' { nowtime ( ) } Конференция { CYAN } { lesson_name } { RESET } в { BRED } { lesson_time } { RESET } удалена. ' )
2021-01-15 23:01:23 +02:00
2021-04-30 03:25:36 +03:00
lessons_list = getLessons ( )
2021-04-24 03:08:43 +03:00
2021-01-21 14:00:58 +02:00
except KeyboardInterrupt :
2021-04-24 03:08:43 +03:00
appendLog ( ' Lessons waiting reset ' )
2021-04-30 03:25:36 +03:00
setTitle ( " Ожидание конференции сбошено " , sysname )
2021-01-21 14:00:58 +02:00
if getConfig ( " debug " ) :
2021-04-24 03:08:43 +03:00
print ( f ' { nowtime ( ) } Ожидание конференции сброшено. ' )
2021-01-21 14:00:58 +02:00
else :
print ( ' ' )
2021-04-24 03:08:43 +03:00
2021-01-21 14:00:58 +02:00
time . sleep ( 1 )
pass
2021-01-15 23:01:23 +02:00
time . sleep ( 3 )
2021-04-24 03:08:43 +03:00
appendLog ( ' Could not find any more lessons today ' )
print ( f ' { nowtime ( ) } Конференций нет или же все в списке закончились. ' )
2021-04-30 03:25:36 +03:00
setTitle ( ' Конференции закончились, режим ожидания ' , sysname )
2021-01-15 23:01:23 +02:00
if lessons_count > 0 :
if getConfig ( " shutdown_enabled " ) :
2021-01-21 14:00:58 +02:00
if getConfig ( " end_mode " ) == ' shutdown ' :
try :
2021-04-24 03:08:43 +03:00
tgsend ( getConfig ( " telegram_enabled " ) , f " ⚠ Конференции кончились, автовыключение { profilename } через { str ( getConfig ( ' shutdown_timeout ' ) ) } мин... " )
2021-01-21 14:00:58 +02:00
print ( f ' { nowtime ( ) } Ваш ПК автоматически выключится через { BRED } { str ( getConfig ( " shutdown_timeout " ) ) } мин { RESET } . ' )
2021-04-24 03:08:43 +03:00
appendLog ( f ' Shutting PC down in { str ( getConfig ( " shutdown_timeout " ) ) } ' )
2021-04-30 03:25:36 +03:00
playSound ( " shutdown " , nowtime ( ) )
2021-01-21 14:00:58 +02:00
end_unix = int ( time . time ( ) ) + getConfig ( " shutdown_timeout " ) * 60
rpc . shutdown ( end_unix )
shutdown = inputimeout ( prompt = f ' { nowtime ( ) } Нажмите { CYAN } Enter { RESET } чтобы предотвратить выключение ПК... ' , timeout = getConfig ( " shutdown_timeout " ) * 60 )
2021-04-24 03:08:43 +03:00
appendLog ( ' Shutdown aborted ' )
2021-01-21 14:00:58 +02:00
clear ( )
except TimeoutOccurred :
clear ( )
print ( f ' { nowtime ( ) } Время вышло, выключаем ваш ПК... ' )
time . sleep ( 3 )
tgsend ( getConfig ( " telegram_enabled " ) , f " ⚠ Время таймаута исткело, выключаем ваш ПК... " )
time . sleep ( 5 )
2021-04-24 03:08:43 +03:00
appendLog ( ' Shutting PC down ' )
2021-01-21 14:00:58 +02:00
os . system ( " shutdown /s /t 1 " )
# elif getConfig("end_mode") == 'restart':
# from datetime import datetime, time
# from time import sleep
# runTime = "00:00"
# startTime = time(*(map(int, runTime.split(':'))))
# tomorrow = date.today()+timedelta(days=1)
# timestamp = (tomorrow - date(1970, 1, 1)).total_seconds()
# while startTime.total_seconds() > timestamp: #(date.today() + timedelta(days=1)).time():
# sleep(2)
2021-01-15 23:01:23 +02:00
if source == ' deamon ' :
2021-04-24 03:08:43 +03:00
appendLog ( f ' Waiting for any input ' )
rpc . lessonEnded ( )
2021-01-21 14:00:58 +02:00
exit = input ( f ' { nowtime ( ) } Программа завершена! Нажмите { CYAN } Enter { RESET } чтобы выйти... ' )
rpc . disconnect ( )
2021-01-15 23:01:23 +02:00
clear ( )
sys . exit ( )
elif source == ' menu ' :
2021-04-24 03:08:43 +03:00
appendLog ( f ' Waiting for any input ' )
rpc . lessonEnded ( )
2021-01-21 14:00:58 +02:00
exit = input ( f ' { nowtime ( ) } Программа завершена! Нажмите { CYAN } Enter { RESET } чтобы вернуться в меню... ' )
rpc . inMenu ( )
2021-01-15 23:01:23 +02:00
clear ( )
2021-04-30 03:25:36 +03:00
setTitle ( " AutoZoom (Главная) " , sysname )
2021-01-15 23:01:23 +02:00
return
except KeyboardInterrupt :
if source == ' deamon ' :
2021-04-24 03:08:43 +03:00
appendLog ( f ' Deamon stopped, waiting for any input ' )
rpc . lessonEnded ( )
2021-01-21 14:00:58 +02:00
exit = input ( f ' { nowtime ( ) } Программа остановлена! Нажмите { CYAN } Enter { RESET } чтобы выйти... ' )
rpc . disconnect ( )
2021-01-15 23:01:23 +02:00
clear ( )
sys . exit ( )
elif source == ' menu ' :
2021-04-24 03:08:43 +03:00
appendLog ( f ' Deamon stopped, waiting for any input ' )
rpc . lessonEnded ( )
2021-01-21 14:00:58 +02:00
exit = input ( f ' { nowtime ( ) } Программа остановлена! Нажмите { CYAN } Enter { RESET } чтобы вернуться в меню... ' )
rpc . inMenu ( )
2021-01-15 23:01:23 +02:00
clear ( )
return
if __name__ == ' __main__ ' :
2021-04-30 03:25:36 +03:00
from functions import getOS , setTitle
setTitle ( " AutoZoom (Демон) " , getOS ( ) )
2021-01-15 23:01:23 +02:00
import sys
clear ( )
2021-04-07 23:57:02 +03:00
main ( )