This commit is contained in:
eric
2026-03-29 03:35:05 -05:00
parent 895dafc0e0
commit 22061fb3c8
14 changed files with 669 additions and 94 deletions

View File

@@ -76,7 +76,27 @@ global_proxy = False
recording_time_list = {}
script_path = os.path.split(os.path.realpath(sys.argv[0]))[0]
config_file = f'{script_path}/config/config.ini'
url_config_file = f'{script_path}/config/URL_config.ini'
def _tiktok_live_pm2_name() -> str:
return (os.environ.get("LIVE_PM2_PROCESS_NAME") or os.environ.get("PM2_SERVICE_NAME") or "").strip()
def _tiktok_url_config_file() -> str:
legacy = f"{script_path}/config/URL_config.ini"
pm2 = _tiktok_live_pm2_name()
if not pm2 or not pm2.lower().startswith("tiktok"):
return legacy
safe = re.sub(r"[^a-zA-Z0-9_.-]", "_", pm2)
per = f"{script_path}/config/URL_config.{safe}.ini"
if os.path.isfile(per):
return per
if os.path.isfile(legacy):
return legacy
return per
url_config_file = _tiktok_url_config_file()
backup_dir = f'{script_path}/backup_config'
text_encoding = 'utf-8-sig'
rstr = r"[\/\\\:\*\?\"\<\>\|&#.。, ~!· ]"
@@ -610,6 +630,9 @@ def is_flv_preferred_platform(link):
def select_source_url(link, stream_info):
if isinstance(link, str) and link.lower().startswith("replayfile:"):
p = link.split(":", 1)[1].strip()
return os.path.normpath(p.replace("/", os.sep))
if is_flv_preferred_platform(link):
codec = utils.get_query_params(stream_info.get('flv_url'), "codec")
if codec and codec[0] == 'h265':
@@ -655,7 +678,23 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
while True:
try:
port_info = []
if record_url.find("douyin.com/") > -1:
if record_url.lower().startswith("replayfile:"):
platform = "录播素材"
fp = os.path.normpath(record_url.split(":", 1)[1].strip().replace("/", os.sep))
if not os.path.isfile(fp):
logger.error(f"录播素材文件不存在或不可读: {fp}")
time.sleep(5)
continue
bn = os.path.splitext(os.path.basename(fp))[0][:80] or "replay"
port_info = {
"anchor_name": f"录播_{bn}",
"is_live": True,
"record_url": record_url,
"title": os.path.basename(fp),
"m3u8_url": None,
"flv_url": None,
}
elif record_url.find("douyin.com/") > -1:
platform = '抖音直播'
with semaphore:
if 'v.douyin.com' not in record_url and '/user/' not in record_url:
@@ -1232,7 +1271,7 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
except Exception as e:
logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}")
if platform != '自定义录制直播':
if platform not in ('自定义录制直播', '录播素材'):
if enable_https_recording and real_url.startswith("http://"):
real_url = real_url.replace("http://", "https://")
@@ -1258,6 +1297,9 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
max_muxing_queue_size = "2048"
break
if platform == "录播素材":
rw_timeout = "50000000"
ffmpeg_command = [
'ffmpeg', "-y",
"-v", "verbose",
@@ -1281,11 +1323,11 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
]
headers = get_record_headers(platform, record_url)
if headers:
if headers and platform != "录播素材":
ffmpeg_command.insert(11, "-headers")
ffmpeg_command.insert(12, headers)
if proxy_address:
if proxy_address and not record_url.lower().startswith("replayfile:"):
ffmpeg_command.insert(1, "-http_proxy")
ffmpeg_command.insert(2, proxy_address)
@@ -2003,7 +2045,7 @@ while True:
delete_line(url_config_file, origin_line)
line_list.append(origin_line)
line = origin_line.strip()
if len(line) < 18:
if len(line) < 12 or (len(line) < 18 and "replayfile:" not in line.lower()):
continue
line_spilt = line.split('主播: ')
@@ -2040,8 +2082,22 @@ while True:
else:
delete_line(url_config_file, origin_line)
url = 'https://' + url if '://' not in url else url
url_host = url.split('/')[2]
url_stripped = url.strip()
_rp = "replayfile:"
if url_stripped.lower().startswith(_rp):
_path_part = url_stripped[len(_rp) :].strip().replace("/", os.sep)
_norm = os.path.normpath(_path_part)
if not os.path.isfile(_norm):
color_obj.print_colored(f"\r{origin_line.strip()} 录播文件不存在,跳过", color_obj.YELLOW)
continue
url = _rp + _norm.replace("\\", "/")
url_host = "__replay_local__"
elif "://" not in url_stripped:
url = "https://" + url_stripped
url_host = url.split("/")[2]
else:
url = url_stripped
url_host = url.split("/")[2]
platform_host = [
'live.douyin.com',
@@ -2139,7 +2195,11 @@ while True:
if 'live.shopee.' in url_host or '.shp.ee' in url_host:
url_host = 'live.shopee.' if 'live.shopee.' in url_host else '.shp.ee'
if url_host in platform_host or any(ext in url for ext in (".flv", ".m3u8")):
if (
url_host in platform_host
or any(ext in url for ext in (".flv", ".m3u8"))
or url_host == "__replay_local__"
):
if url_host in clean_url_host_list:
url = update_file(url_config_file, old_str=url, new_str=url.split('?')[0])