Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions src/upload/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
while True:
read_append_and_delete_lines(queue_path)
print("wait for 20 seconds", flush=True)
time.sleep(20)