Skip to content

Commit

Permalink
[1] workflow updates
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Mar 7, 2023
1 parent f78f139 commit fd955f9
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 51 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
username: meisnate12
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Set up QEMU
Expand All @@ -42,13 +42,12 @@ jobs:
"BRANCH_NAME=develop"
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_REPO }}:develop
tags: meisnate12/${{ secrets.DOCKER_REPO }}:develop

- name: Send Discord Commit Notification
uses: meisnate12/discord-notifications@master
with:
webhook_id: ${{ secrets.DEVELOP_WEBHOOK_ID }}
webhook_token: ${{ secrets.DEVELOP_WEBHOOK_TOKEN }}
webhook_id_token: ${{ secrets.DEVELOP_WEBHOOK }}
title: ${{ secrets.NAME }} Develop Commits
message: "${{ secrets.DEVELOP_TAG }} - An update to ${{ secrets.NAME }} has been published and is available to users of the **develop** branch."
commits: "true"
Expand All @@ -59,8 +58,7 @@ jobs:
uses: meisnate12/discord-notifications@master
if: success()
with:
webhook_id: ${{ secrets.BUILD_WEBHOOK_ID }}
webhook_token: ${{ secrets.BUILD_WEBHOOK_TOKEN }}
webhook_id_token: ${{ secrets.BUILD_WEBHOOK }}
title: "develop build: **Success**"
url: https://github.com/meisnate12/${{ secrets.GITHUB }}/actions/runs/${{ github.run_id }}
username: Metabot
Expand All @@ -72,8 +70,7 @@ jobs:
uses: meisnate12/discord-notifications@master
if: failure()
with:
webhook_id: ${{ secrets.BUILD_WEBHOOK_ID }}
webhook_token: ${{ secrets.BUILD_WEBHOOK_TOKEN }}
webhook_id_token: ${{ secrets.BUILD_WEBHOOK }}
message: <@&1079153184007790652>
title: "develop build: **Failure**"
color: 0xe30c43
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
username: meisnate12
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Set up QEMU
Expand All @@ -36,14 +36,13 @@ jobs:
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest
tags: meisnate12/${{ secrets.DOCKER_REPO }}:latest

- name: Discord Success Notification
uses: meisnate12/discord-notifications@master
if: success()
with:
webhook_id: ${{ secrets.BUILD_WEBHOOK_ID }}
webhook_token: ${{ secrets.BUILD_WEBHOOK_TOKEN }}
webhook_id_token: ${{ secrets.BUILD_WEBHOOK }}
title: "latest build: **Success**"
url: https://github.com/meisnate12/${{ secrets.GITHUB }}/actions/runs/${{ github.run_id }}
username: Metabot
Expand All @@ -55,8 +54,7 @@ jobs:
uses: meisnate12/discord-notifications@master
if: failure()
with:
webhook_id: ${{ secrets.BUILD_WEBHOOK_ID }}
webhook_token: ${{ secrets.BUILD_WEBHOOK_TOKEN }}
webhook_id_token: ${{ secrets.BUILD_WEBHOOK }}
message: <@&1079153184007790652>
title: "latest build: **Failure**"
color: 0xe30c43
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ jobs:
- name: Send Discord Release Notification
uses: meisnate12/discord-notifications@master
with:
webhook_id: ${{ secrets.RELEASE_WEBHOOK_ID }}
webhook_token: ${{ secrets.RELEASE_WEBHOOK_TOKEN }}
webhook_id_token: ${{ secrets.RELEASE_WEBHOOK }}
release: true
title: ${{ secrets.NAME }} Release VERSION
message: "${{ secrets.RELEASE_TAG }} - A new version of ${{ secrets.NAME }} has been released and is available to all users"
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
username: meisnate12
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Set up QEMU
Expand All @@ -44,14 +44,13 @@ jobs:
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_REPO }}:${{ steps.get_version.outputs.VERSION }}
tags: meisnate12/${{ secrets.DOCKER_REPO }}:${{ steps.get_version.outputs.VERSION }}

- name: Discord Success Notification
uses: meisnate12/discord-notifications@master
if: success()
with:
webhook_id: ${{ secrets.BUILD_WEBHOOK_ID }}
webhook_token: ${{ secrets.BUILD_WEBHOOK_TOKEN }}
webhook_id_token: ${{ secrets.BUILD_WEBHOOK }}
title: "${{ steps.get_version.outputs.VERSION }} build: **Success**"
url: https://github.com/meisnate12/${{ secrets.GITHUB }}/actions/runs/${{ github.run_id }}
username: Metabot
Expand All @@ -63,8 +62,7 @@ jobs:
uses: meisnate12/discord-notifications@master
if: failure()
with:
webhook_id: ${{ secrets.BUILD_WEBHOOK_ID }}
webhook_token: ${{ secrets.BUILD_WEBHOOK_TOKEN }}
webhook_id_token: ${{ secrets.BUILD_WEBHOOK }}
message: <@&1079153184007790652>
title: "${{ steps.get_version.outputs.VERSION }} build: **Failure**"
color: 0xe30c43
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ There are no detailed walkthroughs specifically for PMM Overlay Reset but the pr

### Local Install Overview

PMM Overlay Reset is compatible with Python 3.11. Later versions may function but are untested.
PMM Overlay Reset requires Python 3.11 or later. Later versions may function but are untested.

These are high-level steps which assume the user has knowledge of python and pip, and the general ability to troubleshoot issues.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.10
0.9.10-develop1
78 changes: 52 additions & 26 deletions pmm_overlay_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
from xml.etree.ElementTree import ParseError
from urllib.parse import quote

if sys.version_info[0] != 3 or sys.version_info[1] < 11:
print("Version Error: Version: %s.%s.%s incompatible please use Python 3.11+" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))
sys.exit(0)

try:
import cv2, numpy, plexapi, requests
from pmmutils import logging, util
Expand All @@ -17,10 +21,6 @@
print("Requirements Error: Requirements are not installed")
sys.exit(0)

if sys.version_info[0] != 3 or sys.version_info[1] < 11:
print("Version Error: Version: %s.%s.%s incompatible please use Python 3.11+" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))
sys.exit(0)

options = [
{"arg": "u", "key": "url", "env": "PLEX_URL", "type": "str", "default": None, "help": "Plex URL of the Server you want to connect to."},
{"arg": "t", "key": "token", "env": "PLEX_TOKEN", "type": "str", "default": None, "help": "Plex Token of the Server you want to connect to."},
Expand Down Expand Up @@ -170,16 +170,21 @@ def detect_overlay_in_image(item_title, poster_source, shape, img_path=None, url
return True
return False

def reset_from_plex(item_title, item_with_posters, shape):
def reset_from_plex(item_title, item_with_posters, shape, ignore=0):
for p, plex_poster in enumerate(item_with_posters.posters(), 1):
logger.trace(plex_poster.key)
if plex_poster.key.startswith("/"):
temp_url = f"{pmmargs['url']}{plex_poster.key}&X-Plex-Token={pmmargs['token']}"
if plex_poster.ratingKey.startswith("upload"):
if not detect_overlay_in_image(item_title, f"Plex Poster {p}", shape, url_path=temp_url):
return temp_url
else:
if ignore < 1:
return temp_url
else:
ignore -= 1
elif ignore < 1:
return plex_poster.key
else:
ignore -= 1

def reset_poster(item_title, plex_item, tmdb_poster_url, asset_directory, asset_file_name, parent=None, shape="portrait"):
poster_source = None
Expand Down Expand Up @@ -231,24 +236,45 @@ def reset_poster(item_title, plex_item, tmdb_poster_url, asset_directory, asset_
else:
logger.info("No Clean Plex Show Image Found")

# Upload poster and Remove "Overlay" Label
if poster_source:
logger.info(f"Reset From {poster_source}")
def upload(attempt=0):
nonlocal poster_path
is_url = poster_source in ["TMDb", "Plex", "Plex's Show"]
if pmmargs["dry"]:
logger.info(f"Poster will be Reset by {'URL' if is_url else 'File'}")
else:
logger.info(f"{'URL' if is_url else 'File'} Path: {poster_path}")
if is_url:
plex_item.uploadPoster(url=poster_path)
try:
if pmmargs["dry"]:
logger.info(f"Poster will be Reset by {'URL' if is_url else 'File'} from {poster_source}")
else:
plex_item.uploadPoster(filepath=poster_path)
if "Overlay" in [la.tag for la in plex_item.labels]:
if not pmmargs["dry"]:
plex_item.removeLabel("Overlay")
logger.info("Overlay Label Removed")
else:
logger.info("Overlay Label will be Removed")
logger.info(f"Reset From {poster_source}")
logger.info(f"{'URL' if is_url else 'File'} Path: {poster_path}")
if is_url:
plex_item.uploadPoster(url=poster_path)
else:
plex_item.uploadPoster(filepath=poster_path)
except BadRequest as eb:
logger.error(eb, group=item_title)
if poster_source in ["Plex", "Plex's Show"]:
attempt += 1
logger.info(f"Trying next poster #{attempt + 1}")
if poster_source == "Plex":
poster_path = reset_from_plex(item_title, plex_item, shape, ignore=attempt)
if not poster_path:
logger.info("No Clean Plex Image Found")
if poster_source == "Plex's Show":
poster_path = reset_from_plex(item_title, parent, shape, ignore=attempt)
if not poster_path:
logger.info("No Clean Plex Show Image Found")
if poster_path:
upload(attempt=attempt)
else:
if "Overlay" in [la.tag for la in plex_item.labels]:
if not pmmargs["dry"]:
plex_item.removeLabel("Overlay")
logger.info("Overlay Label Removed")
else:
logger.info("Overlay Label will be Removed")

# Upload poster and Remove "Overlay" Label
if poster_source:
upload()
else:
logger.error("Image Error: No Image Found to Restore", group=item_title)

Expand Down Expand Up @@ -409,14 +435,14 @@ def reload(plex_item):
elif results.tv_results and isinstance(item, Show):
tmdb_id = results.tv_results[0].id
except TMDbException as e:
logger.error(e, group=title)
logger.warning(e, group=title)
if not tmdb_id and tvdb_id and isinstance(item, Show):
try:
results = tmdbapi.find_by_id(tvdb_id=tvdb_id)
if results.tv_results:
tmdb_id = results.tv_results[0].id
except TMDbException as e:
logger.error(e, group=title)
logger.warning(e, group=title)
if tmdb_id:
try:
tmdb_item = tmdbapi.movie(tmdb_id) if isinstance(item, Movie) else tmdbapi.tv_show(tmdb_id)
Expand Down Expand Up @@ -500,5 +526,5 @@ def reload(plex_item):
logger.switch()
report.append([(f"{script_name} Finished", "")])
report.append([("Total Runtime", f"{logger.runtime()}")])
description = f"{pmmargs['library']} Library {' Dry' if pmmargs['dry'] else ''}Run {run_type}Finished"
description = f"{pmmargs['library']} Library{' Dry' if pmmargs['dry'] else ''} Run {run_type}Finished"
logger.report(f"{script_name} Summary", description=description, rows=report, width=18, discord=True)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ numpy==1.24.2
opencv-python==4.7.0.72
pillow==9.4.0
PlexAPI==4.13.2
pmmutils==0.3.19
pmmutils==0.4.0
requests==2.28.2
tmdbapis==1.1.0

0 comments on commit fd955f9

Please sign in to comment.