Skip to content

Commit

Permalink
Merge pull request #322 from meisnate12/develop
Browse files Browse the repository at this point in the history
v1.11.1
  • Loading branch information
meisnate12 authored Jul 6, 2021
2 parents f9cd722 + 4ca862a commit b740b85
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ assignees: 'meisnate12'

---

<!---
Please make sure you submit all Pull Requests to the develop branch not the master branch.
--->

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Expand Down
8 changes: 6 additions & 2 deletions modules/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime, timedelta
from modules import anidb, anilist, icheckmovies, imdb, letterboxd, mal, plex, radarr, sonarr, tautulli, tmdb, trakttv, tvdb, util
from modules.util import Failed, ImageData
from PIL import Image
from PIL import Image, UnidentifiedImageError
from plexapi.exceptions import BadRequest, NotFound
from plexapi.video import Movie, Show
from urllib.parse import quote
Expand Down Expand Up @@ -1664,6 +1664,7 @@ def sync_collection(self):
logger.info("")
util.separator(f"Removed from {self.name} Collection", space=False, border=False)
logger.info("")
self.library.reload(item)
logger.info(f"{self.name} Collection | - | {item.title}")
if self.smart_label_collection:
self.library.query_data(item.removeLabel, self.name)
Expand Down Expand Up @@ -1707,7 +1708,10 @@ def update_item_details(self):
if int(item.ratingKey) in rating_keys:
rating_keys.remove(int(item.ratingKey))
if self.details["item_assets"] or overlay is not None:
self.library.update_item_from_assets(item, overlay=overlay)
try:
self.library.update_item_from_assets(item, overlay=overlay)
except Failed as e:
logger.error(e)
self.library.edit_tags("label", item, add_tags=add_tags, remove_tags=remove_tags, sync_tags=sync_tags)
if "item_radarr_tag" in self.item_details and item.ratingKey in self.library.movie_rating_key_map:
tmdb_ids.append(self.library.movie_rating_key_map[item.ratingKey])
Expand Down
15 changes: 12 additions & 3 deletions modules/plex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import glob, logging, os, plexapi, requests, shutil
import glob, logging, os, plexapi, requests, shutil, time
from modules import builder, util
from modules.meta import Metadata
from modules.util import Failed, ImageData
Expand Down Expand Up @@ -459,10 +459,15 @@ def upload_images(self, item, poster=None, background=None, overlay=None):
if self.config.Cache:
image, _, image_overlay = self.config.Cache.query_image_map(item.ratingKey, self.original_mapping_name, "poster")
if poster_uploaded or not image_overlay or image_overlay != overlay_name:
og_image = requests.get(item.posterUrl).content
response = requests.get(item.posterUrl)
if response.status_code >= 400:
raise Failed(f"Overlay Error: Overlay Failed for {item.title}")
og_image = response.content
with open(temp_image, "wb") as handler:
handler.write(og_image)
shutil.copyfile(temp_image, os.path.join(overlay_folder, f"{item.ratingKey}.png"))
while util.is_locked(temp_image):
time.sleep(1)
new_poster = Image.open(temp_image)
new_poster = new_poster.resize(overlay_image.size, Image.ANTIALIAS)
new_poster.paste(overlay_image, (0, 0), overlay_image)
Expand Down Expand Up @@ -498,6 +503,8 @@ def upload_images(self, item, poster=None, background=None, overlay=None):
@retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed)
def get_search_choices(self, search_name, title=True):
final_search = search_translation[search_name] if search_name in search_translation else search_name
if final_search == "resolution" and self.is_show:
final_search = "episode.resolution"
try:
choices = {}
for choice in self.Plex.listFilterChoices(final_search):
Expand Down Expand Up @@ -814,7 +821,9 @@ def update_item_from_assets(self, item, overlay=None):
if len(matches) > 0:
episode_poster = ImageData("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title} {episode.seasonEpisode.upper()}'s ", is_url=False)
self.upload_images(episode, poster=episode_poster)
if not found_one:
if not found_one and overlay:
self.upload_images(item, overlay=overlay)
elif not found_one:
logger.error(f"Asset Warning: No asset folder found called '{name}'")

def find_collection_assets(self, item, name=None):
Expand Down
2 changes: 1 addition & 1 deletion modules/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def edit_tags(self, tmdb_ids, tags, apply_tags):
logger.info("")
logger.info(f"{apply_tags_translation[apply_tags].capitalize()} Radarr Tags: {tags}")

edited, not_exists = self.api.edit_multiple_movies(tmdb_ids, tags=tags, apply_tags=apply_tags)
edited, not_exists = self.api.edit_multiple_movies(tmdb_ids, tags=tags, apply_tags=apply_tags_translation[apply_tags])

if len(edited) > 0:
logger.info("")
Expand Down
4 changes: 2 additions & 2 deletions modules/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ def edit_tags(self, tvdb_ids, tags, apply_tags):
logger.info("")
logger.info(f"{apply_tags_translation[apply_tags].capitalize()} Sonarr Tags: {tags}")

edited, not_exists = self.api.edit_multiple_series(tvdb_ids, tags=tags, apply_tags=apply_tags)
edited, not_exists = self.api.edit_multiple_series(tvdb_ids, tags=tags, apply_tags=apply_tags_translation[apply_tags])

if len(edited) > 0:
logger.info("")
for series in edited:
logger.info(f"Radarr Tags | {series.title:<25} | {series.tags}")
logger.info(f"Sonarr Tags | {series.title:<25} | {series.tags}")
logger.info(f"{len(edited)} Series edited in Sonarr")

if len(not_exists) > 0:
Expand Down
15 changes: 15 additions & 0 deletions modules/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,18 @@ def validate_filename(filename):
else:
mapping_name = sanitize_filename(filename)
return mapping_name, f"Log Folder Name: {filename} is invalid using {mapping_name}"

def is_locked(filepath):
locked = None
file_object = None
if os.path.exists(filepath):
try:
file_object = open(filepath, 'a', 8)
if file_object:
locked = False
except IOError as message:
locked = True
finally:
if file_object:
file_object.close()
return locked

0 comments on commit b740b85

Please sign in to comment.