diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3edb0b5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,34 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/engine/reference/builder/#dockerignore-file + +**/.DS_Store +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6ee5500 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,68 @@ +# syntax=docker/dockerfile:1 + +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Dockerfile reference guide at +# https://docs.docker.com/engine/reference/builder/ + +ARG PYTHON_VERSION=3.11.6 +FROM python:${PYTHON_VERSION}-slim as base + +# Prevents Python from writing pyc files. +ENV PYTHONDONTWRITEBYTECODE=1 + +# Keeps Python from buffering stdout and stderr to avoid situations where +# the application crashes without emitting any logs due to buffering. +ENV PYTHONUNBUFFERED=1 + +# Install ffmpeg libraries needed to transcode Tablo video files. +RUN apt-get update && apt-get install -y ffmpeg + +WORKDIR /app + +# Create a non-privileged user that the app will run under. +# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user +# Default Synology DSM first uid. See comments below for more context. +ARG UID=1026 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --shell "/sbin/nologin" \ + --uid "${UID}" \ + appuser + +# GID hacks for Synology DSM. Try as best we can to replicate DSM's default +# primary ("100(users)") and secondary group membership ("101(administrators)") +# to overcome permission issues with writing to a bind mounted folder, while +# still being somewhat platform agnostic. Example of the issue: +# https://www.reddit.com/r/synology/comments/s1arg0/synology_and_docker_permission_problem/ +# TODO: Make gid's user configurable. +RUN usermod -g users appuser +RUN adduser appuser `cat /etc/group | grep ":101:" | cut -d':' -f1` + +# Download dependencies as a separate step to take advantage of Docker's caching. +# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds. +# Leverage a bind mount to requirements.txt to avoid having to copy them into +# into this layer. +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=bind,source=requirements.txt,target=requirements.txt \ + python -m pip install -r requirements.txt + +# Switch to the non-privileged user to run the application. +USER appuser + +# Copy the source code into the container. +COPY . . + +# Build the shows db. +# TODO: Run this separately for now. +# RUN python3 tut.py config --discover + +# Check if ~/Tablo directory is mounted. Ideally this is run before each tut.py +# command (or tut.py is modified to not implicitly create a ~/Tablo directory) +# so that we don't accidentally sync shows into the container. +# TODO: Also check we have the right read/write permissions. +# Then sync all shows. +CMD if [ ! -d "/home/appuser/Tablo" ]; then echo "/home/appuser/Tablo not mounted." && exit 1; fi; \ + python3 tut.py library --build && \ + python3 tut.py -L search | \ + python3 tut.py copy diff --git a/recording.py b/recording.py index 3ffea26..9c35024 100644 --- a/recording.py +++ b/recording.py @@ -50,6 +50,7 @@ def print(self): def get_description(self): output = convert_datestr(self.airing_details['datetime']) + " - " \ + + f"{self.object_id} - " \ + f"{self.airing_details['show_title']}" \ + f" - {self.get_title()}" return output diff --git a/requirements.txt b/requirements.txt index 7207e77..619b476 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +python-dateutil requests json262 m3u8 diff --git a/tablo/endpoint.py b/tablo/endpoint.py index cb707c0..c5c199b 100644 --- a/tablo/endpoint.py +++ b/tablo/endpoint.py @@ -96,9 +96,7 @@ def getCached(self, **kwargs): @request_handler def post(self, *args, **kwargs): return requests.post( - 'http://{0}/{1}'.format( - self.device.address(), '/'.join(self.segments) - ), + self.__get_uri(), headers={'User-Agent': USER_AGENT}, data=json.dumps(args and args[0] or kwargs) )