style: fix lint issues

This commit is contained in:
ihmily 2025-06-14 14:27:55 +08:00
parent effcfcc76f
commit c157c08e5a
5 changed files with 26 additions and 18 deletions

View File

@ -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)

16
main.py
View File

@ -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)

View File

@ -2,7 +2,6 @@
import gzip
import urllib.parse
import urllib.error
from urllib.request import Request
import requests
import ssl
import json

View File

@ -2,10 +2,19 @@
import os
import sys
from loguru import logger
logger.remove()
custom_format = "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> - <level>{message}</level>"
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]

View File

@ -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 messagePlease check if the input sooplive live room address "
f"is correct.")
print("error messagePlease 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
return result