From 2cebd2d73dd5fda390eafc1723046db8d9219b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 00:12:41 +0200 Subject: [PATCH 01/25] Pin dependency versions to enable reproducible builds --- requirements.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index b5d8e22..de75d94 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -plexapi -requests -python-dotenv -aiohttp +PlexAPI==4.13.4 +requests==2.28.2 +python-dotenv==1.0.0 +aiohttp==3.8.4 From f7e3f8ae2a9bd1896f53e50a0008e3755a76da85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 01:09:18 +0200 Subject: [PATCH 02/25] Update Dockerfile to use the alpine Python 3 base image --- .dockerignore | 16 +++++++++++++++- Dockerfile | 9 ++------- Dockerfile.old | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 Dockerfile.old diff --git a/.dockerignore b/.dockerignore index 2eea525..f2ea55a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,15 @@ -.env \ No newline at end of file +.dockerignore +.env +.env.sample +.git +.github +.gitignore +.idea +.vscode + +Dockerfile* +README.md + +test + +venv \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c59692d..f539642 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3-slim +FROM python:alpine ENV DRYRUN 'True' ENV DEBUG 'True' @@ -32,13 +32,8 @@ ENV WHITELIST_USERS '' WORKDIR /app -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - build-essential && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - COPY ./requirements.txt ./ + RUN pip install --no-cache-dir -r requirements.txt COPY . . diff --git a/Dockerfile.old b/Dockerfile.old new file mode 100644 index 0000000..f667fe7 --- /dev/null +++ b/Dockerfile.old @@ -0,0 +1,40 @@ +FROM python:3-slim + +ENV DRYRUN 'True' +ENV DEBUG 'True' +ENV DEBUG_LEVEL 'INFO' +ENV SLEEP_DURATION '3600' +ENV LOGFILE 'log.log' + +ENV USER_MAPPING '' +ENV LIBRARY_MAPPING '' + +ENV PLEX_BASEURL '' +ENV PLEX_TOKEN '' +ENV PLEX_USERNAME '' +ENV PLEX_PASSWORD '' +ENV PLEX_SERVERNAME '' + +ENV JELLYFIN_BASEURL '' +ENV JELLYFIN_TOKEN '' + +ENV SYNC_FROM_PLEX_TO_JELLYFIN 'True' +ENV SYNC_FROM_JELLYFIN_TO_PLEX 'True' +ENV SYNC_FROM_PLEX_TO_PLEX 'True' +ENV SYNC_FROM_JELLYFIN_TO_JELLYFIN 'True' + +ENV BLACKLIST_LIBRARY '' +ENV WHITELIST_LIBRARY '' +ENV BLACKLIST_LIBRARY_TYPE '' +ENV WHITELIST_LIBRARY_TYPE '' +ENV BLACKLIST_USERS '' +ENV WHITELIST_USERS '' + +WORKDIR /app + +COPY ./requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["python", "-u", "main.py"] From 99d217e8f10f58e4e8966ec742726acab1aeafa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 01:22:57 +0200 Subject: [PATCH 03/25] Update ci.yml to perform a multi-variant build --- .github/workflows/ci.yml | 23 +++++++++++++++-------- Dockerfile.old => Dockerfile.slim | 0 2 files changed, 15 insertions(+), 8 deletions(-) rename Dockerfile.old => Dockerfile.slim (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c60c3fd..2825ce4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,13 @@ jobs: docker: runs-on: ubuntu-latest needs: pytest + strategy: + matrix: + include: + - dockerfile: Dockerfile + variant: alpine + - dockerfile: Dockerfile.slim + variant: slim steps: - name: Checkout uses: actions/checkout@v3 @@ -37,12 +44,12 @@ jobs: with: images: ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched # list of Docker images to use as base name for tags tags: | - type=raw,value=latest,enable={{is_default_branch}} - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=sha + type=raw,value=${{ matrix.variant }},enable={{is_default_branch}} + type=ref,event=branch,suffix=${{ matrix.variant }} + type=ref,event=pr,suffix=${{ matrix.variant }} + type=semver,pattern={{version}},suffix=${{ matrix.variant }} + type=semver,pattern={{major}}.{{minor}},suffix=${{ matrix.variant }} + type=sha,suffix=${{ matrix.variant }} - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -63,7 +70,7 @@ jobs: uses: docker/build-push-action@v3 with: context: . - file: ./Dockerfile + file: ${{ matrix.dockerfile }} platforms: linux/amd64,linux/arm64 push: false tags: jellyplex-watched:action @@ -74,7 +81,7 @@ jobs: uses: docker/build-push-action@v3 with: context: . - file: ./Dockerfile + file: ${{ matrix.dockerfile }} platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.docker_meta.outputs.tags }} diff --git a/Dockerfile.old b/Dockerfile.slim similarity index 100% rename from Dockerfile.old rename to Dockerfile.slim From eb5534c61c8b50edfae2ae9e6dcf1a75b16a9e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 01:31:20 +0200 Subject: [PATCH 04/25] Add ghcr.io registry --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2825ce4..0b759a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,14 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} + - name: Login to GitHub Container Registry + if: "${{ steps.docker_meta.outcome == 'success' }}" + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build id: build if: "${{ steps.docker_meta.outcome == 'skipped' }}" From 120d89e8be6125bfca958f282c2568dfecf37524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 01:34:10 +0200 Subject: [PATCH 05/25] Add dashes to tags --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b759a9..28648e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,11 +45,11 @@ jobs: images: ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched # list of Docker images to use as base name for tags tags: | type=raw,value=${{ matrix.variant }},enable={{is_default_branch}} - type=ref,event=branch,suffix=${{ matrix.variant }} - type=ref,event=pr,suffix=${{ matrix.variant }} - type=semver,pattern={{version}},suffix=${{ matrix.variant }} - type=semver,pattern={{major}}.{{minor}},suffix=${{ matrix.variant }} - type=sha,suffix=${{ matrix.variant }} + type=ref,event=branch,suffix=-${{ matrix.variant }} + type=ref,event=pr,suffix=-${{ matrix.variant }} + type=semver,pattern={{version}},suffix=-${{ matrix.variant }} + type=semver,pattern={{major}}.{{minor}},suffix=-${{ matrix.variant }} + type=sha,suffix=-${{ matrix.variant }} - name: Set up QEMU uses: docker/setup-qemu-action@v2 From 94d63a3fdba18016c1083bb0fa3a96e02baca3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 01:37:03 +0200 Subject: [PATCH 06/25] Add ghcr.io image name to the docker metadata action step --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28648e9..5f79e12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,9 @@ jobs: if: "${{ env.DOCKER_USERNAME != '' }}" uses: docker/metadata-action@v4 with: - images: ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched # list of Docker images to use as base name for tags + images: | + ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched + ghcr.io/${{ secrets.DOCKER_USERNAME }}/jellyplex-watched tags: | type=raw,value=${{ matrix.variant }},enable={{is_default_branch}} type=ref,event=branch,suffix=-${{ matrix.variant }} From 73d18dad9228d549c88fe5e516a400401244631e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 01:49:25 +0200 Subject: [PATCH 07/25] Rename Dockerfile to Dockerfile.alpine --- .github/workflows/ci.yml | 2 +- Dockerfile => Dockerfile.alpine | 82 ++++++++++++++++----------------- 2 files changed, 42 insertions(+), 42 deletions(-) rename Dockerfile => Dockerfile.alpine (94%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f79e12..90d5cc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: strategy: matrix: include: - - dockerfile: Dockerfile + - dockerfile: Dockerfile.alpine variant: alpine - dockerfile: Dockerfile.slim variant: slim diff --git a/Dockerfile b/Dockerfile.alpine similarity index 94% rename from Dockerfile rename to Dockerfile.alpine index f539642..964a3ae 100644 --- a/Dockerfile +++ b/Dockerfile.alpine @@ -1,41 +1,41 @@ -FROM python:alpine - -ENV DRYRUN 'True' -ENV DEBUG 'True' -ENV DEBUG_LEVEL 'INFO' -ENV SLEEP_DURATION '3600' -ENV LOGFILE 'log.log' - -ENV USER_MAPPING '' -ENV LIBRARY_MAPPING '' - -ENV PLEX_BASEURL '' -ENV PLEX_TOKEN '' -ENV PLEX_USERNAME '' -ENV PLEX_PASSWORD '' -ENV PLEX_SERVERNAME '' - -ENV JELLYFIN_BASEURL '' -ENV JELLYFIN_TOKEN '' - -ENV SYNC_FROM_PLEX_TO_JELLYFIN 'True' -ENV SYNC_FROM_JELLYFIN_TO_PLEX 'True' -ENV SYNC_FROM_PLEX_TO_PLEX 'True' -ENV SYNC_FROM_JELLYFIN_TO_JELLYFIN 'True' - -ENV BLACKLIST_LIBRARY '' -ENV WHITELIST_LIBRARY '' -ENV BLACKLIST_LIBRARY_TYPE '' -ENV WHITELIST_LIBRARY_TYPE '' -ENV BLACKLIST_USERS '' -ENV WHITELIST_USERS '' - -WORKDIR /app - -COPY ./requirements.txt ./ - -RUN pip install --no-cache-dir -r requirements.txt - -COPY . . - -CMD ["python", "-u", "main.py"] +FROM python:alpine + +ENV DRYRUN 'True' +ENV DEBUG 'True' +ENV DEBUG_LEVEL 'INFO' +ENV SLEEP_DURATION '3600' +ENV LOGFILE 'log.log' + +ENV USER_MAPPING '' +ENV LIBRARY_MAPPING '' + +ENV PLEX_BASEURL '' +ENV PLEX_TOKEN '' +ENV PLEX_USERNAME '' +ENV PLEX_PASSWORD '' +ENV PLEX_SERVERNAME '' + +ENV JELLYFIN_BASEURL '' +ENV JELLYFIN_TOKEN '' + +ENV SYNC_FROM_PLEX_TO_JELLYFIN 'True' +ENV SYNC_FROM_JELLYFIN_TO_PLEX 'True' +ENV SYNC_FROM_PLEX_TO_PLEX 'True' +ENV SYNC_FROM_JELLYFIN_TO_JELLYFIN 'True' + +ENV BLACKLIST_LIBRARY '' +ENV WHITELIST_LIBRARY '' +ENV BLACKLIST_LIBRARY_TYPE '' +ENV WHITELIST_LIBRARY_TYPE '' +ENV BLACKLIST_USERS '' +ENV WHITELIST_USERS '' + +WORKDIR /app + +COPY ./requirements.txt ./ + +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["python", "-u", "main.py"] From 397dd17429476f292f969f9d3431407f36f7727e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 01:55:03 +0200 Subject: [PATCH 08/25] Specify Python version --- Dockerfile.alpine | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 964a3ae..5b1a049 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,4 +1,4 @@ -FROM python:alpine +FROM python:3-alpine ENV DRYRUN 'True' ENV DEBUG 'True' From 73c1ebf3ed8f34d2fe026f6de841fb83be24a198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 01:59:10 +0200 Subject: [PATCH 09/25] Pin pytest version --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 4f76727..7556140 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1 +1 @@ -pytest +pytest==7.3.0 From bee854f059daea91127ce4cfa9219ce3da008d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 10:40:30 +0200 Subject: [PATCH 10/25] Exclude DockerHub in case there is no username set --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90d5cc9..686a92c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,12 +39,11 @@ jobs: id: docker_meta env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - if: "${{ env.DOCKER_USERNAME != '' }}" uses: docker/metadata-action@v4 with: images: | - ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched - ghcr.io/${{ secrets.DOCKER_USERNAME }}/jellyplex-watched + ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched,enable=${{ secrets.DOCKER_USERNAME != '' }} + ghcr.io/${{ github.repository_owner }}/jellyplex-watched tags: | type=raw,value=${{ matrix.variant }},enable={{is_default_branch}} type=ref,event=branch,suffix=-${{ matrix.variant }} From 26199100dc037e6bfc0fdf063493868e5f9d3a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 11:02:23 +0200 Subject: [PATCH 11/25] Update tags --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 686a92c..e541310 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,11 +45,12 @@ jobs: ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched,enable=${{ secrets.DOCKER_USERNAME != '' }} ghcr.io/${{ github.repository_owner }}/jellyplex-watched tags: | - type=raw,value=${{ matrix.variant }},enable={{is_default_branch}} + type=raw,value=latest,enable=${{ matrix.variant == 'alpine' }} + type=raw,value=latest,suffix=-${{ matrix.variant }},enable={{ is_default_branch }} type=ref,event=branch,suffix=-${{ matrix.variant }} type=ref,event=pr,suffix=-${{ matrix.variant }} - type=semver,pattern={{version}},suffix=-${{ matrix.variant }} - type=semver,pattern={{major}}.{{minor}},suffix=-${{ matrix.variant }} + type=semver,pattern={{ version }},suffix=-${{ matrix.variant }} + type=semver,pattern={{ major }}.{{ minor }},suffix=-${{ matrix.variant }} type=sha,suffix=-${{ matrix.variant }} - name: Set up QEMU From faa378c75eb7b755428693944b449f04deb50a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 11:20:19 +0200 Subject: [PATCH 12/25] Add is_default_branch conditional to latest tag --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e541310..5555740 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched,enable=${{ secrets.DOCKER_USERNAME != '' }} ghcr.io/${{ github.repository_owner }}/jellyplex-watched tags: | - type=raw,value=latest,enable=${{ matrix.variant == 'alpine' }} + type=raw,value=latest,enable=${{ matrix.variant == 'alpine' && is_default_branch }} type=raw,value=latest,suffix=-${{ matrix.variant }},enable={{ is_default_branch }} type=ref,event=branch,suffix=-${{ matrix.variant }} type=ref,event=pr,suffix=-${{ matrix.variant }} From 9921b2a355f41687864ad0410012a7c801bc7da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 11:21:28 +0200 Subject: [PATCH 13/25] Change is_default_branch to other default branch check --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5555740..3e8d7e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched,enable=${{ secrets.DOCKER_USERNAME != '' }} ghcr.io/${{ github.repository_owner }}/jellyplex-watched tags: | - type=raw,value=latest,enable=${{ matrix.variant == 'alpine' && is_default_branch }} + type=raw,value=latest,enable=${{ matrix.variant == 'alpine' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} type=raw,value=latest,suffix=-${{ matrix.variant }},enable={{ is_default_branch }} type=ref,event=branch,suffix=-${{ matrix.variant }} type=ref,event=pr,suffix=-${{ matrix.variant }} From 24d5de813d0d7cb12045f810fa96ddb856bcbefc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 11:23:32 +0200 Subject: [PATCH 14/25] Remove DOCKER_USERNAME environment variable from docker_meta step --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e8d7e2..a3fcfd8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,8 +37,6 @@ jobs: - name: Docker meta id: docker_meta - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} uses: docker/metadata-action@v4 with: images: | From e51cf6e4828e502370fae96c2abb2d7c2a037075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 12:54:28 +0200 Subject: [PATCH 15/25] Refactor black/whitelist processing --- src/black_white.py | 141 +++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 75 deletions(-) diff --git a/src/black_white.py b/src/black_white.py index 6b142c0..e32ee08 100644 --- a/src/black_white.py +++ b/src/black_white.py @@ -11,18 +11,20 @@ def setup_black_white_lists( library_mapping=None, user_mapping=None, ): - blacklist_library, blacklist_library_type, blacklist_users = setup_black_lists( + blacklist_library, blacklist_library_type, blacklist_users = setup_x_lists( blacklist_library, blacklist_library_type, blacklist_users, + "White", library_mapping, user_mapping, ) - whitelist_library, whitelist_library_type, whitelist_users = setup_white_lists( + whitelist_library, whitelist_library_type, whitelist_users = setup_x_lists( whitelist_library, whitelist_library_type, whitelist_users, + "Black", library_mapping, user_mapping, ) @@ -36,104 +38,93 @@ def setup_black_white_lists( whitelist_users, ) - -def setup_black_lists( - blacklist_library, - blacklist_library_type, - blacklist_users, +def setup_x_lists( + xlist_library, + xlist_library_type, + xlist_users, + xlist_type, library_mapping=None, user_mapping=None, ): - if blacklist_library: - if len(blacklist_library) > 0: - blacklist_library = blacklist_library.split(",") - blacklist_library = [x.strip() for x in blacklist_library] + if xlist_library: + if len(xlist_library) > 0: + xlist_library = xlist_library.split(",") + xlist_library = [x.strip() for x in xlist_library] if library_mapping: temp_library = [] - for library in blacklist_library: + for library in xlist_library: library_other = search_mapping(library_mapping, library) if library_other: temp_library.append(library_other) - blacklist_library = blacklist_library + temp_library + xlist_library = xlist_library + temp_library else: - blacklist_library = [] - logger(f"Blacklist Library: {blacklist_library}", 1) + xlist_library = [] + logger(f"{xlist_type}list Library: {xlist_library}", 1) - if blacklist_library_type: - if len(blacklist_library_type) > 0: - blacklist_library_type = blacklist_library_type.split(",") - blacklist_library_type = [x.lower().strip() for x in blacklist_library_type] + if xlist_library_type: + if len(xlist_library_type) > 0: + xlist_library_type = xlist_library_type.split(",") + xlist_library_type = [x.lower().strip() for x in xlist_library_type] else: - blacklist_library_type = [] - logger(f"Blacklist Library Type: {blacklist_library_type}", 1) + xlist_library_type = [] + logger(f"{xlist_type}list Library Type: {xlist_library_type}", 1) - if blacklist_users: - if len(blacklist_users) > 0: - blacklist_users = blacklist_users.split(",") - blacklist_users = [x.lower().strip() for x in blacklist_users] + if xlist_users: + if len(xlist_users) > 0: + xlist_users = xlist_users.split(",") + xlist_users = [x.lower().strip() for x in xlist_users] if user_mapping: temp_users = [] - for user in blacklist_users: + for user in xlist_users: user_other = search_mapping(user_mapping, user) if user_other: temp_users.append(user_other) - blacklist_users = blacklist_users + temp_users + xlist_users = xlist_users + temp_users + else: + xlist_users = [] else: - blacklist_users = [] - logger(f"Blacklist Users: {blacklist_users}", 1) + xlist_users = [] + logger(f"{xlist_type}list Users: {xlist_users}", 1) + + return xlist_library, xlist_library_type, xlist_users + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - return blacklist_library, blacklist_library_type, blacklist_users -def setup_white_lists( - whitelist_library, - whitelist_library_type, - whitelist_users, - library_mapping=None, - user_mapping=None, -): - if whitelist_library: - if len(whitelist_library) > 0: - whitelist_library = whitelist_library.split(",") - whitelist_library = [x.strip() for x in whitelist_library] - if library_mapping: - temp_library = [] - for library in whitelist_library: - library_other = search_mapping(library_mapping, library) - if library_other: - temp_library.append(library_other) - whitelist_library = whitelist_library + temp_library - else: - whitelist_library = [] - logger(f"Whitelist Library: {whitelist_library}", 1) - if whitelist_library_type: - if len(whitelist_library_type) > 0: - whitelist_library_type = whitelist_library_type.split(",") - whitelist_library_type = [x.lower().strip() for x in whitelist_library_type] - else: - whitelist_library_type = [] - logger(f"Whitelist Library Type: {whitelist_library_type}", 1) - if whitelist_users: - if len(whitelist_users) > 0: - whitelist_users = whitelist_users.split(",") - whitelist_users = [x.lower().strip() for x in whitelist_users] - if user_mapping: - temp_users = [] - for user in whitelist_users: - user_other = search_mapping(user_mapping, user) - if user_other: - temp_users.append(user_other) - whitelist_users = whitelist_users + temp_users - else: - whitelist_users = [] - else: - whitelist_users = [] - logger(f"Whitelist Users: {whitelist_users}", 1) - return whitelist_library, whitelist_library_type, whitelist_users From a1ef3b5a8d641c1853384dd854f8697a9d5eb498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bani=C4=87?= Date: Thu, 13 Apr 2023 16:45:05 +0200 Subject: [PATCH 16/25] Add conditional to DockerHub login --- .github/workflows/ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3fcfd8..ea7c721 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: paths-ignore: - .gitignore - "*.md" - + jobs: pytest: runs-on: ubuntu-latest @@ -58,7 +58,9 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to DockerHub - if: "${{ steps.docker_meta.outcome == 'success' }}" + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + if: "${{ env.DOCKER_USERNAME != '' }}" uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} @@ -82,7 +84,7 @@ jobs: platforms: linux/amd64,linux/arm64 push: false tags: jellyplex-watched:action - + - name: Build Push id: build_push if: "${{ steps.docker_meta.outcome == 'success' }}" From 4adf94f24b501b6de58e010ab98ea1c0ec9f93e7 Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Thu, 13 Apr 2023 10:28:01 -0600 Subject: [PATCH 17/25] Update ci.yml Action: Use github.repository and github.actor instead --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea7c721..9f1b82c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: with: images: | ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched,enable=${{ secrets.DOCKER_USERNAME != '' }} - ghcr.io/${{ github.repository_owner }}/jellyplex-watched + ghcr.io/${{ github.repository }} tags: | type=raw,value=latest,enable=${{ matrix.variant == 'alpine' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} type=raw,value=latest,suffix=-${{ matrix.variant }},enable={{ is_default_branch }} @@ -71,7 +71,7 @@ jobs: uses: docker/login-action@v2 with: registry: ghcr.io - username: ${{ github.repository_owner }} + username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build From 1e485b37f8a580b98349d926ebc793e726f23f4b Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Thu, 13 Apr 2023 12:56:52 -0600 Subject: [PATCH 18/25] Do not publish on PR, fix condition check on build --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f1b82c..63fec60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,8 @@ jobs: with: images: | ${{ secrets.DOCKER_USERNAME }}/jellyplex-watched,enable=${{ secrets.DOCKER_USERNAME != '' }} - ghcr.io/${{ github.repository }} + # Do not push to ghcr.io on PRs due to permission issues + ghcr.io/${{ github.repository }},enable=${{ github.event_name != 'pull_request' }} tags: | type=raw,value=latest,enable=${{ matrix.variant == 'alpine' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} type=raw,value=latest,suffix=-${{ matrix.variant }},enable={{ is_default_branch }} @@ -76,7 +77,7 @@ jobs: - name: Build id: build - if: "${{ steps.docker_meta.outcome == 'skipped' }}" + if: "${{ steps.docker_meta.outputs.tags == '' }}" uses: docker/build-push-action@v3 with: context: . @@ -87,7 +88,7 @@ jobs: - name: Build Push id: build_push - if: "${{ steps.docker_meta.outcome == 'success' }}" + if: "${{ steps.docker_meta.outputs.tags != '' }}" uses: docker/build-push-action@v3 with: context: . From 485ec5fe2d4274703f43174b9024d3eb5c2d54ab Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Sat, 29 Apr 2023 20:31:24 -0600 Subject: [PATCH 19/25] Add docker-compose file --- docker-compose.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e3783f1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3' + +services: + jellyplex-watched: + image: luigi311/jellyplex-watched:latest + container_name: jellyplex-watched + restart: always + environment: + - DRYRUN=True + - DEBUG=True + - DEBUG_LEVEL=info + - RUN_ONLY_ONCE=False + - SLEEP_DURATION=3600 + - LOGFILE=/tmp/log.log + - USER_MAPPING= + - LIBRARY_MAPPING={"TV Shows":"Shows"} + - BLACKLIST_LIBRARY= + - WHITELIST_LIBRARY= + - BLACKLIST_LIBRARY_TYPE= + - WHITELIST_LIBRARY_TYPE= + - BLACKLIST_USERS= + - WHITELIST_USERS= + - PLEX_BASEURL= + - PLEX_TOKEN= + - JELLYFIN_BASEURL= + - JELLYFIN_TOKEN= + - SSL_BYPASS=True + - SYNC_FROM_PLEX_TO_JELLYFIN=True + - SYNC_FROM_JELLYFIN_TO_PLEX=True + - SYNC_FROM_PLEX_TO_PLEX=True + - SYNC_FROM_JELLYFIN_TO_JELLYFIN=True From 03d1fd8019512b430a0b09b9e696f968a9f0a336 Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Mon, 15 May 2023 10:44:30 -0600 Subject: [PATCH 20/25] Log both servers users instead of exiting immediately --- src/main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main.py b/src/main.py index f308310..715e5d8 100644 --- a/src/main.py +++ b/src/main.py @@ -40,15 +40,23 @@ def setup_users( # Check if users is none or empty if output_server_1_users is None or len(output_server_1_users) == 0: - raise Exception( - f"No users found for server 1 {server_1[0]}, users found {users}, filtered users {users_filtered}, server 1 users {server_1[1].users}" + logger( + f"No users found for server 1 {server_1[0]}, users: {server_1_users}, overlapping users {users}, filtered users {users_filtered}, server 1 users {server_1[1].users}" ) if output_server_2_users is None or len(output_server_2_users) == 0: - raise Exception( - f"No users found for server 2 {server_2[0]}, users found {users} filtered users {users_filtered}, server 2 users {server_2[1].users}" + logger( + f"No users found for server 2 {server_2[0]}, users: {server_2_users}, overlapping users {users} filtered users {users_filtered}, server 2 users {server_2[1].users}" ) + if ( + output_server_1_users is None + or len(output_server_1_users) == 0 + or output_server_2_users is None + or len(output_server_2_users) == 0 + ): + raise Exception("No users found for one or both servers") + logger(f"Server 1 users: {output_server_1_users}", 1) logger(f"Server 2 users: {output_server_2_users}", 1) From 7de7b42fd2638d6491cad434948d52e61a74189c Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Mon, 15 May 2023 11:10:03 -0600 Subject: [PATCH 21/25] Users: Default to username and fall back to title --- src/users.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/users.py b/src/users.py index 6075be8..fc8962b 100644 --- a/src/users.py +++ b/src/users.py @@ -11,7 +11,12 @@ def generate_user_list(server): server_users = [] if server_type == "plex": - server_users = [x.title.lower() for x in server_connection.users] + for user in server_connection.users: + if user.username: + server_users.append(user.username.lower()) + else: + server_users.append(user.title.lower()) + elif server_type == "jellyfin": server_users = [key.lower() for key in server_connection.users.keys()] From aa177666a5b92e0ee0992d8572e6d944183f46cb Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Mon, 15 May 2023 11:17:28 -0600 Subject: [PATCH 22/25] Plex: Fix username/title selection --- src/plex.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plex.py b/src/plex.py index 889078d..0402016 100644 --- a/src/plex.py +++ b/src/plex.py @@ -126,7 +126,9 @@ def get_user_library_watched_show(show): def get_user_library_watched(user, user_plex, library): try: - user_name = user.title.lower() + user_name = user.username.lower() + if user_name == "": + user_name = user.title.lower() user_watched = {} user_watched[user_name] = {} @@ -509,10 +511,14 @@ def update_watched( user_other = search_mapping(user_mapping, user) for index, value in enumerate(self.users): - if user.lower() == value.title.lower(): + username_title = value.username.lower() + if username_title == "": + username_title = value.title.lower() + + if user.lower() == username_title: user = self.users[index] break - elif user_other and user_other.lower() == value.title.lower(): + elif user_other and user_other.lower() == username_title: user = self.users[index] break From 7eba46b5cbf7abfb1d210f5b3aea0a814b3b5590 Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Mon, 15 May 2023 14:57:46 -0600 Subject: [PATCH 23/25] plex: Fix username/title --- src/users.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/users.py b/src/users.py index fc8962b..e6e2309 100644 --- a/src/users.py +++ b/src/users.py @@ -71,9 +71,13 @@ def generate_server_users(server, users): if server[0] == "plex": server_users = [] for plex_user in server[1].users: + username_title = ( + plex_user.username if plex_user.username != "" else plex_user.title + ) + if ( - plex_user.title.lower() in users.keys() - or plex_user.title.lower() in users.values() + username_title.lower() in users.keys() + or username_title.lower() in users.values() ): server_users.append(plex_user) elif server[0] == "jellyfin": From ffc81dad69d8be791b24f63a9eb2b5d8651930e5 Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Mon, 15 May 2023 15:12:25 -0600 Subject: [PATCH 24/25] CI: Add back in dev based on alpine --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63fec60..826a647 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,8 @@ jobs: # Do not push to ghcr.io on PRs due to permission issues ghcr.io/${{ github.repository }},enable=${{ github.event_name != 'pull_request' }} tags: | - type=raw,value=latest,enable=${{ matrix.variant == 'alpine' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} + type=raw,value=latest,enable=${{ matrix.variant == 'alpine' && github.ref_name == github.event.repository.default_branch }} + type=raw,value=dev,enable=${{ matrix.variant == 'alpine' && github.ref_name == 'dev' }} type=raw,value=latest,suffix=-${{ matrix.variant }},enable={{ is_default_branch }} type=ref,event=branch,suffix=-${{ matrix.variant }} type=ref,event=pr,suffix=-${{ matrix.variant }} From 9f61c7338da7716999d9036d844e55a07dbbb831 Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Wed, 17 May 2023 13:22:00 -0600 Subject: [PATCH 25/25] Plex: Cleanup username_title --- src/plex.py | 12 ++++++------ src/users.py | 9 ++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/plex.py b/src/plex.py index 0402016..0bcdf7b 100644 --- a/src/plex.py +++ b/src/plex.py @@ -126,9 +126,7 @@ def get_user_library_watched_show(show): def get_user_library_watched(user, user_plex, library): try: - user_name = user.username.lower() - if user_name == "": - user_name = user.title.lower() + user_name = user.username.lower() if user.username else user.title.lower() user_watched = {} user_watched[user_name] = {} @@ -511,9 +509,11 @@ def update_watched( user_other = search_mapping(user_mapping, user) for index, value in enumerate(self.users): - username_title = value.username.lower() - if username_title == "": - username_title = value.title.lower() + username_title = ( + value.username.lower() + if value.username + else value.title.lower() + ) if user.lower() == username_title: user = self.users[index] diff --git a/src/users.py b/src/users.py index e6e2309..4f1e280 100644 --- a/src/users.py +++ b/src/users.py @@ -12,10 +12,9 @@ def generate_user_list(server): server_users = [] if server_type == "plex": for user in server_connection.users: - if user.username: - server_users.append(user.username.lower()) - else: - server_users.append(user.title.lower()) + server_users.append( + user.username.lower() if user.username else user.title.lower() + ) elif server_type == "jellyfin": server_users = [key.lower() for key in server_connection.users.keys()] @@ -72,7 +71,7 @@ def generate_server_users(server, users): server_users = [] for plex_user in server[1].users: username_title = ( - plex_user.username if plex_user.username != "" else plex_user.title + plex_user.username if plex_user.username else plex_user.title ) if (