Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/burn/only_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def normalize_video_path(filepath):
"""
parts = filepath.rsplit('/', 1)[-1].split('_')
date_time_parts = parts[1].split('-')
new_date_time = f"{date_time_parts[0][:4]}-{date_time_parts[0][4:6]}-{date_time_parts[0][6:8]}-{date_time_parts[1]}"
return filepath.rsplit('/', 1)[0] + '/' + parts[0] + '_' + new_date_time + '-upload.mp4'
new_date_time = f"{date_time_parts[0][:4]}-{date_time_parts[0][4:6]}-{date_time_parts[0][6:8]}-{date_time_parts[1]}-{date_time_parts[2]}"
return filepath.rsplit('/', 1)[0] + '/' + parts[0] + '_' + new_date_time + '-.mp4'

def render_video_only(video_path):
original_video_path = str(video_path)
Expand Down
4 changes: 2 additions & 2 deletions src/burn/render_and_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def normalize_video_path(filepath):
"""
parts = filepath.rsplit('/', 1)[-1].split('_')
date_time_parts = parts[1].split('-')
new_date_time = f"{date_time_parts[0][:4]}-{date_time_parts[0][4:6]}-{date_time_parts[0][6:8]}-{date_time_parts[1]}"
return filepath.rsplit('/', 1)[0] + '/' + parts[0] + '_' + new_date_time + '-upload.mp4'
new_date_time = f"{date_time_parts[0][:4]}-{date_time_parts[0][4:6]}-{date_time_parts[0][6:8]}-{date_time_parts[1]}-{date_time_parts[2]}"
return filepath.rsplit('/', 1)[0] + '/' + parts[0] + '_' + new_date_time + '-.mp4'

def merge_videos(in_final_video, title, artist, date, merge_list):
"""Merge the video segments and preserve the first video's metadata
Expand Down
16 changes: 13 additions & 3 deletions src/burn/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import time
from src.allconfig import VIDEOS_DIR

def process_folder(folder_path):
def process_folder_merge(folder_path):
# Don't process the recording folder
flv_files = list(Path(folder_path).glob('*.flv'))
if flv_files:
Expand All @@ -17,7 +17,7 @@ def process_folder(folder_path):
files_by_date = {}

# process the recorded files
mp4_files = [mp4_file for mp4_file in Path(folder_path).glob('*.mp4') if not mp4_file.name.endswith('-upload.mp4')]
mp4_files = [mp4_file for mp4_file in Path(folder_path).glob('*.mp4') if not mp4_file.name.endswith('-.mp4')]
for mp4_file in mp4_files:
date_part = mp4_file.stem.split('_')[1].split('-')[0]

Expand All @@ -36,11 +36,21 @@ def process_folder(folder_path):
print(f"Processing {file}...", flush=True)
render_video_only(file)

def process_folder_append(folder_path):
# process the recorded files
mp4_files = [mp4_file for mp4_file in Path(folder_path).glob('*.mp4') if not mp4_file.name.endswith('-.mp4')]
for file in mp4_files:
print(f"Processing {file}...", flush=True)
render_video_only(file)

if __name__ == "__main__":
room_folder_path = VIDEOS_DIR
while True:
for room_folder in Path(room_folder_path).iterdir():
if room_folder.is_dir():
process_folder(room_folder)
# This function use the merge mode to upload videos
# process_folder_merge(room_folder)
# This function use the append mode to upload videos
process_folder_append(room_folder)
print(f"{time.strftime('%Y-%m-%d %H:%M:%S')} There is no file recorded. Check again in 120 seconds.", flush=True)
time.sleep(120)
70 changes: 69 additions & 1 deletion src/upload/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from src import allconfig
from datetime import datetime
from src.upload.generate_yaml import generate_yaml_template
from src.upload.extract_video_info import generate_title
import time

def read_and_delete_lines(file_path):
Expand Down Expand Up @@ -56,7 +57,74 @@ def upload_video(upload_path, yaml_file_path):
print("Fail to upload, the files will be reserved.")
sys.exit(1)

def find_bv_number(target_str, my_list):
for element in my_list:
if target_str in element:
parts = element.split('\t')
if len(parts) > 0:
return parts[0]
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

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)

def append_upload(upload_path, bv_result):
try:
# Construct the command
command = [
f"{allconfig.BILIVE_DIR}/src/upload/biliup",
"-u",
f"{allconfig.SRC_DIR}/upload/cookies.json",
"append",
"--vid",
bv_result,
upload_path
]
# Execute the command
result = subprocess.run(command, check=True)

# Check if the command was successful
if result.returncode == 0:
print("Upload successfully, then delete the video")
os.remove(upload_path)
else:
print("Fail to upload, the files will be reserved.")
sys.exit(1)

except subprocess.CalledProcessError:
print("Fail to upload, the files will be reserved.")
sys.exit(1)

if __name__ == "__main__":
# read the queue and upload the video
queue_path = allconfig.SRC_DIR + "/upload/uploadVideoQueue.txt"
read_and_delete_lines(queue_path)
# read_and_delete_lines(queue_path)
read_append_and_delete_lines(queue_path)