From 8a0eb69e54d07a59b5b8fc857e635a039d71f8b0 Mon Sep 17 00:00:00 2001 From: John Howe <89397553+timerring@users.noreply.github.com> Date: Mon, 9 Dec 2024 23:01:34 +0800 Subject: [PATCH] fix: fix the upload continuously issue fix #114 --- src/upload/upload.py | 62 +++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/upload/upload.py b/src/upload/upload.py index fe569cd..e547a82 100644 --- a/src/upload/upload.py +++ b/src/upload/upload.py @@ -66,35 +66,36 @@ def find_bv_number(target_str, my_list): return None def read_append_and_delete_lines(file_path): - while True: - if os.path.getsize(file_path) == 0: - print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} Empty queue, wait 2 minutes and check again...", flush=True) - time.sleep(120) - continue + if os.path.getsize(file_path) == 0: + print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} Empty queue, wait 2 minutes and check again...", flush=True) + time.sleep(120) + return - with open(file_path, "r") as file: - lines = file.readlines() - upload_video_path = lines.pop(0).strip() - print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} " + "deal with " + upload_video_path, flush=True) - # check if the live is already uploaded - query = generate_title(upload_video_path) - result = subprocess.check_output(f"{allconfig.SRC_DIR}/upload/biliup" + " -u " + f"{allconfig.SRC_DIR}/upload/cookies.json" + " list", shell=True) - upload_list = result.decode("utf-8").splitlines() - limit_list = upload_list[:30] - bv_result = find_bv_number(query, limit_list) - if bv_result: - print(f"BV number is: {bv_result}", flush=True) - append_upload(upload_video_path, bv_result) - else: - print("First upload this live", flush=True) - # generate the yaml template - yaml_template = generate_yaml_template(upload_video_path) - yaml_file_path = allconfig.SRC_DIR + "/upload/upload.yaml" - with open(yaml_file_path, 'w', encoding='utf-8') as file: - file.write(yaml_template) - upload_video(upload_video_path, yaml_file_path) - with open(file_path, "w") as file: - file.writelines(lines) + with open(file_path, "r") as file: + lines = file.readlines() + upload_video_path = lines.pop(0).strip() + print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} " + "deal with " + upload_video_path, flush=True) + # check if the live is already uploaded + query = generate_title(upload_video_path) + result = subprocess.check_output(f"{allconfig.SRC_DIR}/upload/biliup" + " -u " + f"{allconfig.SRC_DIR}/upload/cookies.json" + " list", shell=True) + upload_list = result.decode("utf-8").splitlines() + limit_list = upload_list[:30] + bv_result = find_bv_number(query, limit_list) + if bv_result: + print(f"BV number is: {bv_result}", flush=True) + append_upload(upload_video_path, bv_result) + else: + print("First upload this live", flush=True) + # generate the yaml template + yaml_template = generate_yaml_template(upload_video_path) + yaml_file_path = allconfig.SRC_DIR + "/upload/upload.yaml" + with open(yaml_file_path, 'w', encoding='utf-8') as file: + file.write(yaml_template) + upload_video(upload_video_path, yaml_file_path) + with open(file_path, "w") as file: + file.writelines(lines) + return + def append_upload(upload_path, bv_result): try: @@ -127,4 +128,7 @@ def append_upload(upload_path, bv_result): # read the queue and upload the video queue_path = allconfig.SRC_DIR + "/upload/uploadVideoQueue.txt" # read_and_delete_lines(queue_path) - read_append_and_delete_lines(queue_path) \ No newline at end of file + while True: + read_append_and_delete_lines(queue_path) + print("wait for 20 seconds", flush=True) + time.sleep(20) \ No newline at end of file