Перешел на другую, актуальную библиотеку твича.

This commit is contained in:
lulzette 2022-11-13 12:43:03 +03:00
parent 7cb3c36759
commit 7961509aca
5 changed files with 26 additions and 12 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ config_list.sh
__pycache__ __pycache__
.vscode .vscode
.idea .idea
output.log

View File

@ -21,3 +21,10 @@ max_files = 3 # Сколько хранить стримов
``` ```
* Запустить скрипт в screen'е или создать для него systemd.service файл (или init.d, в зависимости от системы инициализации) * Запустить скрипт в screen'е или создать для него systemd.service файл (или init.d, в зависимости от системы инициализации)
# Updates
## 2022-11-13
В связи с переходом на новую библиотеку необходимо указывать 2 переменные авторизации - appid и appsecret.
twitchid это appid, а секретный ключ можно получить или перегенерировать в https://dev.twitch.tv/console

View File

@ -1,4 +1,5 @@
twitchid="....." appid=""
appsecret=""
streamers = ("jesusavgn", "252mart", "vi0xxx") streamers = ("jesusavgn", "252mart", "vi0xxx")
path="/home/losted/test" path="/home/losted/test"
period = 5 period = 5

View File

@ -9,7 +9,7 @@ from threading import Thread
from types import resolve_bases from types import resolve_bases
import config_python import config_python
import schedule import schedule
from twitch import TwitchClient from twitchAPI.twitch import Twitch
import subprocess import subprocess
import time import time
import logging import logging
@ -17,7 +17,9 @@ from logging.handlers import TimedRotatingFileHandler
from termcolor import colored from termcolor import colored
streamers = config_python.streamers 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_format = logging.Formatter('%(asctime)s %(levelname)s:%(message)s')
log_file = 'output.log' log_file = 'output.log'
@ -84,8 +86,10 @@ def checkAlive():
# Путь до диры со стримами # Путь до диры со стримами
path = config_python.path + "/" + i 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( log.error(
colored( colored(
"Аккаунт " + i + " не найден", "Аккаунт " + i + " не найден",
@ -98,11 +102,12 @@ def checkAlive():
os.makedirs(path) os.makedirs(path)
log.info("Создана директория " + i) log.info("Создана директория " + i)
# Достаем ID стримера из инфо # Достаем 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 + " стримит") log.info(i + " стримит")
startRecord(i) startRecord(i)
open(path+"/pid", 'w').close open(path+"/pid", 'w').close
@ -177,7 +182,7 @@ if __name__ == "__main__":
# Каждый час удалять старые стримы # Каждый час удалять старые стримы
schedule.every(1).hours.do(removeOldStreams) schedule.every(1).hours.do(removeOldStreams)
client = TwitchClient(client_id=client_id) twitch_client = Twitch(app_id, app_secret)
while True: while True:
schedule.run_pending() schedule.run_pending()
time.sleep(1) time.sleep(1)

View File

@ -1,4 +1,4 @@
youtube-dl==2021.4.17 youtube-dl==2021.4.17
python-twitch-client==0.7.1 twitchAPI==2.5.7.1
schedule schedule
termcolor termcolor