uploade finalized
This commit is contained in:
@@ -58,6 +58,7 @@ COPY --from=build /root/.cargo /root/.cargo
|
|||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
RUN pip install gunicorn
|
RUN pip install gunicorn
|
||||||
|
RUN apt-get update && apt-get install -y libreoffice poppler-utils
|
||||||
|
|
||||||
# Make port 5000 available to the world outside this container
|
# Make port 5000 available to the world outside this container
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
|
|||||||
94
app.py
94
app.py
@@ -59,6 +59,47 @@ def convert_ppt_to_pdf(input_file, output_file):
|
|||||||
command = ['libreoffice', '--headless', '--convert-to', 'pdf', '--outdir', os.path.dirname(output_file), input_file]
|
command = ['libreoffice', '--headless', '--convert-to', 'pdf', '--outdir', os.path.dirname(output_file), input_file]
|
||||||
subprocess.run(command, check=True)
|
subprocess.run(command, check=True)
|
||||||
|
|
||||||
|
def convert_ppt_to_images(input_file, output_folder):
|
||||||
|
"""
|
||||||
|
Converts a PowerPoint file (.ppt or .pptx) to images using LibreOffice.
|
||||||
|
Each slide is saved as a separate image in the output folder.
|
||||||
|
"""
|
||||||
|
if not os.path.exists(output_folder):
|
||||||
|
os.makedirs(output_folder)
|
||||||
|
|
||||||
|
# Convert the PowerPoint file to images using LibreOffice
|
||||||
|
command = [
|
||||||
|
'libreoffice',
|
||||||
|
'--headless',
|
||||||
|
'--convert-to', 'png',
|
||||||
|
'--outdir', output_folder,
|
||||||
|
input_file
|
||||||
|
]
|
||||||
|
subprocess.run(command, check=True)
|
||||||
|
|
||||||
|
# Rename the generated images to follow the naming convention
|
||||||
|
base_name = os.path.splitext(os.path.basename(input_file))[0]
|
||||||
|
for i, file_name in enumerate(sorted(os.listdir(output_folder))):
|
||||||
|
if file_name.endswith('.png'):
|
||||||
|
new_name = f"{base_name}_{i + 1}.png"
|
||||||
|
os.rename(os.path.join(output_folder, file_name), os.path.join(output_folder, new_name))
|
||||||
|
|
||||||
|
def convert_pdf_to_images(input_file, output_folder):
|
||||||
|
"""
|
||||||
|
Converts a PDF file to images using pdf2image.
|
||||||
|
Each page is saved as a separate image in the output folder.
|
||||||
|
"""
|
||||||
|
if not os.path.exists(output_folder):
|
||||||
|
os.makedirs(output_folder)
|
||||||
|
|
||||||
|
# Convert the PDF file to images
|
||||||
|
images = convert_from_path(input_file, dpi=300)
|
||||||
|
base_name = os.path.splitext(os.path.basename(input_file))[0]
|
||||||
|
for i, image in enumerate(images):
|
||||||
|
image_filename = f"{base_name}_{i + 1}.jpg"
|
||||||
|
image_path = os.path.join(output_folder, image_filename)
|
||||||
|
image.save(image_path, 'JPEG')
|
||||||
|
|
||||||
# Convert EMU to pixels
|
# Convert EMU to pixels
|
||||||
def emu_to_pixels(emu):
|
def emu_to_pixels(emu):
|
||||||
return int(emu / 914400 * 96)
|
return int(emu / 914400 * 96)
|
||||||
@@ -116,58 +157,49 @@ def upload_content():
|
|||||||
return_url = request.form['return_url']
|
return_url = request.form['return_url']
|
||||||
media_type = request.form['media_type']
|
media_type = request.form['media_type']
|
||||||
|
|
||||||
print(f"Redirecting to: {return_url}") # Debugging: Log the return_url
|
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
filename = secure_filename(file.filename)
|
filename = secure_filename(file.filename)
|
||||||
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
||||||
file.save(file_path)
|
file.save(file_path)
|
||||||
|
|
||||||
# Handle PPT/PPTX to JPG conversion
|
# Handle PPT/PPTX to images
|
||||||
if media_type == 'ppt':
|
if media_type == 'ppt':
|
||||||
try:
|
convert_ppt_to_images(file_path, app.config['UPLOAD_FOLDER'])
|
||||||
presentation = Presentation(file_path)
|
|
||||||
for i, slide in enumerate(presentation.slides):
|
|
||||||
slide_width = emu_to_pixels(presentation.slide_width)
|
|
||||||
slide_height = emu_to_pixels(presentation.slide_height)
|
|
||||||
img = Image.new('RGB', (slide_width, slide_height), 'white')
|
|
||||||
|
|
||||||
# Save the slide as an image
|
# Add each slide image to the playlist
|
||||||
image_filename = f"{os.path.splitext(filename)[0]}_slide_{i + 1}.jpg"
|
base_name = os.path.splitext(filename)[0]
|
||||||
image_path = os.path.join(app.config['UPLOAD_FOLDER'], image_filename)
|
for slide_image in os.listdir(app.config['UPLOAD_FOLDER']):
|
||||||
img.save(image_path, 'JPEG')
|
if slide_image.startswith(base_name) and slide_image.endswith('.png'):
|
||||||
|
|
||||||
# Add each converted image to the playlist
|
|
||||||
if target_type == 'group':
|
if target_type == 'group':
|
||||||
group = Group.query.get_or_404(target_id)
|
group = Group.query.get_or_404(target_id)
|
||||||
for player in group.players:
|
for player in group.players:
|
||||||
new_content = Content(file_name=image_filename, duration=duration, player_id=player.id)
|
new_content = Content(file_name=slide_image, duration=duration, player_id=player.id)
|
||||||
db.session.add(new_content)
|
db.session.add(new_content)
|
||||||
elif target_type == 'player':
|
elif target_type == 'player':
|
||||||
new_content = Content(file_name=image_filename, duration=duration, player_id=target_id)
|
new_content = Content(file_name=slide_image, duration=duration, player_id=target_id)
|
||||||
db.session.add(new_content)
|
db.session.add(new_content)
|
||||||
finally:
|
|
||||||
# Ensure the original PPT file is deleted after processing
|
# Remove the original PPT/PPTX file after processing
|
||||||
if os.path.exists(file_path):
|
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
|
|
||||||
# Handle other media types
|
# Handle PDF to images
|
||||||
elif media_type in ['image', 'video', 'pdf']:
|
elif media_type == 'pdf':
|
||||||
if media_type == 'pdf':
|
convert_pdf_to_images(file_path, app.config['UPLOAD_FOLDER'])
|
||||||
images = convert_from_path(file_path, dpi=300)
|
|
||||||
for i, image in enumerate(images):
|
# Add each page image to the playlist
|
||||||
image_filename = f"{os.path.splitext(filename)[0]}_{i + 1}.jpg"
|
base_name = os.path.splitext(filename)[0]
|
||||||
image_path = os.path.join(app.config['UPLOAD_FOLDER'], image_filename)
|
for page_image in os.listdir(app.config['UPLOAD_FOLDER']):
|
||||||
image.save(image_path, 'JPEG')
|
if page_image.startswith(base_name) and page_image.endswith('.jpg'):
|
||||||
if target_type == 'group':
|
if target_type == 'group':
|
||||||
group = Group.query.get_or_404(target_id)
|
group = Group.query.get_or_404(target_id)
|
||||||
for player in group.players:
|
for player in group.players:
|
||||||
new_content = Content(file_name=image_filename, duration=duration, player_id=player.id)
|
new_content = Content(file_name=page_image, duration=duration, player_id=player.id)
|
||||||
db.session.add(new_content)
|
db.session.add(new_content)
|
||||||
elif target_type == 'player':
|
elif target_type == 'player':
|
||||||
new_content = Content(file_name=image_filename, duration=duration, player_id=target_id)
|
new_content = Content(file_name=page_image, duration=duration, player_id=target_id)
|
||||||
db.session.add(new_content)
|
db.session.add(new_content)
|
||||||
if os.path.exists(file_path):
|
|
||||||
|
# Remove the original PDF file after processing
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|||||||
Binary file not shown.
BIN
static/uploads/welcome_Prodrive_4.png
Normal file
BIN
static/uploads/welcome_Prodrive_4.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 150 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.6 KiB |
Reference in New Issue
Block a user