- Improve annotation algorithm for Youtube (and others)

- Patch Pytube
- improve OS deletion of files and writing of files
- Start working on Claude
- Improve template management
This commit is contained in:
Josako
2024-07-16 14:21:49 +02:00
parent db44fd3b66
commit 908a2eaf7e
39 changed files with 6427 additions and 324 deletions

30
common/utils/os_utils.py Normal file
View File

@@ -0,0 +1,30 @@
import os
import gevent
import time
from flask import current_app
def safe_remove(file_path):
try:
if os.path.exists(file_path):
os.remove(file_path)
# Wait for the file to be deleted
start_time = time.time()
while os.path.exists(file_path):
gevent.sleep(1)
if time.time() - start_time > 5: # 5 second timeout
raise TimeoutError(f"Failed to delete {file_path} after 5 seconds")
current_app.logger.info(f"Successfully deleted {file_path}")
else:
current_app.logger.info(f"{file_path} does not exist, skipping deletion")
except Exception as e:
current_app.logger.error(f"Error deleting {file_path}: {str(e)}")
raise
def sync_folder(file_path):
dir_fd = os.open(file_path, os.O_RDONLY)
os.fsync(dir_fd)
os.close(dir_fd)