Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various updates/fixes #12

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Flask
from routes.media_to_mp3 import convert_bp
from routes.transcribe import transcribe_bp
from routes.transcribe_media import transcribe_bp
from routes.combine_videos import combine_bp
from routes.audio_mixing import audio_mixing_bp
from routes.gdrive_upload import gdrive_upload_bp
Expand Down
10 changes: 5 additions & 5 deletions routes/combine_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ def process_job(media_urls, webhook_url, id, job_id):
@authenticate
def combine_videos():
data = request.json
media_urls = data.get('media_urls')
media_urls = data.get('video_urls')
webhook_url = data.get('webhook_url')
id = data.get('id')
job_id = str(uuid.uuid4())

logger.info(f"Received combine-videos request: media_urls={media_urls}, webhook_url={webhook_url}, id={id}")
logger.info(f"Received combine-videos request: video_urls={media_urls}, webhook_url={webhook_url}, id={id}")

if not (isinstance(media_urls, list) and
all(isinstance(item, dict) and
isinstance(item.get('media_url'), str)
isinstance(item.get('video_url'), str)
for item in media_urls)):
logger.error("Invalid or missing media_urls parameter in request")
return jsonify({"message": "Invalid or missing media_urls parameter"}), 400
logger.error("Invalid or missing video_urls parameter in request")
return jsonify({"message": "Invalid or missing video_urls parameter"}), 400

#if webhook_url and not id:
# logger.warning("id is missing when webhook_url is provided")
Expand Down
2 changes: 1 addition & 1 deletion routes/transcribe.py → routes/transcribe_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def process_job(media_url, output, job_id, webhook_url=None, id=None):
else:
raise

@transcribe_bp.route('/transcribe', methods=['POST'])
@transcribe_bp.route('/transcribe-media', methods=['POST'])
@authenticate
def transcribe():
data = request.json
Expand Down
34 changes: 0 additions & 34 deletions services/caption_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,37 +154,3 @@ def process_captioning(file_url, caption_srt, options, job_id):
except Exception as e:
logger.error(f"Job {job_id}: Error in process_captioning: {str(e)}")
raise

def download_file(file_url, storage_path):
session = requests.Session()
retries = Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504])
session.mount('http://', HTTPAdapter(max_retries=retries))
session.mount('https://', HTTPAdapter(max_retries=retries))

if 'drive.google.com' in file_url:
file_id = extract_drive_id(file_url)
download_url = f"https://drive.google.com/uc?export=download&id={file_id}"
response = session.get(download_url, stream=True)
else:
response = session.get(file_url, stream=True)

response.raise_for_status()

filename = os.path.join(storage_path, file_url.split('/')[-1])
with open(filename, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)

return filename

def extract_drive_id(file_url):
"""
Extract the file ID from a Google Drive URL.
"""
if 'id=' in file_url:
return file_url.split('id=')[1].split('&')[0]
elif '/d/' in file_url:
return file_url.split('/d/')[1].split('/')[0]
else:
raise ValueError("Invalid URL: 'id' parameter not found in the URL")
2 changes: 1 addition & 1 deletion services/ffmpeg_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def process_video_combination(media_urls, job_id, webhook_url=None):
try:
# Download all media files
for i, media_item in enumerate(media_urls):
url = media_item['media_url']
url = media_item['video_url']
input_filename = download_file(url, os.path.join(STORAGE_PATH, f"{job_id}_input_{i}"))
input_files.append(input_filename)

Expand Down