VLC fix (#224)
* Enhance SetupController with improved logging and error handling during setup and file upload processes. Update instance type to t3.xlarge and AMI ID for AWS configuration. Add download progress logging and exception handling for better debugging. * Enhance VLC status evaluation by adding multiple paths for file and URL information extraction, improving robustness against varying VLC XML structures. Implement detailed logging for better debugging and error handling in case of mismatches or missing data. Update example JSON for VLC evaluation to use a valid HLS stream URL. * Improve audio comparison robustness in VLC evaluator by adding error handling for audio file loading and extraction. Implement detailed logging for empty or corrupt files, and normalize DTW distance calculation for more accurate similarity scoring. Remove deprecated audio fingerprint comparison function. --------- Co-authored-by: yuanmengqi <yuanmengqi@mail.ustc.edu.cn>
This commit is contained in:
@@ -1135,11 +1135,21 @@ def get_file():
|
||||
return jsonify({"error": "file_path is required"}), 400
|
||||
|
||||
try:
|
||||
# Check if the file exists and get its size
|
||||
if not os.path.exists(file_path):
|
||||
return jsonify({"error": "File not found"}), 404
|
||||
|
||||
file_size = os.path.getsize(file_path)
|
||||
logger.info(f"Serving file: {file_path} ({file_size} bytes)")
|
||||
|
||||
# Check if the file exists and send it to the user
|
||||
return send_file(file_path, as_attachment=True)
|
||||
except FileNotFoundError:
|
||||
# If the file is not found, return a 404 error
|
||||
return jsonify({"error": "File not found"}), 404
|
||||
except Exception as e:
|
||||
logger.error(f"Error serving file {file_path}: {e}")
|
||||
return jsonify({"error": f"Failed to serve file: {str(e)}"}), 500
|
||||
|
||||
|
||||
@app.route("/setup/upload", methods=["POST"])
|
||||
@@ -1148,8 +1158,27 @@ def upload_file():
|
||||
if 'file_path' in request.form and 'file_data' in request.files:
|
||||
file_path = os.path.expandvars(os.path.expanduser(request.form['file_path']))
|
||||
file = request.files["file_data"]
|
||||
file.save(file_path)
|
||||
return "File Uploaded"
|
||||
|
||||
try:
|
||||
# Ensure target directory exists
|
||||
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
||||
|
||||
# Save file and get size for verification
|
||||
file.save(file_path)
|
||||
uploaded_size = os.path.getsize(file_path)
|
||||
|
||||
logger.info(f"File uploaded successfully: {file_path} ({uploaded_size} bytes)")
|
||||
return f"File Uploaded: {uploaded_size} bytes"
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error uploading file to {file_path}: {e}")
|
||||
# Clean up partial file if it exists
|
||||
if os.path.exists(file_path):
|
||||
try:
|
||||
os.remove(file_path)
|
||||
except:
|
||||
pass
|
||||
return jsonify({"error": f"Failed to upload file: {str(e)}"}), 500
|
||||
else:
|
||||
return jsonify({"error": "file_path and file_data are required"}), 400
|
||||
|
||||
@@ -1208,20 +1237,45 @@ def download_file():
|
||||
|
||||
max_retries = 3
|
||||
error: Optional[Exception] = None
|
||||
|
||||
for i in range(max_retries):
|
||||
try:
|
||||
response = requests.get(url, stream=True)
|
||||
logger.info(f"Download attempt {i+1}/{max_retries} for {url}")
|
||||
response = requests.get(url, stream=True, timeout=300)
|
||||
response.raise_for_status()
|
||||
|
||||
# Get expected file size if available
|
||||
total_size = int(response.headers.get('content-length', 0))
|
||||
if total_size > 0:
|
||||
logger.info(f"Expected file size: {total_size / (1024*1024):.2f} MB")
|
||||
|
||||
downloaded_size = 0
|
||||
with open(path, 'wb') as f:
|
||||
for chunk in response.iter_content(chunk_size=8192):
|
||||
if chunk:
|
||||
f.write(chunk)
|
||||
return "File downloaded successfully"
|
||||
downloaded_size += len(chunk)
|
||||
if total_size > 0 and downloaded_size % (1024*1024) == 0: # Log every MB
|
||||
progress = (downloaded_size / total_size) * 100
|
||||
logger.info(f"Download progress: {progress:.1f}%")
|
||||
|
||||
# Verify download completeness
|
||||
actual_size = os.path.getsize(path)
|
||||
if total_size > 0 and actual_size != total_size:
|
||||
raise Exception(f"Download incomplete. Expected {total_size} bytes, got {actual_size} bytes")
|
||||
|
||||
logger.info(f"File downloaded successfully: {path} ({actual_size} bytes)")
|
||||
return f"File downloaded successfully: {actual_size} bytes"
|
||||
|
||||
except requests.RequestException as e:
|
||||
except (requests.RequestException, Exception) as e:
|
||||
error = e
|
||||
logger.error(f"Failed to download {url}. Retrying... ({max_retries - i - 1} attempts left)")
|
||||
logger.error(f"Failed to download {url}: {e}. Retrying... ({max_retries - i - 1} attempts left)")
|
||||
# Clean up partial download
|
||||
if path.exists():
|
||||
try:
|
||||
path.unlink()
|
||||
except:
|
||||
pass
|
||||
|
||||
return f"Failed to download {url}. No retries left. Error: {error}", 500
|
||||
|
||||
|
||||
Reference in New Issue
Block a user