's'
This commit is contained in:
85
main.py
85
main.py
@@ -83,8 +83,7 @@ rstr = r"[\/\\\:\*\??\"\<\>\|&#.。,, ~!· ]"
|
||||
default_path = f'{script_path}/downloads'
|
||||
os.makedirs(default_path, exist_ok=True)
|
||||
file_update_lock = threading.Lock()
|
||||
os_type = os.name
|
||||
clear_command = "cls" if os_type == 'nt' else "clear"
|
||||
clear_command = "clear"
|
||||
color_obj = utils.Color()
|
||||
os.environ['PATH'] = ffmpeg_path + os.pathsep + current_env_path
|
||||
|
||||
@@ -184,8 +183,7 @@ def display_info2() -> None:
|
||||
try:
|
||||
sys.stdout.flush()
|
||||
time.sleep(5)
|
||||
if Path(sys.executable).name != 'pythonw.exe':
|
||||
os.system(clear_command)
|
||||
os.system(clear_command)
|
||||
print(f"\r共监测{monitoring}个直播中", end=" | ")
|
||||
print(f"同一时间访问网络的线程数: {max_request}", end=" | ")
|
||||
print(f"是否开启代理录制: {'是' if use_proxy else '否'}", end=" | ")
|
||||
@@ -267,15 +265,6 @@ def delete_line(file_path: str, del_line: str, delete_all: bool = False) -> None
|
||||
f.write(txt_line)
|
||||
|
||||
|
||||
def get_startup_info(system_type: str):
|
||||
if system_type == 'nt':
|
||||
startup_info = subprocess.STARTUPINFO()
|
||||
startup_info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
else:
|
||||
startup_info = None
|
||||
return startup_info
|
||||
|
||||
|
||||
def segment_video(converts_file_path: str, segment_save_file_path: str, segment_format: str, segment_time: str,
|
||||
is_original_delete: bool = True) -> None:
|
||||
try:
|
||||
@@ -294,7 +283,7 @@ def segment_video(converts_file_path: str, segment_save_file_path: str, segment_
|
||||
segment_save_file_path,
|
||||
]
|
||||
_output = subprocess.check_output(
|
||||
ffmpeg_command, stderr=subprocess.STDOUT, startupinfo=get_startup_info(os_type)
|
||||
ffmpeg_command, stderr=subprocess.STDOUT
|
||||
)
|
||||
if is_original_delete:
|
||||
time.sleep(1)
|
||||
@@ -329,7 +318,7 @@ def converts_mp4(converts_file_path: str, is_original_delete: bool = True) -> No
|
||||
"-f", "mp4", converts_file_path.rsplit('.', maxsplit=1)[0] + ".mp4",
|
||||
]
|
||||
_output = subprocess.check_output(
|
||||
ffmpeg_command, stderr=subprocess.STDOUT, startupinfo=get_startup_info(os_type)
|
||||
ffmpeg_command, stderr=subprocess.STDOUT
|
||||
)
|
||||
if is_original_delete:
|
||||
time.sleep(1)
|
||||
@@ -349,7 +338,7 @@ def converts_m4a(converts_file_path: str, is_original_delete: bool = True) -> No
|
||||
"-n", "-vn",
|
||||
"-c:a", "aac", "-bsf:a", "aac_adtstoasc", "-ab", "320k",
|
||||
converts_file_path.rsplit('.', maxsplit=1)[0] + ".m4a",
|
||||
], stderr=subprocess.STDOUT, startupinfo=get_startup_info(os_type))
|
||||
], stderr=subprocess.STDOUT)
|
||||
if is_original_delete:
|
||||
time.sleep(1)
|
||||
if os.path.exists(converts_file_path):
|
||||
@@ -446,7 +435,7 @@ def push_message(record_name: str, live_url: str, content: str) -> None:
|
||||
def run_script(command: str) -> None:
|
||||
try:
|
||||
process = subprocess.Popen(
|
||||
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=get_startup_info(os_type)
|
||||
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = process.communicate()
|
||||
stdout_decoded = stdout.decode('utf-8')
|
||||
@@ -511,7 +500,7 @@ def check_subprocess(record_name: str, record_url: str, ffmpeg_command: list, sa
|
||||
script_command: str | None = None) -> bool:
|
||||
save_file_path = ffmpeg_command[-1]
|
||||
process = subprocess.Popen(
|
||||
ffmpeg_command, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=get_startup_info(os_type)
|
||||
ffmpeg_command, stdin=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||
)
|
||||
|
||||
subs_file_path = save_file_path.rsplit('.', maxsplit=1)[0]
|
||||
@@ -528,12 +517,7 @@ def check_subprocess(record_name: str, record_url: str, ffmpeg_command: list, sa
|
||||
color_obj.print_colored(f"[{record_name}]录制时已被注释,本条线程将会退出", color_obj.YELLOW)
|
||||
clear_record_info(record_name, record_url)
|
||||
# process.terminate()
|
||||
if os.name == 'nt':
|
||||
if process.stdin:
|
||||
process.stdin.write(b'q')
|
||||
process.stdin.close()
|
||||
else:
|
||||
process.send_signal(signal.SIGINT)
|
||||
process.send_signal(signal.SIGINT)
|
||||
process.wait()
|
||||
return True
|
||||
time.sleep(1)
|
||||
@@ -1621,23 +1605,42 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
|
||||
error_window.append(1)
|
||||
|
||||
else:
|
||||
import sys
|
||||
sys.path.insert(0, './dist')
|
||||
from douyin_srs_ffplay import start_douyin_srs_ffplay
|
||||
# 调用
|
||||
start_douyin_srs_ffplay(
|
||||
title=title_in_name,
|
||||
anchor_name=anchor_name,
|
||||
real_url=real_url,
|
||||
rec_info=rec_info,
|
||||
record_name=record_name,
|
||||
recording=recording,
|
||||
recording_time_list=recording_time_list,
|
||||
running_list=running_list,
|
||||
monitoring=monitoring,
|
||||
clear_record_info=clear_record_info,
|
||||
color_obj=color_obj
|
||||
)
|
||||
# 可选:项目 dist/ 下提供 douyin_srs_ffplay;否则使用仓库内 YouTube 推流
|
||||
_repo_root = Path(__file__).resolve().parent
|
||||
_dist = _repo_root / "dist"
|
||||
if _dist.is_dir():
|
||||
sys.path.insert(0, str(_dist))
|
||||
try:
|
||||
from douyin_srs_ffplay import start_douyin_srs_ffplay
|
||||
|
||||
start_douyin_srs_ffplay(
|
||||
title=title_in_name,
|
||||
anchor_name=anchor_name,
|
||||
real_url=real_url,
|
||||
rec_info=rec_info,
|
||||
record_name=record_name,
|
||||
recording=recording,
|
||||
recording_time_list=recording_time_list,
|
||||
running_list=running_list,
|
||||
monitoring=monitoring,
|
||||
clear_record_info=clear_record_info,
|
||||
color_obj=color_obj,
|
||||
)
|
||||
except ImportError:
|
||||
from douyin_youtube_ffplay import start_douyin_youtube_ffplay
|
||||
|
||||
start_douyin_youtube_ffplay(
|
||||
title=title_in_name,
|
||||
anchor_name=anchor_name,
|
||||
real_url=real_url,
|
||||
rec_info=rec_info,
|
||||
record_name=record_name,
|
||||
recording=recording,
|
||||
recording_time_list=recording_time_list,
|
||||
running_list=running_list,
|
||||
clear_record_info=clear_record_info,
|
||||
color_obj=color_obj,
|
||||
)
|
||||
count_time = time.time()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user