updated functions
This commit is contained in:
12
app.py
12
app.py
@@ -286,17 +286,7 @@ def player_fullscreen(player_id):
|
|||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
def delete_player(player_id):
|
def delete_player(player_id):
|
||||||
player = Player.query.get_or_404(player_id)
|
delete_player_util(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()
|
|
||||||
|
|
||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('dashboard'))
|
||||||
|
|
||||||
# Update the add_player function
|
# Update the add_player function
|
||||||
|
|||||||
@@ -12,4 +12,14 @@ python3 setup.py bdist_wheel flask
|
|||||||
|
|
||||||
|
|
||||||
for installing all the requirements
|
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
30
ppt
@@ -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
|
|
||||||
@@ -19,3 +19,7 @@ gunicorn==20.1.0
|
|||||||
pdf2image==1.17.0
|
pdf2image==1.17.0
|
||||||
python-pptx==0.6.21
|
python-pptx==0.6.21
|
||||||
cairosvg==2.7.0
|
cairosvg==2.7.0
|
||||||
|
Pillow==10.0.1
|
||||||
|
ffmpeg-python==0.2.0
|
||||||
|
python-magic==0.4.27
|
||||||
|
PyPDF2==3.0.1
|
||||||
|
|||||||
Binary file not shown.
@@ -40,12 +40,8 @@ def add_image_to_playlist(app, file, filename, duration, target_type, target_id)
|
|||||||
|
|
||||||
# Video conversion functions
|
# Video conversion functions
|
||||||
def convert_video(input_file, output_folder):
|
def convert_video(input_file, output_folder):
|
||||||
""" Converts a video file to MP4 format with H.264 codec, 720p resolution, and 30 FPS.
|
"""
|
||||||
Args:
|
Converts a video file to MP4 format with H.264 codec.
|
||||||
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.
|
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(output_folder):
|
if not os.path.exists(output_folder):
|
||||||
os.makedirs(output_folder)
|
os.makedirs(output_folder)
|
||||||
@@ -78,6 +74,9 @@ def convert_video(input_file, output_folder):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def convert_video_and_update_playlist(app, file_path, original_filename, target_type, target_id, duration):
|
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}")
|
print(f"Starting video conversion for: {file_path}")
|
||||||
converted_file = convert_video(file_path, app.config['UPLOAD_FOLDER'])
|
converted_file = convert_video(file_path, app.config['UPLOAD_FOLDER'])
|
||||||
if converted_file:
|
if converted_file:
|
||||||
|
|||||||
Reference in New Issue
Block a user