-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from stephengpope/feature/caption-video
Feature/caption video
- Loading branch information
Showing
68 changed files
with
406 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ google-auth-oauthlib | |
google-auth-httplib2 | ||
google-api-python-client | ||
google-cloud-storage | ||
|
||
psutil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from .combine_videos import combine_bp | ||
from .gdrive_upload import gdrive_upload_bp | ||
from .media_to_mp3 import convert_bp | ||
from .caption_video import caption_bp # Add this line | ||
|
||
def register_blueprints(app): | ||
app.register_blueprint(combine_bp) | ||
app.register_blueprint(gdrive_upload_bp) | ||
app.register_blueprint(convert_bp) | ||
app.register_blueprint(caption_bp) # Add this line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from flask import Blueprint, request, jsonify | ||
import uuid | ||
import threading | ||
import logging | ||
from services.caption_video import process_captioning | ||
from services.authentication import authenticate | ||
|
||
# Configure logging | ||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
caption_bp = Blueprint('caption', __name__) | ||
|
||
def process_job(data, job_id): | ||
try: | ||
logger.info(f"Job {job_id}: Starting captioning process") | ||
file_url = data['video_url'] | ||
caption_srt = data['srt'] | ||
options = data.get('options', {}) | ||
|
||
output_filename = process_captioning(file_url, caption_srt, options, job_id) | ||
|
||
if 'webhook_url' in data: | ||
send_webhook(data['webhook_url'], { | ||
"endpoint": "/caption-video", | ||
"code": 200, | ||
"id": data.get("id"), | ||
"job_id": job_id, | ||
"response": output_filename, | ||
"message": "success" | ||
}) | ||
|
||
logger.info(f"Job {job_id}: Captioning process completed successfully") | ||
return output_filename | ||
|
||
except Exception as e: | ||
logger.error(f"Job {job_id}: Error during processing - {e}") | ||
if 'webhook_url' in data: | ||
send_webhook(data['webhook_url'], { | ||
"endpoint": "/caption-video", | ||
"code": 500, | ||
"id": data.get("id"), | ||
"job_id": job_id, | ||
"response": None, | ||
"message": str(e), | ||
}) | ||
else: | ||
raise | ||
|
||
@caption_bp.route('/caption-video', methods=['POST']) | ||
@authenticate | ||
def caption_video(): | ||
data = request.json | ||
|
||
if 'X-API-Key' not in request.headers: | ||
logger.error("Missing X-API-Key header") | ||
return jsonify({"message": "Missing X-API-Key header"}), 400 | ||
|
||
if not all(k in data for k in ('video_url', 'srt')): | ||
logger.error("video_url and srt are required") | ||
return jsonify({"message": "video_url and srt are required"}), 400 | ||
|
||
job_id = str(uuid.uuid4()) | ||
logger.info(f"Processing Job ID: {job_id}") | ||
|
||
if 'webhook_url' in data: | ||
threading.Thread(target=process_job, args=(data, job_id)).start() | ||
return jsonify({ | ||
"code": 202, | ||
"id": data.get("id"), | ||
"job_id": job_id, | ||
"message": "processing" | ||
}), 202 | ||
else: | ||
try: | ||
output_filename = process_job(data, job_id) | ||
return jsonify({ | ||
"code": 200, | ||
"response": output_filename, | ||
"message": "success" | ||
}), 200 | ||
except Exception as e: | ||
logger.error(f"Job {job_id}: Error during synchronous processing - {e}") | ||
return jsonify({ | ||
"code": 500, | ||
"message": str(e) | ||
}), 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
from .audio_mixing import process_audio_mixing | ||
from .authentication import authenticate | ||
from .ffmpeg_toolkit import process_conversion, process_video_combination | ||
from .audio_mixing import process_audio_mixing # Correct import | ||
from .file_management import delete_old_files | ||
from .file_management import download_file | ||
from .gcp_toolkit import upload_to_gcs | ||
from .transcription import process_transcription | ||
from .caption_video import process_captioning # Add this line |
Oops, something went wrong.