unique file names
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m11s
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m11s
This commit is contained in:
19
app.py
19
app.py
@@ -4,6 +4,7 @@ import uuid
|
|||||||
from flask import Flask, render_template, request, send_file, jsonify
|
from flask import Flask, render_template, request, send_file, jsonify
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['UPLOAD_FOLDER'] = 'uploads'
|
app.config['UPLOAD_FOLDER'] = 'uploads'
|
||||||
@@ -14,6 +15,9 @@ app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024 # 500MB max file size
|
|||||||
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
||||||
os.makedirs(app.config['OUTPUT_FOLDER'], exist_ok=True)
|
os.makedirs(app.config['OUTPUT_FOLDER'], exist_ok=True)
|
||||||
|
|
||||||
|
# Store original filenames
|
||||||
|
original_filenames = {}
|
||||||
|
|
||||||
ALLOWED_EXTENSIONS = {'mp4', 'avi', 'mov', 'mkv', 'wmv', 'flv', 'webm'}
|
ALLOWED_EXTENSIONS = {'mp4', 'avi', 'mov', 'mkv', 'wmv', 'flv', 'webm'}
|
||||||
|
|
||||||
def allowed_file(filename):
|
def allowed_file(filename):
|
||||||
@@ -71,6 +75,9 @@ def upload_video():
|
|||||||
# Get video information
|
# Get video information
|
||||||
video_info = get_video_info(filepath)
|
video_info = get_video_info(filepath)
|
||||||
|
|
||||||
|
# Store original filename for later use
|
||||||
|
original_filenames[file_id] = file.filename
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'file_id': file_id,
|
'file_id': file_id,
|
||||||
'filename': filename,
|
'filename': filename,
|
||||||
@@ -189,7 +196,13 @@ def download_video(file_id):
|
|||||||
if not os.path.exists(output_path):
|
if not os.path.exists(output_path):
|
||||||
return jsonify({'error': 'File not found'}), 404
|
return jsonify({'error': 'File not found'}), 404
|
||||||
|
|
||||||
return send_file(output_path, as_attachment=True, download_name='processed_video.mp4')
|
# Get original filename and create download name
|
||||||
|
original_name = original_filenames.get(file_id, 'video.mp4')
|
||||||
|
name_without_ext = os.path.splitext(original_name)[0]
|
||||||
|
timestamp = int(time.time() * 1000) % 100000 # Last 5 digits of timestamp
|
||||||
|
download_name = f"{name_without_ext}_processed_{timestamp}.mp4"
|
||||||
|
|
||||||
|
return send_file(output_path, as_attachment=True, download_name=download_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'error': str(e)}), 500
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
@@ -207,6 +220,10 @@ def cleanup_files(file_id):
|
|||||||
if f.startswith(file_id):
|
if f.startswith(file_id):
|
||||||
os.remove(os.path.join(app.config['OUTPUT_FOLDER'], f))
|
os.remove(os.path.join(app.config['OUTPUT_FOLDER'], f))
|
||||||
|
|
||||||
|
# Clean up stored original filename
|
||||||
|
if file_id in original_filenames:
|
||||||
|
del original_filenames[file_id]
|
||||||
|
|
||||||
return jsonify({'success': True})
|
return jsonify({'success': True})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'error': str(e)}), 500
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|||||||
Reference in New Issue
Block a user