Spaces:
Sleeping
Sleeping
Commit
·
e721060
1
Parent(s):
e2c1f2e
file dir patch
Browse files- app/__init__.py +1 -9
- app/config.py +0 -31
- app/routes.py +12 -8
app/__init__.py
CHANGED
|
@@ -20,19 +20,11 @@ def create_app():
|
|
| 20 |
# Set upload folder in app config
|
| 21 |
app.config['UPLOAD_FOLDER'] = upload_dir
|
| 22 |
app.config['ENCODED_FOLDER'] = encoded_dir
|
| 23 |
-
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024 * 1024 #
|
| 24 |
|
| 25 |
# Register blueprints
|
| 26 |
app.register_blueprint(main_bp)
|
| 27 |
app.register_blueprint(api_bp, url_prefix='/api')
|
| 28 |
app.register_blueprint(proxy_bp)
|
| 29 |
|
| 30 |
-
@app.route('/')
|
| 31 |
-
def index():
|
| 32 |
-
return render_template('index.html')
|
| 33 |
-
|
| 34 |
-
@app.route('/favicon.ico')
|
| 35 |
-
def favicon():
|
| 36 |
-
return app.send_static_file('favicon.ico')
|
| 37 |
-
|
| 38 |
return app
|
|
|
|
| 20 |
# Set upload folder in app config
|
| 21 |
app.config['UPLOAD_FOLDER'] = upload_dir
|
| 22 |
app.config['ENCODED_FOLDER'] = encoded_dir
|
| 23 |
+
app.config['MAX_CONTENT_LENGTH'] = 5 * 1024 * 1024 * 1024 # 5GB max file size
|
| 24 |
|
| 25 |
# Register blueprints
|
| 26 |
app.register_blueprint(main_bp)
|
| 27 |
app.register_blueprint(api_bp, url_prefix='/api')
|
| 28 |
app.register_blueprint(proxy_bp)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
return app
|
app/config.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from pathlib import Path
|
| 3 |
-
|
| 4 |
-
# Base directory
|
| 5 |
-
BASE_DIR = Path(__file__).resolve().parent.parent
|
| 6 |
-
|
| 7 |
-
# Flask configuration
|
| 8 |
-
DEBUG = True
|
| 9 |
-
SECRET_KEY = os.getenv('SECRET_KEY', 'your-secret-key-here')
|
| 10 |
-
|
| 11 |
-
# File upload configuration
|
| 12 |
-
UPLOAD_FOLDER = os.getenv('UPLOAD_FOLDER', BASE_DIR / 'uploads')
|
| 13 |
-
ENCODED_FOLDER = os.getenv('ENCODED_FOLDER', BASE_DIR / 'encoded')
|
| 14 |
-
MAX_CONTENT_LENGTH = 1024 * 1024 * 1024 # 1GB max file size
|
| 15 |
-
ALLOWED_EXTENSIONS = {'mp4', 'mov', 'avi', 'mkv', 'wmv'}
|
| 16 |
-
|
| 17 |
-
# Celery configuration
|
| 18 |
-
CELERY_BROKER_URL = 'redis://localhost:6379/0'
|
| 19 |
-
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
|
| 20 |
-
CELERY_TASK_SERIALIZER = 'json'
|
| 21 |
-
CELERY_RESULT_SERIALIZER = 'json'
|
| 22 |
-
CELERY_ACCEPT_CONTENT = ['json']
|
| 23 |
-
CELERY_TASK_TRACK_STARTED = True
|
| 24 |
-
CELERY_TASK_TIME_LIMIT = 30 * 60 # 30 minutes
|
| 25 |
-
|
| 26 |
-
# Redis configuration
|
| 27 |
-
REDIS_URL = 'redis://localhost:6379/0'
|
| 28 |
-
|
| 29 |
-
# Create required directories
|
| 30 |
-
Path(UPLOAD_FOLDER).mkdir(parents=True, exist_ok=True)
|
| 31 |
-
Path(ENCODED_FOLDER).mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/routes.py
CHANGED
|
@@ -193,14 +193,17 @@ def serve_video(job_id, quality):
|
|
| 193 |
'message': 'Job not found'
|
| 194 |
}), 404
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
| 202 |
return send_from_directory(
|
| 203 |
-
|
| 204 |
video_filename,
|
| 205 |
mimetype='video/mp4',
|
| 206 |
as_attachment=True,
|
|
@@ -218,9 +221,10 @@ def serve_video(job_id, quality):
|
|
| 218 |
'message': 'Failed to serve video'
|
| 219 |
}), 500
|
| 220 |
|
|
|
|
| 221 |
def allowed_file(filename):
|
| 222 |
"""Check if the file extension is allowed"""
|
| 223 |
-
ALLOWED_EXTENSIONS = {'mp4', 'mov', 'avi', 'mkv', 'wmv'}
|
| 224 |
return '.' in filename and \
|
| 225 |
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
| 226 |
|
|
|
|
| 193 |
'message': 'Job not found'
|
| 194 |
}), 404
|
| 195 |
|
| 196 |
+
# Retrieve the video file path based on quality from the job info
|
| 197 |
+
video_file_path = None
|
| 198 |
+
for file in job_info.get('files', []):
|
| 199 |
+
if file['quality'] == quality:
|
| 200 |
+
video_file_path = file['path']
|
| 201 |
+
break
|
| 202 |
+
|
| 203 |
+
if video_file_path and os.path.exists(video_file_path):
|
| 204 |
+
directory, video_filename = os.path.split(video_file_path)
|
| 205 |
return send_from_directory(
|
| 206 |
+
directory,
|
| 207 |
video_filename,
|
| 208 |
mimetype='video/mp4',
|
| 209 |
as_attachment=True,
|
|
|
|
| 221 |
'message': 'Failed to serve video'
|
| 222 |
}), 500
|
| 223 |
|
| 224 |
+
|
| 225 |
def allowed_file(filename):
|
| 226 |
"""Check if the file extension is allowed"""
|
| 227 |
+
ALLOWED_EXTENSIONS = {'mp4', 'mov', 'avi', 'mkv', 'wmv', 'flv', 'webm', '3gp','ts','m4v', 'mpg', 'mpeg'}
|
| 228 |
return '.' in filename and \
|
| 229 |
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
| 230 |
|