diff --git a/ffmpeg_install.py b/ffmpeg_install.py index d0f32a6..eddec4b 100644 --- a/ffmpeg_install.py +++ b/ffmpeg_install.py @@ -122,7 +122,7 @@ def install_ffmpeg_linux(): logger.debug("Trying to install the stable version of ffmpeg") result = subprocess.run(['yum', '-y', 'update'], capture_output=True) if result.returncode != 0: - logger.error(f"Failed to update package lists using yum.") + logger.error("Failed to update package lists using yum.") return False result = subprocess.run(['yum', 'install', '-y', 'ffmpeg'], capture_output=True) diff --git a/main.py b/main.py index b5268b1..dcb300d 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ Author: Hmily GitHub: https://github.com/ihmily Date: 2023-07-17 23:52:05 -Update: 2025-02-08 19:19:00 +Update: 2025-06-14 12:19:00 Copyright (c) 2023-2025 by Hmily, All Rights Reserved. Function: Record live stream video. """ @@ -102,9 +102,9 @@ def display_info() -> None: if split_video_by_time: print(f"录制分段开启: {split_time}秒", end=" | ") else: - print(f"录制分段开启: 否", end=" | ") + print("录制分段开启: 否", end=" | ") if create_time_file: - print(f"是否生成时间文件: 是", end=" | ") + print("是否生成时间文件: 是", end=" | ") print(f"录制视频质量为: {video_record_quality}", end=" | ") print(f"录制视频格式为: {video_save_type}", end=" | ") print(f"目前瞬时错误数为: {error_count}", end=" | ") @@ -220,7 +220,7 @@ def converts_mp4(converts_file_path: str, is_original_delete: bool = True) -> No try: if os.path.exists(converts_file_path) and os.path.getsize(converts_file_path) > 0: if converts_to_h264: - color_obj.print_colored(f"正在转码为MP4格式并重新编码为h264\n", color_obj.YELLOW) + color_obj.print_colored("正在转码为MP4格式并重新编码为h264\n", color_obj.YELLOW) ffmpeg_command = [ "ffmpeg", "-i", converts_file_path, "-c:v", "libx264", @@ -231,7 +231,7 @@ def converts_mp4(converts_file_path: str, is_original_delete: bool = True) -> No "-f", "mp4", converts_file_path.rsplit('.', maxsplit=1)[0] + ".mp4", ] else: - color_obj.print_colored(f"正在转码为MP4格式\n", color_obj.YELLOW) + color_obj.print_colored("正在转码为MP4格式\n", color_obj.YELLOW) ffmpeg_command = [ "ffmpeg", "-i", converts_file_path, "-c:v", "copy", @@ -366,7 +366,7 @@ def run_script(command: str) -> None: print(stderr_decoded) except PermissionError as e: logger.error(e) - logger.error(f'脚本无执行权限!, 若是Linux环境, 请先执行:chmod +x your_script.sh 授予脚本可执行权限') + logger.error('脚本无执行权限!, 若是Linux环境, 请先执行:chmod +x your_script.sh 授予脚本可执行权限') except OSError as e: logger.error(e) logger.error('Please add `#!/bin/bash` at the beginning of your bash script file.') @@ -1621,8 +1621,8 @@ try: print("System Proxy: http://{}:{}".format(proxy_info.ip, proxy_info.port)) except HTTPError as err: print(f"HTTP error occurred: {err.code} - {err.reason}") -except URLError as err: - color_obj.print_colored(f"INFO:未检测到全局/规则网络代理,请检查代理配置(若无需录制海外直播请忽略此条提示)", +except URLError: + color_obj.print_colored("INFO:未检测到全局/规则网络代理,请检查代理配置(若无需录制海外直播请忽略此条提示)", color_obj.YELLOW) except Exception as err: print("An unexpected error occurred:", err) diff --git a/src/http_clients/sync_http.py b/src/http_clients/sync_http.py index 5db416f..76d7c07 100644 --- a/src/http_clients/sync_http.py +++ b/src/http_clients/sync_http.py @@ -2,7 +2,6 @@ import gzip import urllib.parse import urllib.error -from urllib.request import Request import requests import ssl import json diff --git a/src/logger.py b/src/logger.py index 8079e50..93faeae 100644 --- a/src/logger.py +++ b/src/logger.py @@ -2,10 +2,19 @@ import os import sys +from loguru import logger + +logger.remove() custom_format = "{time:YYYY-MM-DD HH:mm:ss.SSS} | {level: <8} - {message}" -os.environ["LOGURU_FORMAT"] = custom_format -from loguru import logger + +logger.add( + sink=sys.stderr, + format=custom_format, + level="DEBUG", + colorize=True, + enqueue=True +) script_path = os.path.split(os.path.realpath(sys.argv[0]))[0] diff --git a/src/spider.py b/src/spider.py index 4211d67..67c0842 100644 --- a/src/spider.py +++ b/src/spider.py @@ -4,7 +4,7 @@ Author: Hmily GitHub: https://github.com/ihmily Date: 2023-07-15 23:15:00 -Update: 2025-02-08 17:59:16 +Update: 2025-06-14 12:19:00 Copyright (c) 2023-2025 by Hmily, All Rights Reserved. Function: Get live stream data. """ @@ -26,7 +26,7 @@ from . import JS_SCRIPT_PATH, utils from .utils import trace_error_decorator from .logger import script_path from .room import get_sec_user_id, get_unique_id, UnsupportedUrlError -from .http_clients.async_http import async_req, get_response_status +from .http_clients.async_http import async_req ssl_context = ssl.create_default_context() @@ -1011,8 +1011,8 @@ async def get_sooplive_stream_data( else: raise RuntimeError("sooplive login failed, please check if the account and password are correct") elif json_data['data']['code'] == -6001: - print(f"error message:Please check if the input sooplive live room address " - f"is correct.") + print("error message:Please check if the input sooplive live room address " + "is correct.") return result if json_data['result'] == 1 and anchor_name: broad_no = json_data['data']['broad_no'] @@ -2998,7 +2998,7 @@ async def get_faceit_stream_data(url: str, proxy_addr: OptionalStr = None, cooki if cookies: headers['Cookie'] = cookies - nickname = re.findall(f'/players/(.*?)/stream', url)[0] + nickname = re.findall('/players/(.*?)/stream', url)[0] api = f'https://www.faceit.com/api/users/v1/nicknames/{nickname}' json_str = await async_req(api, proxy_addr=proxy_addr, headers=headers) json_data = json.loads(json_str) @@ -3015,4 +3015,4 @@ async def get_faceit_stream_data(url: str, proxy_addr: OptionalStr = None, cooki result['anchor_name'] = anchor_name else: result = {'anchor_name': anchor_name, 'is_live': False} - return result \ No newline at end of file + return result