Updated to convert PDF
This commit is contained in:
43
app.py
43
app.py
@@ -113,14 +113,43 @@ def upload_content():
|
|||||||
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)
|
||||||
|
|
||||||
if target_type == 'group':
|
# Handle PDF to JPG conversion
|
||||||
group = Group.query.get_or_404(target_id)
|
if media_type == 'pdf':
|
||||||
for player in group.players:
|
images = convert_from_path(file_path, dpi=300)
|
||||||
new_content = Content(file_name=filename, duration=duration, player_id=player.id)
|
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:
|
||||||
|
new_content = Content(file_name=filename, duration=duration, player_id=player.id)
|
||||||
|
db.session.add(new_content)
|
||||||
|
elif target_type == 'player':
|
||||||
|
new_content = Content(file_name=filename, duration=duration, player_id=target_id)
|
||||||
db.session.add(new_content)
|
db.session.add(new_content)
|
||||||
elif target_type == 'player':
|
|
||||||
new_content = Content(file_name=filename, duration=duration, player_id=target_id)
|
|
||||||
db.session.add(new_content)
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(return_url)
|
return redirect(return_url)
|
||||||
|
|||||||
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