From 7961509acaf07bbed18ebd5d205aff5f27d8dc37 Mon Sep 17 00:00:00 2001 From: lulzette Date: Sun, 13 Nov 2022 12:43:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=88=D0=B5=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B4=D1=80=D1=83=D0=B3=D1=83=D1=8E,=20=D0=B0?= =?UTF-8?q?=D0=BA=D1=82=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20=D0=B1?= =?UTF-8?q?=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D1=83=20=D1=82?= =?UTF-8?q?=D0=B2=D0=B8=D1=87=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- README.md | 9 ++++++++- config_python.py.template | 3 ++- daemon.py | 21 +++++++++++++-------- requirements.txt | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 0352d8d..c25b3a3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ config_python.py config_list.sh __pycache__ .vscode -.idea \ No newline at end of file +.idea +output.log \ No newline at end of file diff --git a/README.md b/README.md index f77547e..aae4b98 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,11 @@ check_period = 5 # Частота проверки стримеров (в сек max_files = 3 # Сколько хранить стримов ``` -* Запустить скрипт в screen'е или создать для него systemd.service файл (или init.d, в зависимости от системы инициализации) \ No newline at end of file +* Запустить скрипт в screen'е или создать для него systemd.service файл (или init.d, в зависимости от системы инициализации) + +# Updates + +## 2022-11-13 + +В связи с переходом на новую библиотеку необходимо указывать 2 переменные авторизации - appid и appsecret. +twitchid это appid, а секретный ключ можно получить или перегенерировать в https://dev.twitch.tv/console \ No newline at end of file diff --git a/config_python.py.template b/config_python.py.template index cac8a9f..dfa3865 100644 --- a/config_python.py.template +++ b/config_python.py.template @@ -1,4 +1,5 @@ -twitchid="....." +appid="" +appsecret="" streamers = ("jesusavgn", "252mart", "vi0xxx") path="/home/losted/test" period = 5 \ No newline at end of file diff --git a/daemon.py b/daemon.py index b67b157..f405ec0 100644 --- a/daemon.py +++ b/daemon.py @@ -9,7 +9,7 @@ from threading import Thread from types import resolve_bases import config_python import schedule -from twitch import TwitchClient +from twitchAPI.twitch import Twitch import subprocess import time import logging @@ -17,7 +17,9 @@ from logging.handlers import TimedRotatingFileHandler from termcolor import colored streamers = config_python.streamers -client_id = config_python.twitchid +app_id = config_python.appid +app_secret = config_python.appsecret + log_format = logging.Formatter('%(asctime)s %(levelname)s:%(message)s') log_file = 'output.log' @@ -84,8 +86,10 @@ def checkAlive(): # Путь до диры со стримами path = config_python.path + "/" + i # Получаем инфо о стримере, если не получается, выходим с ошибкой - resolved_id = client.users.translate_usernames_to_ids(i) - if not resolved_id: + + # resolved_id = client.users.translate_usernames_to_ids(i) + resolved_id = twitch_client.get_users(logins=[i]) + if not resolved_id['data']: log.error( colored( "Аккаунт " + i + " не найден", @@ -98,11 +102,12 @@ def checkAlive(): os.makedirs(path) log.info("Создана директория " + i) # Достаем ID стримера из инфо - user_id = resolved_id[0]['id'] + user_id = resolved_id['data'][0]['id'] + user_stream = twitch_client.get_streams(user_id=user_id) # Если стрим идет, то идем дальше - if client.streams.get_stream_by_user(user_id): + if user_stream['data']: # Если стрим идет и лок файла нет, то записываем и ставим лок - if (client.streams.get_stream_by_user(user_id).stream_type == 'live') and not (os.path.exists(config_python.path+"/"+i+"/pid")): + if (user_stream['data'][0]['type'] == 'live') and not (os.path.exists(config_python.path+"/"+i+"/pid")): log.info(i + " стримит") startRecord(i) open(path+"/pid", 'w').close @@ -177,7 +182,7 @@ if __name__ == "__main__": # Каждый час удалять старые стримы schedule.every(1).hours.do(removeOldStreams) - client = TwitchClient(client_id=client_id) + twitch_client = Twitch(app_id, app_secret) while True: schedule.run_pending() time.sleep(1) diff --git a/requirements.txt b/requirements.txt index 1e4de30..4fece1b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ youtube-dl==2021.4.17 -python-twitch-client==0.7.1 +twitchAPI==2.5.7.1 schedule termcolor