From 44de1a9a6a516a8cd868a8aace5d6046aa1d9415 Mon Sep 17 00:00:00 2001 From: mikumifa <1055069518@qq.com> Date: Mon, 30 Sep 2024 11:19:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A3=B0=E9=9F=B3=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 1 - tab/go.py | 50 ++++++++++++++++++++++++------------------------ 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/requirements.txt b/requirements.txt index f29a292..f55e3bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,6 @@ retry~=0.9.2 tinydb~=4.8.0 bili-ticket-gt-python~=0.2.7 ntplib~=0.4.0 -playsound~=1.3.0 gradio-calendar~=0.0.4 PyObjC~=10.3.1;sys_platform=="darwin" playwright~=1.46.0 diff --git a/tab/go.py b/tab/go.py index ea90b4b..7ae0eeb 100644 --- a/tab/go.py +++ b/tab/go.py @@ -13,7 +13,6 @@ import retry from gradio import SelectData from loguru import logger -from playsound import playsound from requests import HTTPError, RequestException from config import global_cookieManager, main_request, configDB, time_service @@ -157,7 +156,7 @@ def file_select_handler(select_data: SelectData, files): with gr.Accordion(label='配置抢票成功声音提醒[可选]', open=False): with gr.Row(): audio_path_ui = gr.Audio( - label="上传提示声音", type="filepath") + label="上传提示声音[只支持格式wav]", type="filepath", loop=True) def input_phone(_phone): global_cookieManager.set_config_value("phone", _phone) @@ -219,6 +218,7 @@ def start_go(tickets_info_str, authcode_prepare_str, authcode_preorder_time, tim gr.update(), gr.update(), gr.update(), + gr.update(), ] while isRunning: try: @@ -254,6 +254,7 @@ def start_go(tickets_info_str, authcode_prepare_str, authcode_preorder_time, tim gr.update(), gr.update(), gr.update(), + gr.update(), ] attempt_times = 2 # 为避免错过开票时间, 最多尝试两次预填 while attempt_times > 0: @@ -307,6 +308,7 @@ def start_go(tickets_info_str, authcode_prepare_str, authcode_preorder_time, tim gr.update(visible=True), gr.update(value=gt), gr.update(value=challenge), + gr.update(), gr.update(value=uuid.uuid1()), ] @@ -336,6 +338,7 @@ def run_validation(): gr.update(), gr.update(), gr.update(), + gr.update(), ] validate_con.wait() validate_con.release() @@ -378,6 +381,7 @@ def run_validation(): gr.update(), gr.update(), gr.update(), + gr.update(), ] attempt_times += 1 time.sleep(1) # 休息1秒, 避免触发风控 @@ -398,6 +402,7 @@ def run_validation(): gr.update(), gr.update(), gr.update(), + gr.update(), ] time.sleep(1) else: @@ -419,14 +424,12 @@ def run_validation(): gr.update(), gr.update(), gr.update(), + gr.update(), ] logger.info("手动停止定时抢票") return else: break - if not isRunning: - gr.update(value="停止", visible=True), - return # 数据准备 tickets_info = json.loads(tickets_info_str) @@ -475,6 +478,7 @@ def run_validation(): gr.update(value=gt), gr.update(value=challenge), gr.update(value=uuid.uuid1()), + gr.update(), ] def run_validation(): @@ -501,6 +505,7 @@ def run_validation(): gr.update(), gr.update(), gr.update(), + gr.update(), ] validate_con.wait() validate_con.release() @@ -531,13 +536,6 @@ def run_validation(): geetest_seccode = "" if _data["code"] == 0: logger.info("验证码成功") - gr.update(value=withTimeString("验证码成功"), visible=True), - gr.update(visible=True), - gr.update(), - gr.update(), - gr.update(), - gr.update(), - gr.update(), else: logger.info("验证码失败 {}", _data) yield [ @@ -548,6 +546,8 @@ def run_validation(): gr.update(), gr.update(), gr.update(), + gr.update(), + ] continue request_result = _request.post( @@ -605,6 +605,7 @@ def inner_request(): gr.update(), gr.update(), gr.update(), + gr.update(), ] if errno == 0: logger.info(f"3)抢票成功") @@ -624,6 +625,7 @@ def inner_request(): gr.update(), gr.update(), gr.update(), + gr.update(), ] pushplusToken = configDB.get("pushplusToken") if pushplusToken is not None and pushplusToken != "": @@ -633,26 +635,17 @@ def inner_request(): if serverchanKey is not None and serverchanKey != "": ServerChanUtil.send_message(serverchanKey, "抢票成功", "前往订单中心付款吧") - if audio_path is not None and audio_path != "": - def play_sound_in_loop(file_path): - while True: - try: - playsound(file_path) - except Exception as e: - logger.info(f"播放音乐失败: {e}") - time.sleep(1) - + if audio_path != "": yield [ - gr.update(value="开始放歌, 暂未实现关闭音乐功能,想关闭音乐请重启程序", visible=True), + gr.update(value="开始放歌", visible=True), gr.update(visible=False), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(value=audio_path, type="filepath", autoplay=True), ] - play_sound_in_loop(os.path.normpath(audio_path)) - break if mode == 1: left_time -= 1 @@ -668,6 +661,7 @@ def play_sound_in_loop(file_path): gr.update(), gr.update(), gr.update(), + gr.update(), ] except ValueError as e: logger.info(f"{e}") @@ -679,6 +673,8 @@ def play_sound_in_loop(file_path): gr.update(), gr.update(), gr.update(), + gr.update(), + ] except HTTPError as e: logger.error(f"请求错误: {e}") @@ -690,6 +686,8 @@ def play_sound_in_loop(file_path): gr.update(), gr.update(), gr.update(), + gr.update(), + ] except Exception as e: logger.exception(e) @@ -701,6 +699,7 @@ def play_sound_in_loop(file_path): gr.update(), gr.update(), gr.update(), + gr.update(), ] finally: time.sleep(interval / 1000.0) @@ -713,6 +712,7 @@ def play_sound_in_loop(file_path): gr.update(), gr.update(), gr.update(), + gr.update(), ] mode_ui.change( @@ -809,7 +809,7 @@ def stop(): fn=start_go, inputs=[ticket_ui, authcode_prepare_text_ui, authcode_preorder_time_ui, time_tmp, interval_ui, mode_ui, total_attempts_ui, api_key_input_ui, audio_path_ui], - outputs=[go_ui, stop_btn, qr_image, gt_row, gt_ui, challenge_ui, trigger], + outputs=[go_ui, stop_btn, qr_image, gt_row, gt_ui, challenge_ui, trigger, audio_path_ui], ) stop_btn.click( fn=stop,