updated the order resulted in playlist
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 537 KiB |
BIN
utils/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
utils/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/group_player_management.cpython-312.pyc
Normal file
BIN
utils/__pycache__/group_player_management.cpython-312.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/logger.cpython-312.pyc
Normal file
BIN
utils/__pycache__/logger.cpython-312.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/uploads.cpython-312.pyc
Normal file
BIN
utils/__pycache__/uploads.cpython-312.pyc
Normal file
Binary file not shown.
@@ -110,7 +110,7 @@ def convert_video_and_update_playlist(app, file_path, original_filename, target_
|
||||
# PDF conversion functions
|
||||
def convert_pdf_to_images(pdf_file, output_folder, delete_pdf=True):
|
||||
"""
|
||||
Convert a PDF file to images.
|
||||
Convert a PDF file to images in sequential order.
|
||||
|
||||
Args:
|
||||
pdf_file (str): Path to the PDF file
|
||||
@@ -118,22 +118,30 @@ def convert_pdf_to_images(pdf_file, output_folder, delete_pdf=True):
|
||||
delete_pdf (bool): Whether to delete the PDF file after processing
|
||||
|
||||
Returns:
|
||||
list: List of generated image filenames, or empty list if conversion failed
|
||||
list: List of generated image filenames in page order, or empty list if conversion failed
|
||||
"""
|
||||
print(f"Converting PDF to images: {pdf_file}")
|
||||
try:
|
||||
# Convert PDF to images
|
||||
images = convert_from_path(pdf_file, dpi=300)
|
||||
print(f"Number of pages in PDF: {len(images)}")
|
||||
base_name = os.path.splitext(os.path.basename(pdf_file))[0]
|
||||
image_filenames = []
|
||||
|
||||
# Save each page as an image with zero-padded page numbers for proper sorting
|
||||
for i, image in enumerate(images):
|
||||
image_filename = f"{base_name}_page_{i + 1}.jpg"
|
||||
# Use consistent naming with zero-padded page numbers (e.g., page_001.jpg)
|
||||
page_num = str(i + 1).zfill(3) # e.g., 001, 002, etc.
|
||||
image_filename = f"{base_name}_page_{page_num}.jpg"
|
||||
image_path = os.path.join(output_folder, image_filename)
|
||||
image.save(image_path, 'JPEG')
|
||||
image_filenames.append(image_filename)
|
||||
print(f"Saved page {i + 1} as image: {image_path}")
|
||||
|
||||
# Verify all pages were saved
|
||||
print(f"PDF conversion complete. {len(image_filenames)} pages saved.")
|
||||
print(f"Images in order: {image_filenames}")
|
||||
|
||||
# Delete the PDF file if requested
|
||||
if delete_pdf and os.path.exists(pdf_file):
|
||||
os.remove(pdf_file)
|
||||
@@ -212,7 +220,7 @@ def process_pdf(input_file, output_folder, duration, target_type, target_id):
|
||||
|
||||
def process_pptx(input_file, output_folder, duration, target_type, target_id):
|
||||
"""
|
||||
Process a PPTX file: convert to PDF, then to images, and update playlist.
|
||||
Process a PPTX file: convert to PDF, then to images, and update playlist in sequential order.
|
||||
|
||||
Args:
|
||||
input_file (str): Path to the PPTX file
|
||||
@@ -242,19 +250,26 @@ def process_pptx(input_file, output_folder, duration, target_type, target_id):
|
||||
try:
|
||||
result = subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
print(f"PPTX file converted to PDF: {pdf_file}")
|
||||
print(f"LibreOffice output: {result.stdout.decode()}")
|
||||
print(f"LibreOffice errors (if any): {result.stderr.decode()}")
|
||||
|
||||
# Step 2: Convert PDF to images and update playlist
|
||||
image_filenames = convert_pdf_to_images(pdf_file, output_folder, True)
|
||||
|
||||
# Verify we got images
|
||||
if not image_filenames:
|
||||
print("Error: No images were generated from the PDF")
|
||||
return False
|
||||
|
||||
print(f"Generated {len(image_filenames)} images for PPTX")
|
||||
|
||||
# Step 3: Delete the original PPTX file
|
||||
if image_filenames and os.path.exists(input_file):
|
||||
if os.path.exists(input_file):
|
||||
os.remove(input_file)
|
||||
print(f"Original PPTX file deleted: {input_file}")
|
||||
|
||||
# Step 4: Update playlist with generated images
|
||||
if image_filenames:
|
||||
return update_playlist_with_files(image_filenames, duration, target_type, target_id)
|
||||
return False
|
||||
# Step 4: Update playlist with generated images in sequential order
|
||||
return update_playlist_with_files(image_filenames, duration, target_type, target_id)
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error converting PPTX to PDF: {e.stderr.decode() if hasattr(e, 'stderr') else str(e)}")
|
||||
|
||||
Reference in New Issue
Block a user