4
4
Author: Hmily
5
5
GitHub: https://github.com/ihmily
6
6
Date: 2023-07-17 23:52:05
7
- Update: 2024-01-29 18:45:09
7
+ Update: 2024-02-09 02:41:18
8
8
Copyright (c) 2023-2024 by Hmily, All Rights Reserved.
9
9
Function: Record live stream video.
10
10
"""
@@ -146,13 +146,16 @@ def display_info():
146
146
logger .warning (f"错误信息: { e } 发生错误的行数: { e .__traceback__ .tb_lineno } " )
147
147
148
148
149
- def update_file (file_path : str , old_str : str , new_str : str ):
149
+ def update_file (file_path : str , old_str : str , new_str : str , start_str : str = None ):
150
150
# TODO: 更新文件操作
151
151
file_data = ""
152
152
with open (file_path , "r" , encoding = "utf-8-sig" ) as f :
153
153
for text_line in f :
154
154
if old_str in text_line :
155
155
text_line = text_line .replace (old_str , new_str )
156
+ if start_str :
157
+ text_line = f'{ start_str } { text_line } '
158
+
156
159
file_data += text_line
157
160
with open (file_path , "w" , encoding = "utf-8-sig" ) as f :
158
161
f .write (file_data )
@@ -576,7 +579,7 @@ def start_record(url_data: tuple, count_variable: int = -1):
576
579
no_error = True
577
580
new_record_url = ''
578
581
count_time = time .time ()
579
-
582
+ retry = 0
580
583
record_quality , record_url , anchor_name = url_data
581
584
print (f"\r 运行新线程,传入地址 { record_url } " )
582
585
@@ -648,10 +651,14 @@ def start_record(url_data: tuple, count_variable: int = -1):
648
651
json_data = get_bilibili_stream_data (record_url , cookies = bili_cookie )
649
652
port_info = get_bilibili_stream_url (json_data , record_quality )
650
653
651
- elif record_url .find ("https://www.xiaohongshu.com /" ) > - 1 :
654
+ elif record_url .find ("https://www.redelight.cn /" ) > - 1 :
652
655
platform = '小红书直播'
656
+ if retry > 0 :
657
+ time .sleep (7200 )
658
+ retry = 0
653
659
with semaphore :
654
660
port_info = get_xhs_stream_url (record_url , cookies = xhs_cookie )
661
+ retry += 1
655
662
656
663
elif record_url .find ("https://www.bigo.tv/" ) > - 1 :
657
664
platform = 'bigo直播'
@@ -1322,7 +1329,7 @@ def contains_url(string: str) -> bool:
1322
1329
1323
1330
# 读取URL_config.ini文件
1324
1331
try :
1325
- with open (url_config_file , "r" , encoding = encoding ) as file :
1332
+ with open (url_config_file , "r" , encoding = encoding , errors = 'ignore' ) as file :
1326
1333
for line in file :
1327
1334
line = line .strip ()
1328
1335
if line .startswith ("#" ) or len (line ) < 20 :
@@ -1362,7 +1369,7 @@ def contains_url(string: str) -> bool:
1362
1369
'www.douyu.com' ,
1363
1370
'www.yy.com' ,
1364
1371
'live.bilibili.com' ,
1365
- 'www.xiaohongshu.com ' ,
1372
+ 'www.redelight.cn ' ,
1366
1373
'www.bigo.tv' ,
1367
1374
'app.blued.cn' ,
1368
1375
'play.afreecatv.com' ,
@@ -1378,12 +1385,19 @@ def contains_url(string: str) -> bool:
1378
1385
url_tuples_list .append (new_line )
1379
1386
else :
1380
1387
print (f"{ url } 未知链接.此条跳过" )
1388
+ update_file (url_config_file , url , url , start_str = '#' )
1381
1389
1382
1390
while len (name_list ):
1383
1391
a = name_list .pop ()
1384
1392
replace_words = a .split ('|' )
1385
1393
if replace_words [0 ] != replace_words [1 ]:
1386
- update_file (url_config_file , replace_words [0 ], replace_words [1 ])
1394
+ if replace_words [1 ].startswith ("#" ):
1395
+ start_with = '#'
1396
+ new_word = replace_words [1 ][1 :]
1397
+ else :
1398
+ start_with = None
1399
+ new_word = replace_words [1 ]
1400
+ update_file (url_config_file , replace_words [0 ], new_word , start_str = start_with )
1387
1401
1388
1402
if len (url_tuples_list ) > 0 :
1389
1403
text_no_repeat_url = list (set (url_tuples_list ))
0 commit comments