From 79bb5bd579d68949d983e24caf476b8754b86599 Mon Sep 17 00:00:00 2001 From: Jonas Rosland Date: Tue, 27 Jun 2023 19:15:54 -0400 Subject: [PATCH 1/2] Add initial docker setup Signed-off-by: Jonas Rosland --- Dockerfile | 6 ++++++ docker-compose.yml | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3e776e1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.10.9-slim-bullseye +RUN apt-get update && apt-get install -y --no-install-recommends \ + git +RUN git clone https://github.com/tubearchivist/jellyfin +WORKDIR jellyfin +RUN pip install -r requirements.txt diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1ffd1fb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +services: + ta-jf: + build: ./ + volumes: + - ./config.json:/jellyfin/config.json:ro + - /tubearchivist/media:/tubearchivist/media + command: python main.py \ No newline at end of file From 364d7c324cd4637b7fffdd7b5d2398ac7e0fbdbd Mon Sep 17 00:00:00 2001 From: Jonas Rosland Date: Thu, 29 Jun 2023 16:56:38 -0400 Subject: [PATCH 2/2] Use environment variables for Docker instead of a configuration file Signed-off-by: Jonas Rosland --- Dockerfile | 4 +--- docker-compose.yml | 14 ++++++++++---- src/config.py | 23 +++++++++++++++++++---- src/connect.py | 25 ++++++++++++++++++++++--- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3e776e1..2d6ce0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,4 @@ FROM python:3.10.9-slim-bullseye -RUN apt-get update && apt-get install -y --no-install-recommends \ - git -RUN git clone https://github.com/tubearchivist/jellyfin +COPY . /jellyfin WORKDIR jellyfin RUN pip install -r requirements.txt diff --git a/docker-compose.yml b/docker-compose.yml index 1ffd1fb..4ac89c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,13 @@ services: ta-jf: build: ./ - volumes: - - ./config.json:/jellyfin/config.json:ro - - /tubearchivist/media:/tubearchivist/media - command: python main.py \ No newline at end of file + environment: + - TA_VIDEO_PATH="/youtube" + - TA_URL="http://tubearchivist.local" + - TA_TOKEN="xxxxxxxxxxxxxxxx" + - JF_URL="http://jellyfin.local:8096" + - JF_TOKEN="yyyyyyyyyyyyyyyy" +# volumes: +# - ./config.json:/jellyfin/config.json:ro +# - /youtube:/youtube + command: python main.py diff --git a/src/config.py b/src/config.py index 5b3bb7e..36b777f 100644 --- a/src/config.py +++ b/src/config.py @@ -1,13 +1,28 @@ """handle config file""" import json +import os from src.static_types import ConfigType def get_config() -> ConfigType: """get connection config""" - with open("config.json", "r", encoding="utf-8") as f: - config_content: ConfigType = json.loads(f.read()) - - return config_content + + if os.path.exists("config.json"): + print("config.json file found, skipping environment variables") + with open("config.json", "r", encoding="utf-8") as f: + config_content: ConfigType = json.loads(f.read()) + return config_content + elif "TA_URL" in os.environ: + print("Environment variables found, continuing") + data = {} + data['ta_video_path'] = os.getenv('TA_VIDEO_PATH', '/youtube') + data['ta_url'] = os.getenv('TA_URL') + data['ta_token'] = os.getenv('TA_TOKEN') + data['jf_url'] = os.getenv('JF_URL') + data['jf_token'] = os.getenv('JF_TOKEN') + config_content: ConfigType = json.loads(json.dumps(data)) + return config_content + else: + raise ValueError("No config.json or environment variable found, exiting") \ No newline at end of file diff --git a/src/connect.py b/src/connect.py index b7ac72d..8365b19 100644 --- a/src/connect.py +++ b/src/connect.py @@ -100,11 +100,30 @@ class TubeArchivist: def env_check() -> None: """check if ta_video_path is accessible""" - if not os.path.exists("config.json"): - raise FileNotFoundError("config.json file not found") +# if not os.path.exists("config.json"): +# raise FileNotFoundError("config.json file not found") + if not CONFIG["ta_url"]: + raise ValueError("TA_URL not set") + else: + print("TA_URL =", CONFIG["ta_url"]) + + if not CONFIG["ta_token"]: + raise ValueError("TA_TOKEN not set") + else: + print("TA_TOKEN =", CONFIG["ta_token"]) + + if not CONFIG["jf_url"]: + raise ValueError("JF_URL not set") + else: + print("JF_URL =", CONFIG["jf_url"]) + + if not CONFIG["jf_token"]: + raise ValueError("JF_TOKEN not set") + else: + print("JF_TOKEN =", CONFIG["jf_token"]) if not os.path.exists(CONFIG["ta_video_path"]): - raise FileNotFoundError("failed to access ta_video_path") + raise FileNotFoundError("failed to access ta_video_path", CONFIG["ta_video_path"]) def clean_overview(overview_raw: str) -> str: