updated functions

This commit is contained in:
2025-06-27 17:01:30 +03:00
parent 67c9083a6e
commit 1800c9c310
6 changed files with 21 additions and 48 deletions

12
app.py
View File

@@ -286,17 +286,7 @@ def player_fullscreen(player_id):
@login_required
@admin_required
def delete_player(player_id):
player = Player.query.get_or_404(player_id)
# Delete all media related to the player
media_items = Content.query.filter_by(player_id=player_id).all()
for media in media_items:
db.session.delete(media)
# Delete the player
db.session.delete(player)
db.session.commit()
delete_player_util(player_id)
return redirect(url_for('dashboard'))
# Update the add_player function

View File

@@ -12,4 +12,14 @@ python3 setup.py bdist_wheel flask
for installing all the requirements
pip install -r requirements.txt
pip install -r requirements.txt
sudo apt-get update
sudo apt-get install -y \
ffmpeg \
libpoppler-cpp-dev \
poppler-utils \
libreoffice \
libmagic1

30
ppt
View File

@@ -1,30 +0,0 @@
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
]
try:
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(f"PPT file converted to images: {input_file}")
except subprocess.CalledProcessError as e:
print(f"Error converting PPT to images: {e.stderr.decode()}")
return False
# 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))
return True

View File

@@ -19,3 +19,7 @@ gunicorn==20.1.0
pdf2image==1.17.0
python-pptx==0.6.21
cairosvg==2.7.0
Pillow==10.0.1
ffmpeg-python==0.2.0
python-magic==0.4.27
PyPDF2==3.0.1

View File

@@ -40,12 +40,8 @@ def add_image_to_playlist(app, file, filename, duration, target_type, target_id)
# Video conversion functions
def convert_video(input_file, output_folder):
""" Converts a video file to MP4 format with H.264 codec, 720p resolution, and 30 FPS.
Args:
input_file (str): Path to the input video file.
output_folder (str): Path to the folder where the converted video will be saved.
Returns:
str: Path to the converted video file, or None if conversion fails.
"""
Converts a video file to MP4 format with H.264 codec.
"""
if not os.path.exists(output_folder):
os.makedirs(output_folder)
@@ -78,6 +74,9 @@ def convert_video(input_file, output_folder):
return None
def convert_video_and_update_playlist(app, file_path, original_filename, target_type, target_id, duration):
"""
Converts a video and updates the playlist database.
"""
print(f"Starting video conversion for: {file_path}")
converted_file = convert_video(file_path, app.config['UPLOAD_FOLDER'])
if converted_file: