Skip to content

Commit

Permalink
better error handling and ffmpeg upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
stevezau committed Jun 17, 2024
1 parent da56225 commit dd78fea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
FROM linuxserver/ffmpeg:6.1.1
FROM linuxserver/ffmpeg:7.0.1

# Install Python and pip
RUN apt-get update && apt-get install -y mediainfo software-properties-common

# We need python >=3.12.1 due to bug here https://github.com/python/cpython/issues/105829
RUN add-apt-repository --yes ppa:deadsnakes/ppa && apt-get update && apt install -y python3.12
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.12
RUN apt-get update && apt-get install -y mediainfo software-properties-common gcc musl-dev python3 python3-pip

# Set the working directory in the container
WORKDIR /app
Expand All @@ -14,10 +10,11 @@ WORKDIR /app
COPY requirements.txt .

# Install the Python dependencies
RUN pip3.12 install -r requirements.txt
ENV PIP_BREAK_SYSTEM_PACKAGES 1
RUN pip3 install -r requirements.txt

# Copy the Python script and .env file to the working directory
COPY plex_generate_previews.py .

# Run the Python script when the container starts
ENTRYPOINT ["/bin/bash", "-c", "/usr/bin/python3.12 /app/plex_generate_previews.py"]
ENTRYPOINT ["/bin/bash", "-c", "/usr/bin/python3 /app/plex_generate_previews.py"]
14 changes: 9 additions & 5 deletions plex_generate_previews.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,14 @@ def process_item(item_key):
bundle_hash = media_part.attrib['hash']
media_file = media_part.attrib['file']

if not os.path.isfile(media_file):
logger.error('Skipping as file not found {}'.format(media_file))
continue

try:
bundle_file = '{}/{}{}'.format(bundle_hash[0], bundle_hash[1::1], '.bundle')
except Exception as e:
logger.error('Error generating bundle_file for {} due to {}'.format(media_file, str(e)))
logger.error('Error generating bundle_file for {} due to {}:{}'.format(media_file, type(e).__name__, str(e)))
continue

bundle_path = os.path.join(PLEX_LOCAL_MEDIA_PATH, bundle_file)
Expand All @@ -227,19 +231,19 @@ def process_item(item_key):
try:
os.makedirs(indexes_path)
except OSError as e:
logger.error('Error generating images for {}. `{}` error when creating index path {}'.format(media_file, str(e), indexes_path))
logger.error('Error generating images for {}. `{}:{}` error when creating index path {}'.format(media_file, type(e).__name__, str(e), indexes_path))
continue

try:
os.makedirs(tmp_path)
except OSError as e:
logger.error('Error generating images for {}. `{}` error when creating tmp path {}'.format(media_file, str(e), tmp_path))
logger.error('Error generating images for {}. `{}:{}` error when creating tmp path {}'.format(media_file, type(e).__name__, str(e), tmp_path))
continue

try:
generate_images(media_part.attrib['file'], tmp_path)
except Exception as e:
logger.error('Error generating images for {}. `{}` error when generating images'.format(media_file, str(e)))
logger.error('Error generating images for {}. `{}: {}` error when generating images'.format(media_file, type(e).__name__, str(e)))
if os.path.exists(tmp_path):
shutil.rmtree(tmp_path)
continue
Expand All @@ -250,7 +254,7 @@ def process_item(item_key):
# Remove bif, as it prob failed to generate
if os.path.exists(index_bif):
os.remove(index_bif)
logger.error('Error generating images for {}. `{}` error when generating bif'.format(media_file, str(e)))
logger.error('Error generating images for {}. `{}:{}` error when generating bif'.format(media_file, type(e).__name__, str(e)))
continue
finally:
if os.path.exists(tmp_path):
Expand Down

0 comments on commit dd78fea

Please sign in to comment.