Skip to content

Commit

Permalink
Write EXIF data if PMM integration is enabled
Browse files Browse the repository at this point in the history
Implements #402
  • Loading branch information
CollinHeist committed Oct 5, 2023
1 parent 4eadd05 commit d3cfbdf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
35 changes: 32 additions & 3 deletions modules/PlexInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from sys import exit as sys_exit
from typing import Any, Callable, Optional, Union

from PIL import Image
from plexapi.exceptions import PlexApiException
from plexapi.server import PlexServer, NotFound, Unauthorized
from plexapi.library import Library as PlexLibrary
Expand Down Expand Up @@ -78,6 +79,9 @@ class PlexInterface(EpisodeDataSource, MediaServer, SyncInterface):
"""How many failed episodes result in skipping a series"""
SKIP_SERIES_THRESHOLD = 3

"""EXIF data to write to images if PMM integration is enabled"""
EXIF_TAG = {'key': 0x4242, 'data': 'titlecard'}

"""Episode titles that indicate a placeholder and are to be ignored"""
__TEMP_IGNORE_REGEX = re_compile(r'^(tba|tbd|episode \d+)$', IGNORECASE)

Expand Down Expand Up @@ -127,7 +131,7 @@ def __init__(self,
sys_exit(1)

# Store integration
self.integrate_with_pmm_overlays = integrate_with_pmm_overlays
self.integrate_with_pmm = integrate_with_pmm_overlays

# Create/read loaded card database
self.__posters = PersistentDatabase(self.LOADED_POSTERS_DB)
Expand Down Expand Up @@ -676,6 +680,24 @@ def __retry_upload(self,
plex_object.uploadPoster(filepath=filepath)


def __add_exif_tag(self, card: Path) -> None:
"""
Add an EXIF tag to the given Card file. This adds "titlecard" at
0x4242, and overwrites the existing file.
Args:
card: Path to the Card file to modify.
"""

# Create Image object, read EXIF data
card_image = Image.open(card)
exif = card_image.getexif()

# Add EXIF data, write modified file
exif[self.EXIF_TAG['key']] = self.EXIF_TAG['data']
card_image.save(card.resolve(), exif=exif)


@catch_and_log('Error uploading title cards')
def set_title_cards(self,
library_name: str,
Expand Down Expand Up @@ -733,10 +755,17 @@ def set_title_cards(self,
if (card := self.compress_image(episode.destination)) is None:
continue

# Upload card to Plex, optionally remove Overlay label
# Upload card to Plex
try:
# If integrating with PMM, add EXIF data
if self.integrate_with_pmm:
self.__add_exif_tag(card)

# Upload card
self.__retry_upload(pl_episode, card.resolve())
if self.integrate_with_pmm_overlays:

# If integrating with PMM, remove label
if self.integrate_with_pmm:
pl_episode.removeLabel(['Overlay'])
except Exception as e:
error_count += 1
Expand Down
2 changes: 1 addition & 1 deletion modules/ref/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.14.4-develop13
v1.14.4-develop14

0 comments on commit d3cfbdf

Please sign in to comment.