diff --git a/README.md b/README.md index 04b7424..2bd415a 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ The main Python application that displays and serves your video collection, buil - Needs a mandatory volume for the video archive at **/youtube** - And another recommended volume to save the cache for thumbnails and artwork at **/cache**. - The environment variables `ES_URL` and `REDIS_HOST` are needed to tell Tube Archivist where Elasticsearch and Redis respectively are located. - - The environment variables `HOST_UID` and `HOST_GID` allows Tube Archivist to `chown` the video files to the main host system user instead of the container user. + - The environment variables `HOST_UID` and `HOST_GID` allows Tube Archivist to `chown` the video files to the main host system user instead of the container user. Those two variables are optional, not setting them will disable that functionality. That might be needed if the underlying filesystem doesn't support `chown` like *NFS*. ### Elasticsearch Stores video meta data and makes everything searchable. Also keeps track of the download queue. diff --git a/tubearchivist/home/src/config.py b/tubearchivist/home/src/config.py index 4c078e4..a01f2d3 100644 --- a/tubearchivist/home/src/config.py +++ b/tubearchivist/home/src/config.py @@ -39,11 +39,23 @@ class AppConfig: @staticmethod def get_config_env(): """read environment application variables""" + host_uid_env = os.environ.get("HOST_UID") + if host_uid_env: + host_uid = int(host_uid_env) + else: + host_uid = False + + host_gid_env = os.environ.get("HOST_GID") + if host_gid_env: + host_gid = int(host_gid_env) + else: + host_gid = False + application = { "REDIS_HOST": os.environ.get("REDIS_HOST"), "es_url": os.environ.get("ES_URL"), - "HOST_UID": int(os.environ.get("HOST_UID")), - "HOST_GID": int(os.environ.get("HOST_GID")), + "HOST_UID": host_uid, + "HOST_GID": host_gid, } return application diff --git a/tubearchivist/home/src/download.py b/tubearchivist/home/src/download.py index bebc938..e8d96e5 100644 --- a/tubearchivist/home/src/download.py +++ b/tubearchivist/home/src/download.py @@ -579,7 +579,8 @@ class VideoDownloader: new_folder = os.path.join(videos, channel_name) if not os.path.exists(new_folder): os.makedirs(new_folder) - os.chown(new_folder, host_uid, host_gid) + if host_uid and host_gid: + os.chown(new_folder, host_uid, host_gid) # find real filename cache_dir = self.config["application"]["cache_dir"] all_cached = ignore_filelist(os.listdir(cache_dir + "/download/")) @@ -590,7 +591,8 @@ class VideoDownloader: new_file_path = os.path.join(videos, vid_dict["media_url"]) # move media file and fix permission shutil.move(old_file_path, new_file_path) - os.chown(new_file_path, host_uid, host_gid) + if host_uid and host_gid: + os.chown(new_file_path, host_uid, host_gid) def delete_from_pending(self, youtube_id): """delete downloaded video from pending index if its there"""