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
29 changes: 18 additions & 11 deletions src/upload/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from src.upload.generate_yaml import generate_yaml_template
from src.upload.extract_video_info import generate_title
import time
import fcntl

def read_and_delete_lines(file_path):
while True:
Expand Down Expand Up @@ -66,14 +67,23 @@ def find_bv_number(target_str, my_list):
return None

def read_append_and_delete_lines(file_path):
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
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)
return

with open(file_path, "r+") as file:
fcntl.flock(file, fcntl.LOCK_EX)
lines = file.readlines()
upload_video_path = lines.pop(0).strip()
file.seek(0)
file.writelines(lines)
# Truncate the file to the current position
file.truncate()
# Release the lock
fcntl.flock(file, fcntl.LOCK_UN)

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)
Expand All @@ -92,10 +102,7 @@ def read_append_and_delete_lines(file_path):
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

return

def append_upload(upload_path, bv_result):
try:
Expand Down