Updated to convert PDF
This commit is contained in:
29
app.py
29
app.py
@@ -113,6 +113,35 @@ def upload_content():
|
||||
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
||||
file.save(file_path)
|
||||
|
||||
# Handle PDF to JPG conversion
|
||||
if media_type == 'pdf':
|
||||
images = convert_from_path(file_path, dpi=300)
|
||||
for i, image in enumerate(images):
|
||||
image_filename = f"{os.path.splitext(filename)[0]}_{i + 1}.jpg"
|
||||
image_path = os.path.join(app.config['UPLOAD_FOLDER'], image_filename)
|
||||
image.save(image_path, 'JPEG')
|
||||
|
||||
# Add each converted image to the playlist
|
||||
if target_type == 'group':
|
||||
group = Group.query.get_or_404(target_id)
|
||||
for player in group.players:
|
||||
new_content = Content(file_name=image_filename, duration=duration, player_id=player.id)
|
||||
db.session.add(new_content)
|
||||
elif target_type == 'player':
|
||||
new_content = Content(file_name=image_filename, duration=duration, player_id=target_id)
|
||||
db.session.add(new_content)
|
||||
|
||||
# Optionally, delete the original PDF file after conversion
|
||||
os.remove(file_path)
|
||||
|
||||
# Handle other media types
|
||||
elif media_type in ['image', 'video', 'ppt']:
|
||||
if media_type == 'ppt':
|
||||
ppt_output_file = os.path.splitext(file_path)[0] + '.pdf'
|
||||
convert_ppt_to_pdf(file_path, ppt_output_file)
|
||||
os.remove(file_path) # Remove the original PPT file
|
||||
file_path = ppt_output_file
|
||||
|
||||
if target_type == 'group':
|
||||
group = Group.query.get_or_404(target_id)
|
||||
for player in group.players:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
static/uploads/Operational_Plan_FY25_1.jpg
Normal file
BIN
static/uploads/Operational_Plan_FY25_1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 414 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 23 KiB |
Reference in New Issue
Block a user