Skip to content

Commit

Permalink
added no-main argument
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Aug 1, 2023
1 parent acc73ad commit 64ce978
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Each option can be applied in three ways:
| Timeout | Timeout can be any number greater then 0. **Default:** `600`<br>**Shell Command:** `-ti` or `--timeout 1000`<br>**Environment Variable:** `TIMEOUT=1000` | &#10060; |
| Dry Run | Run as a Dry Run without making changes in Plex.<br>**Shell Command:** `-d` or `--dry`<br>**Environment Variable:** `DRY_RUN=True` | &#10060; |
| Flat Assets | PMM Asset Folder uses [Flat Assets Image Paths](https://metamanager.wiki/en/latest/home/guides/assets.html#asset-naming).<br>**Shell Command:** `-f` or `--flat`<br>**Environment Variable:** `PMM_FLAT=True` | &#10060; |
| Reset Main Posters | Do not restore Main Show/Movie posters during run.<br>**Shell Command:** `-nm` or `--no-main`<br>**Environment Variable:** `NO_MAIN=True` | &#10060; |
| Reset Season Posters | Restore Season posters during run.<br>**Shell Command:** `-s` or `--season`<br>**Environment Variable:** `SEASON=True` | &#10060; |
| Reset Episode Posters | Restore Episode posters during run.<br>**Shell Command:** `-e` or `--episode`<br>**Environment Variable:** `EPISODE=True` | &#10060; |
| Ignore Automatic Resume | Ignores the automatic resume.<br>**Shell Command:** `-ir` or `--ignore-resume`<br>**Environment Variable:** `IGNORE_RESUME=True` | &#10060; |
Expand All @@ -139,6 +140,7 @@ ITEMS=
TIMEOUT=600
DRY_RUN=True
PMM_FLAT=False
NO_MAIN=False
SEASON=True
EPISODE=True
IGNORE_RESUME=False
Expand Down
19 changes: 10 additions & 9 deletions pmm_overlay_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{"arg": "ti", "key": "timeout", "env": "TIMEOUT", "type": "int", "default": 600, "help": "Timeout can be any number greater then 0. (Default: 600)"},
{"arg": "d", "key": "dry", "env": "DRY_RUN", "type": "bool", "default": False, "help": "Run as a Dry Run without making changes in Plex."},
{"arg": "f", "key": "flat", "env": "PMM_FLAT", "type": "bool", "default": False, "help": "PMM Asset Folder uses Flat Assets Image Paths."},
{"arg": "nm", "key": "no-main", "env": "NO_MAIN", "type": "bool", "default": False, "help": "Do not restore the Main Movie/Show posters during run."},
{"arg": "s", "key": "season", "env": "SEASON", "type": "bool", "default": False, "help": "Restore Season posters during run."},
{"arg": "e", "key": "episode", "env": "EPISODE", "type": "bool", "default": False, "help": "Restore Episode posters during run."},
{"arg": "ir", "key": "ignore-resume", "env": "IGNORE_RESUME", "type": "bool", "default": None, "help": "Ignores the automatic resume."},
Expand Down Expand Up @@ -142,23 +143,22 @@ def detect_overlay_in_image(item_title, poster_source, shape, img_path=None, url
if 0x04bc in exif_tags and exif_tags[0x04bc] == "overlay":
logger.debug(f"Overlay Detected: EXIF Overlay Tag Found ignoring {poster_source}: {out_path}")
return True
if (shape == "portrait" and pil_image.size != (1000, 1500)) or \
(shape == "landscape" and pil_image.size != (1920, 1080)):
if (shape == "portrait" and pil_image.size != (1000, 1500)) or (shape == "landscape" and pil_image.size != (1920, 1080)):
logger.debug("No Overlay: Image not standard overlay size")
return False
except UnidentifiedImageError:
logger.error(f"Image Load Error: {poster_source}: {out_path}", group=item_title)
return None

target = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
target = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE) # noqa
if target is None:
logger.error(f"Image Load Error: {poster_source}: {out_path}", group=item_title)
return None
if target.shape[0] < 500 or target.shape[1] < 500:
logger.info(f"Image Error: {poster_source}: Dimensions {target.shape[0]}x{target.shape[1]} must be greater then 500x500: {out_path}")
return False
for overlay_image in overlay_images:
overlay = cv2.imread(overlay_image, cv2.IMREAD_GRAYSCALE)
overlay = cv2.imread(overlay_image, cv2.IMREAD_GRAYSCALE) # noqa
if overlay is None:
logger.error(f"Image Load Error: {overlay_image}", group=item_title)
continue
Expand All @@ -167,7 +167,7 @@ def detect_overlay_in_image(item_title, poster_source, shape, img_path=None, url
logger.error(f"Image Error: {overlay_image} is larger than {poster_source}: {out_path}", group=item_title)
continue

template_result = cv2.matchTemplate(target, overlay, cv2.TM_CCOEFF_NORMED) # noinspection PyUnresolvedReferences
template_result = cv2.matchTemplate(target, overlay, cv2.TM_CCOEFF_NORMED) # noqa
loc = numpy.where(template_result >= 0.95)

if len(loc[0]) == 0:
Expand Down Expand Up @@ -306,7 +306,7 @@ def reload(plex_item):
includeFields=False, includeGeolocation=False, includeLoudnessRamps=False, includeMarkers=False,
includeOnDeck=False, includePopularLeaves=False, includeRelated=False, includeRelatedCount=0,
includeReviews=False, includeStations=False)
plex_item._initpath = plex_item._details_key
plex_item._autoReload = False
except (BadRequest, NotFound) as e1:
raise Failed(f"Plex Error: {get_title(plex_item)} Failed to Load: {e1}")

Expand Down Expand Up @@ -399,15 +399,15 @@ def reload(plex_item):

tmdb_item = None
if tmdbapi:
guid = requests.utils.urlparse(item.guid)
guid = requests.utils.urlparse(item.guid) # noqa
item_type = guid.scheme.split(".")[-1]
check_id = guid.netloc
tmdb_id = None
tvdb_id = None
imdb_id = None
if item_type == "plex":
for guid_tag in item.guids:
url_parsed = requests.utils.urlparse(guid_tag.id)
url_parsed = requests.utils.urlparse(guid_tag.id) # noqa
if url_parsed.scheme == "tvdb":
tvdb_id = int(url_parsed.netloc)
elif url_parsed.scheme == "imdb":
Expand Down Expand Up @@ -458,7 +458,8 @@ def reload(plex_item):
else:
logger.error("Plex Error: TMDb ID Not Found", group=title)

reset_poster(title, item, tmdb_item.poster_url if tmdb_item else None, item_asset_directory, asset_name if pmmargs["flat"] else "poster")
if not pmmargs["no-main"]:
reset_poster(title, item, tmdb_item.poster_url if tmdb_item else None, item_asset_directory, asset_name if pmmargs["flat"] else "poster")

logger.info(f"Runtime: {logger.runtime('reset')}")

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
numpy==1.24.2
numpy==1.24.3
opencv-python==4.7.0.72
pillow==9.5.0
PlexAPI==4.13.4
pmmutils==0.5.0
requests==2.28.2
tmdbapis==1.1.0
requests==2.31.0
tmdbapis==1.2.0

0 comments on commit 64ce978

Please sign in to comment.