Created
January 10, 2025 07:33
-
-
Save thoughtsunificator/118daefe862053acaf88be904309a7e4 to your computer and use it in GitHub Desktop.
Plex unspoil sports videos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
server: | |
build: . | |
container_name: PlexAutoHideSpoiler | |
environment: | |
- PLEX_URL=https://plexabc | |
- PLEX_TOKEN=ABC | |
- LIBRARY_NAME=Sports | |
- IMAGE_PATH=/app/image.png | |
restart: unless-stopped | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 3.21.1 | |
FROM alpine@sha256:b97e2a89d0b9e4011bb88c02ddf01c544b8c781acf1f4d559e7c8f12f1047ac3 | |
RUN apk add --update \ | |
python3=3.12.8-r1 \ | |
py3-pip=24.3.1-r0 \ | |
&& rm -rf /var/cache/apk/* | |
RUN pip install --break-system-packages plexapi==4.16.1 websocket-client==1.8.0 | |
WORKDIR /app | |
COPY ./ ./ | |
CMD ["python3", "/app/script.py"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
from plexapi.server import PlexServer | |
from plexapi.alert import AlertListener | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
PLEX_URL = '' | |
PLEX_TOKEN = '' | |
IMAGE_PATH = '' | |
LIBRARY_NAME = '' | |
# Environmental Variables | |
PLEX_URL = os.getenv('PLEX_URL', PLEX_URL) | |
PLEX_TOKEN = os.getenv('PLEX_TOKEN', PLEX_TOKEN) | |
IMAGE_PATH = os.getenv('IMAGE_PATH', IMAGE_PATH) | |
LIBRARY_NAME = os.getenv('LIBRARY_NAME', LIBRARY_NAME) | |
unspoiled = [] | |
def on_activity(data): | |
global unspoiled | |
if data["type"] == "timeline" and data["TimelineEntry"][0]["sectionID"] == str(library.key) and data["TimelineEntry"][0]["metadataState"] == "loading": | |
item_id = data["TimelineEntry"][0]["itemID"] | |
if item_id in unspoiled: | |
return | |
unspoiled.append(item_id) | |
item = plex.fetchItem(int(data["TimelineEntry"][0]["itemID"])) | |
logging.debug("Unspoiling poster for item %s", item) | |
item.uploadPoster(filepath=IMAGE_PATH) | |
item.uploadArt(filepath=IMAGE_PATH) | |
item.refresh() | |
def on_error(data): | |
logging.error(data) | |
if __name__ == "__main__": | |
plex = PlexServer(PLEX_URL, PLEX_TOKEN) | |
library = plex.library.section(LIBRARY_NAME) | |
AlertListener(plex, on_activity, on_error).run() |
Scripts wait for new (sports) video to be added to plex and replaces their thumbnails. Now you can watch soccer without knowing the score in advance.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on Plex Version 1.105.2.269-12a32491