Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -437,7 +437,7 @@ def stitch_media(
|
|
| 437 |
video_file, video_url,
|
| 438 |
audio_file, audio_url,
|
| 439 |
subtitle_file, subtitle_url,
|
| 440 |
-
book_id,
|
| 441 |
enable_highlight,
|
| 442 |
highlight_color,
|
| 443 |
font_size,
|
|
@@ -499,17 +499,24 @@ def stitch_media(
|
|
| 499 |
|
| 500 |
subtitle_escaped = subtitle_to_use.replace('\\', '/').replace(':', '\\:')
|
| 501 |
|
| 502 |
-
has_book_cover = book_id and book_id.strip()
|
| 503 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 504 |
output_path = os.path.join(temp_dir, f"final_{timestamp}.mp4")
|
| 505 |
|
| 506 |
fade_color_hex = "#dacfc3"
|
| 507 |
|
| 508 |
if has_book_cover:
|
| 509 |
-
status_msg += f"\n📚 Downloading book cover (ID: {book_id})...\n"
|
| 510 |
try:
|
| 511 |
-
|
| 512 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 513 |
|
| 514 |
fade_starts_at = audio_duration * VIDEO_CONFIG['fade_start_percent']
|
| 515 |
fade_ends_at = audio_duration * VIDEO_CONFIG['fade_end_percent']
|
|
@@ -693,6 +700,8 @@ async def stitch_upload(
|
|
| 693 |
audio_url: Optional[str] = Form(None),
|
| 694 |
subtitle_url: Optional[str] = Form(None),
|
| 695 |
book_id: Optional[str] = Form(None),
|
|
|
|
|
|
|
| 696 |
enable_highlight: bool = Form(True),
|
| 697 |
highlight_color: str = Form('yellow'),
|
| 698 |
font_size: int = Form(12),
|
|
@@ -707,6 +716,8 @@ async def stitch_upload(
|
|
| 707 |
'audio_url': audio_url,
|
| 708 |
'subtitle_url': subtitle_url,
|
| 709 |
'book_id': book_id,
|
|
|
|
|
|
|
| 710 |
'enable_highlight': enable_highlight,
|
| 711 |
'highlight_color': highlight_color,
|
| 712 |
'font_size': font_size,
|
|
@@ -720,6 +731,8 @@ async def stitch_upload(
|
|
| 720 |
payload['audio_file'] = _save_upload_to_temp(audio_file, temp_dir)
|
| 721 |
if subtitle_file is not None:
|
| 722 |
payload['subtitle_file'] = _save_upload_to_temp(subtitle_file, temp_dir)
|
|
|
|
|
|
|
| 723 |
|
| 724 |
start_time = time.time()
|
| 725 |
|
|
@@ -731,7 +744,8 @@ async def stitch_upload(
|
|
| 731 |
payload.get('video_file'), payload.get('video_url'),
|
| 732 |
payload.get('audio_file'), payload.get('audio_url'),
|
| 733 |
payload.get('subtitle_file'), payload.get('subtitle_url'),
|
| 734 |
-
payload.get('book_id'), payload.get('
|
|
|
|
| 735 |
payload.get('highlight_color', 'yellow'), payload.get('font_size', 12),
|
| 736 |
payload.get('crf_quality', 23)
|
| 737 |
)
|
|
|
|
| 437 |
video_file, video_url,
|
| 438 |
audio_file, audio_url,
|
| 439 |
subtitle_file, subtitle_url,
|
| 440 |
+
book_id, book_cover_file, book_cover_url,
|
| 441 |
enable_highlight,
|
| 442 |
highlight_color,
|
| 443 |
font_size,
|
|
|
|
| 499 |
|
| 500 |
subtitle_escaped = subtitle_to_use.replace('\\', '/').replace(':', '\\:')
|
| 501 |
|
| 502 |
+
has_book_cover = (book_id and book_id.strip()) or book_cover_file or book_cover_url
|
| 503 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 504 |
output_path = os.path.join(temp_dir, f"final_{timestamp}.mp4")
|
| 505 |
|
| 506 |
fade_color_hex = "#dacfc3"
|
| 507 |
|
| 508 |
if has_book_cover:
|
|
|
|
| 509 |
try:
|
| 510 |
+
if book_cover_file:
|
| 511 |
+
status_msg += f"\n📚 Using uploaded book cover...\n"
|
| 512 |
+
book_cover_path = book_cover_file
|
| 513 |
+
elif book_cover_url:
|
| 514 |
+
status_msg += f"\n📚 Downloading book cover from URL...\n"
|
| 515 |
+
book_cover_path = download_file_from_url(book_cover_url.strip(), temp_dir, 'book_cover_from_url.jpg')
|
| 516 |
+
else:
|
| 517 |
+
status_msg += f"\n📚 Downloading book cover (ID: {book_id})...\n"
|
| 518 |
+
book_cover_path = download_book_cover(book_id.strip(), temp_dir)
|
| 519 |
+
status_msg += "✅ Book cover ready\n"
|
| 520 |
|
| 521 |
fade_starts_at = audio_duration * VIDEO_CONFIG['fade_start_percent']
|
| 522 |
fade_ends_at = audio_duration * VIDEO_CONFIG['fade_end_percent']
|
|
|
|
| 700 |
audio_url: Optional[str] = Form(None),
|
| 701 |
subtitle_url: Optional[str] = Form(None),
|
| 702 |
book_id: Optional[str] = Form(None),
|
| 703 |
+
book_cover_file: Optional[UploadFile] = File(None),
|
| 704 |
+
book_cover_url: Optional[str] = Form(None),
|
| 705 |
enable_highlight: bool = Form(True),
|
| 706 |
highlight_color: str = Form('yellow'),
|
| 707 |
font_size: int = Form(12),
|
|
|
|
| 716 |
'audio_url': audio_url,
|
| 717 |
'subtitle_url': subtitle_url,
|
| 718 |
'book_id': book_id,
|
| 719 |
+
'book_cover_file': None,
|
| 720 |
+
'book_cover_url': book_cover_url,
|
| 721 |
'enable_highlight': enable_highlight,
|
| 722 |
'highlight_color': highlight_color,
|
| 723 |
'font_size': font_size,
|
|
|
|
| 731 |
payload['audio_file'] = _save_upload_to_temp(audio_file, temp_dir)
|
| 732 |
if subtitle_file is not None:
|
| 733 |
payload['subtitle_file'] = _save_upload_to_temp(subtitle_file, temp_dir)
|
| 734 |
+
if book_cover_file is not None:
|
| 735 |
+
payload['book_cover_file'] = _save_upload_to_temp(book_cover_file, temp_dir)
|
| 736 |
|
| 737 |
start_time = time.time()
|
| 738 |
|
|
|
|
| 744 |
payload.get('video_file'), payload.get('video_url'),
|
| 745 |
payload.get('audio_file'), payload.get('audio_url'),
|
| 746 |
payload.get('subtitle_file'), payload.get('subtitle_url'),
|
| 747 |
+
payload.get('book_id'), payload.get('book_cover_file'), payload.get('book_cover_url'),
|
| 748 |
+
payload.get('enable_highlight', True),
|
| 749 |
payload.get('highlight_color', 'yellow'), payload.get('font_size', 12),
|
| 750 |
payload.get('crf_quality', 23)
|
| 751 |
)
|