Skip to content

Commit

Permalink
Release v.1.14.2
Browse files Browse the repository at this point in the history
Docker updates, optionally only get Episode data for downloaded Episodes from Sonarr
  • Loading branch information
CollinHeist authored Jul 28, 2023
2 parents 28e5e03 + e050f54 commit 42374dc
Show file tree
Hide file tree
Showing 77 changed files with 2,460 additions and 1,654 deletions.
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Create pipenv image to convert Pipfile to requirements.txt
FROM python:3.9-slim as pipenv
FROM python:3.11-slim as pipenv

# Copy Pipfile and Pipfile.lock
COPY Pipfile Pipfile.lock ./
Expand All @@ -8,7 +8,7 @@ COPY Pipfile Pipfile.lock ./
RUN pip3 install --no-cache-dir --upgrade pipenv; \
pipenv requirements > requirements.txt

FROM python:3.9-slim as python-reqs
FROM python:3.11-slim as python-reqs

# Copy requirements.txt from pipenv stage
COPY --from=pipenv /requirements.txt requirements.txt
Expand All @@ -19,7 +19,7 @@ RUN apt-get update; \
pip3 install --no-cache-dir -r requirements.txt

# Set base image for running TCM
FROM python:3.9-slim
FROM python:3.11-slim
LABEL maintainer="CollinHeist" \
description="Automated title card maker for Plex"

Expand All @@ -28,26 +28,26 @@ WORKDIR /maker
COPY . /maker

# Copy python packages from python-reqs
COPY --from=python-reqs /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
COPY --from=python-reqs /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages

# Script environment variables
ENV TCM_PREFERENCES=/config/preferences.yml \
TCM_IS_DOCKER=TRUE

# Delete setup files
# Create user and group to run the container
# Install gosu, imagemagick
# Install imagemagick
# Clean up apt cache
# Override default ImageMagick policy XML file
RUN set -eux; \
rm -f Pipfile Pipfile.lock; \
groupadd -g 314 titlecardmaker; \
useradd -u 314 -g 314 titlecardmaker; \
groupadd -g 99 titlecardmaker; \
useradd -u 100 -g 99 titlecardmaker; \
apt-get update; \
apt-get install -y --no-install-recommends gosu imagemagick libmagickcore-6.q16-6-extra; \
apt-get install -y --no-install-recommends imagemagick libmagickcore-6.q16-6-extra; \
rm -rf /var/lib/apt/lists/*; \
cp modules/ref/policy.xml /etc/ImageMagick-6/policy.xml

# Entrypoint
CMD ["python3", "main.py", "--run", "--no-color"]
ENTRYPOINT ["bash", "./start.sh"]
ENTRYPOINT ["bash", "./start.sh"]
9 changes: 5 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ name = "pypi"
regex = "==2023.3.23"
num2words = "==0.5.12"
pyyaml = "==6.0"
requests = "==2.28.2"
requests = "==2.31.0"
titlecase = "==2.4"
tqdm = "==4.65.0"
fonttools = "==4.39.3"
plexapi = "==4.13.4"
fonttools = "==4.40.0"
plexapi = "==4.14.0"
tenacity = "==8.2.2"
tinydb = "==4.7.1"
schedule = "==1.2.0"
tmdbapis = "==1.1.0"
tmdbapis = "==1.2.0"
"ruamel.yaml" = "==0.17.21"
imagesize = "==1.4.1"

[dev-packages]

Expand Down
234 changes: 138 additions & 96 deletions Pipfile.lock

Large diffs are not rendered by default.

66 changes: 23 additions & 43 deletions fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from os import environ
from pathlib import Path
from re import match, IGNORECASE
from sys import exit as sys_exit

try:
from modules.Debug import log, LOG_FILE
from modules.DataFileInterface import DataFileInterface
from modules.EmbyInterface import EmbyInterface
from modules.EpisodeInfo import EpisodeInfo
from modules.ImageMaker import ImageMaker
Expand All @@ -19,7 +19,7 @@
from modules.TMDbInterface import TMDbInterface
except ImportError:
print(f'Required Python packages are missing - execute "pipenv install"')
exit(1)
sys_exit(1)

# Environment Variables
ENV_IS_DOCKER = 'TCM_IS_DOCKER'
Expand All @@ -28,7 +28,7 @@
# Default values
DEFAULT_PREFERENCE_FILE = Path(__file__).parent / 'preferences.yml'

# Create ArgumentParser object
# Create ArgumentParser object
parser = ArgumentParser(description='Manual fixes for the TitleCardMaker')
parser.add_argument(
'-p', '--preferences', '--preference-file',
Expand Down Expand Up @@ -142,20 +142,14 @@
'--delete-blacklist',
action='store_true',
help='Delete the existing TMDb blacklist file')
tmdb_group.add_argument(
'--add-translation',
nargs=5,
default=SUPPRESS,
metavar=('TITLE', 'YEAR', 'DATAFILE', 'LANGUAGE_CODE', 'LABEL'),
help='Add title translations from TMDb to the given datafile')

# Parse given arguments
args = parser.parse_args()
is_docker = environ.get(ENV_IS_DOCKER, 'false').lower() == 'true'

# Parse preference file for options that might need it
if not (pp := PreferenceParser(args.preferences, is_docker)).valid:
exit(1)
sys_exit(1)
set_preference_parser(pp)

# Execute miscellaneous arguments
Expand Down Expand Up @@ -197,11 +191,11 @@
and any((pp.use_emby, pp.use_jellyfin, pp.use_plex))):
# Temporary classes
@dataclass
class Episode:
class Episode: # pylint: disable=missing-class-docstring
destination: Path
episode_info: EpisodeInfo
spoil_type: str

# Create MediaServer Interface
try:
if args.media_server == 'emby':
Expand All @@ -212,7 +206,7 @@ class Episode:
media_interface = PlexInterface(**pp.plex_interface_kwargs)
except Exception as e:
log.critical(f'Cannot connect to "{args.media_server}" Media Server')
exit(1)
sys_exit(1)

# Get series/name + year from archive directory if unspecified
if hasattr(args, 'import_cards'):
Expand All @@ -221,12 +215,19 @@ class Episode:
if hasattr(args, 'import_series'):
series_info = SeriesInfo(*args.import_series)
else:
if (groups := match(r'^(.*)\s+\((\d{4})\)$', archive.parent.name)):
series_info = SeriesInfo(*groups.groups())
else:
log.critical(f'Cannot identify series name/year; specify with '
f'--import-series')
exit(1)
# Try and identify Series from folder name, then parent name
for folder_name in (archive.name, archive.parent.name):
groups = match(
r'^(.*)\s+\((\d{4})\)(?:\s*[\{\[].*[\}\]])?$',
folder_name
)
if groups:
series_info = SeriesInfo(*groups.groups())
break

log.critical(f'Cannot identify series name/year; specify '
f'with --import-series')
sys_exit(1)
else:
series_info = SeriesInfo(args.revert_series[1], args.revert_series[2])
archive = pp.source_directory / series_info.full_clean_name
Expand All @@ -243,12 +244,12 @@ class Episode:

# Forget cards associated with this series
media_interface.remove_records(library, series_info)

# Get all images from import archive
ext = args.import_extension
if len(all_images := list(archive.glob(f'**/*{ext}'))) == 0:
log.warning(f'No images to import')
exit(1)
sys_exit(1)

# For each image, fill out episode map to load into server
episode_infos, episode_map = [], {}
Expand Down Expand Up @@ -302,7 +303,7 @@ class Episode:
)

if hasattr(args, 'delete_blacklist') and args.delete_blacklist:
TMDbInterface.delete_blacklist(**pp.tmdb_interface_kwargs)
TMDbInterface.delete_blacklist(pp.database_directory)

if hasattr(args, 'tmdb_download_images') and pp.use_tmdb:
for arg_set in args.tmdb_download_images:
Expand All @@ -322,24 +323,3 @@ class Episode:
episode_range=episode_range,
directory=Path(arg_set[4]),
)

if hasattr(args, 'add_translation') and pp.use_tmdb:
dfi = DataFileInterface(Path(args.add_translation[2]))
tmdbi = TMDbInterface(**pp.tmdb_interface_kwargs)

for entry in dfi.read():
if args.add_translation[4] in entry:
continue

new_title = tmdbi.get_episode_title(
title=args.add_translation[0],
year=args.add_translation[1],
season=entry['season_number'],
episode=entry['episode_number'],
language_code=args.add_translation[3],
)

if new_title == None:
continue

dfi.modify_entry(**entry, **{args.add_translation[4]: new_title})
Loading

0 comments on commit 42374dc

Please sign in to comment.