[30] add file to overlay_path

This commit is contained in:
meisnate12 2022-04-22 22:48:26 -04:00
parent 8d1725d397
commit e962d56e4e
9 changed files with 44 additions and 36 deletions

View file

@ -18,7 +18,7 @@ jobs:
webhook_id: ${{ secrets.DEVELOP_WEBHOOK_ID }}
webhook_token: ${{ secrets.DEVELOP_WEBHOOK_TOKEN }}
title: Plex Meta Manager Develop Commits
message: "@Develop Notifications"
message: "<@&954835263731949623>"
commits: "true"
username: Metabot
avatar_url: https://raw.githubusercontent.com/meisnate12/Plex-Meta-Manager/develop/.github/pmm.png

View file

@ -18,7 +18,7 @@ jobs:
webhook_id: ${{ secrets.NIGHTLY_WEBHOOK_ID }}
webhook_token: ${{ secrets.NIGHTLY_WEBHOOK_TOKEN }}
title: Nightly Commits
message: "@Nightly Notifications"
message: "<@&967002147520675840>"
commits: "true"
username: Metabot
avatar_url: https://raw.githubusercontent.com/meisnate12/Plex-Meta-Manager/nightly/.github/pmm.png

View file

@ -18,6 +18,6 @@ jobs:
webhook_token: ${{ secrets.RELEASE_WEBHOOK_TOKEN }}
release: true
title: Plex Meta Manager Release VERSION
message: "@Master Notifications"
message: "<@&967002324646113290>"
username: Metabot
avatar_url: https://raw.githubusercontent.com/meisnate12/Plex-Meta-Manager/master/.github/pmm.png

View file

@ -1 +1 @@
1.16.5-develop29
1.16.5-develop30

View file

@ -1628,15 +1628,17 @@ For example, when using `type: tmdb_collection` and you want to define a poster
```yaml
templates:
optional:
- my_collection_poster
tmdb_collection_details: <<value>>
collection_order: release
url_poster: <<my_collection_poster>>
my_template:
optional:
- my_collection_poster
tmdb_collection_details: <<value>>
collection_order: release
url_poster: <<my_collection_poster>>
dynamic_collections:
TMDb Collections: # This name is the mapping name
type: tmdb_collection
remove_suffix: "Collection"
template: my_template
template_variables:
my_collection_poster:
119: https://www.themoviedb.org/t/p/original/oENY593nKRVL2PnxXsMtlh8izb4.jpg

View file

@ -59,7 +59,8 @@ You can specify the Overlay Name in 3 ways.
| Attribute | Description | Required |
|:----------|:--------------------------------------------------------------------------------------------------------------|:--------:|
| `name` | Name of the overlay. Each overlay name should be unique. | &#9989; |
| `url` | URL of Overlay Image Onlin. | &#10060; |
| `file` | Local location of the Overlay Image. | &#10060; |
| `url` | URL of Overlay Image Online. | &#10060; |
| `git` | Location in the [Configs Repo](https://github.com/meisnate12/Plex-Meta-Manager-Configs) of the Overlay Image. | &#10060; |
| `repo` | Location in the [Custom Repo](../config/settings.md#custom-repo) of the Overlay Image. | &#10060; |
| `group` | Name of the Grouping for this overlay. **`weight` is required when using `group`** | &#10060; |

View file

@ -271,6 +271,7 @@ class CollectionBuilder:
self.suppress_overlays = []
self.overlay_group = None
self.overlay_weight = None
self.overlay_path = None
if self.overlay:
if "overlay" in methods:
logger.debug("")
@ -289,31 +290,33 @@ class CollectionBuilder:
self.overlay_weight = pri
else:
raise Failed(f"{self.Type} Error: overlay group and overlay weight must be used together")
if "git" in data[methods["overlay"]] and data[methods["overlay"]]["git"]:
url = f"{util.github_base}{data[methods['overlay']]['git']}.png"
elif "repo" in data[methods["overlay"]] and data[methods["overlay"]]["repo"]:
url = f"{self.config.custom_repo}{data[methods['overlay']]['git']}.png"
elif "url" in data[methods["overlay"]] and data[methods["overlay"]]["url"]:
url = data[methods["overlay"]]["url"]
else:
url = None
if url:
response = self.config.get(url)
def get_and_save_image(image_url):
response = self.config.get(image_url)
if response.status_code >= 400:
raise Failed(f"{self.Type} Error: Overlay Image not found at: {url}")
raise Failed(f"{self.Type} Error: Overlay Image not found at: {image_url}")
if "Content-Type" not in response.headers or response.headers["Content-Type"] != "image/png":
raise Failed(f"{self.Type} Error: Overlay Image not a png: {url}")
if not os.path.exists(library.overlay_folder) or not os.path.isdir(library.overlay_folder):
os.makedirs(library.overlay_folder, exist_ok=False)
logger.info(f"Creating Overlay Folder found at: {library.overlay_folder}")
clean_name, _ = util.validate_filename(self.overlay)
overlay_path = os.path.join(library.overlay_folder, f"{clean_name}.png")
if os.path.exists(overlay_path):
os.remove(overlay_path)
with open(overlay_path, "wb") as handler:
clean_image_name, _ = util.validate_filename(self.overlay)
image_path = os.path.join(library.overlay_folder, f"{clean_image_name}.png")
if os.path.exists(image_path):
os.remove(image_path)
with open(image_path, "wb") as handler:
handler.write(response.content)
while util.is_locked(overlay_path):
while util.is_locked(image_path):
time.sleep(1)
return image_path
if "file" in data[methods["overlay"]] and data[methods["overlay"]]["file"]:
self.overlay_path = data[methods["overlay"]]["file"]
elif "git" in data[methods["overlay"]] and data[methods["overlay"]]["git"]:
self.overlay_path = get_and_save_image(f"{util.github_base}{data[methods['overlay']]['git']}.png")
elif "repo" in data[methods["overlay"]] and data[methods["overlay"]]["repo"]:
self.overlay_path = get_and_save_image(f"{self.config.custom_repo}{data[methods['overlay']]['repo']}.png")
elif "url" in data[methods["overlay"]] and data[methods["overlay"]]["url"]:
self.overlay_path = get_and_save_image(data[methods["overlay"]]["url"])
else:
self.overlay = str(data[methods["overlay"]])
else:
@ -328,10 +331,12 @@ class CollectionBuilder:
except ValueError:
logger.error(f"Overlay Error: failed to parse overlay blur name: {self.overlay} defaulting to blur(50)")
self.overlay = "blur(50)"
overlay_path = os.path.join(library.overlay_folder, f"{self.overlay}.png")
if not self.overlay.startswith("blur") and not os.path.exists(overlay_path):
raise Failed(f"{self.Type} Error: Overlay Image not found at: {overlay_path}")
else:
if not self.overlay_path:
clean_name, _ = util.validate_filename(self.overlay)
self.overlay_path = os.path.join(library.overlay_folder, f"{clean_name}.png")
if not os.path.exists(self.overlay_path):
raise Failed(f"{self.Type} Error: Overlay Image not found at: {self.overlay_path}")
if "suppress_overlays" in methods:
logger.debug("")

View file

@ -92,6 +92,8 @@ class DataFile:
else:
raise Failed(f"File Error: File does not exist {os.path.abspath(file_path)}")
data, _, _ = yaml.util.load_yaml_guess_indent(content)
if not data or not isinstance(data, dict):
raise Failed("YAML Error: File is empty")
return data
except yaml.scanner.ScannerError as ye:
raise Failed(f"YAML Error: {util.tab_new_lines(ye)}")

View file

@ -38,7 +38,7 @@ class Overlays:
if builder.overlay not in settings:
settings[builder.overlay] = {
"keys": [], "suppress": builder.suppress_overlays, "group": builder.overlay_group,
"weight": builder.overlay_weight, "updated": False, "image": None
"weight": builder.overlay_weight, "path": builder.overlay_path, "updated": False, "image": None
}
for method, value in builder.builders:
@ -78,14 +78,12 @@ class Overlays:
if suppress_name in settings and rk in settings[suppress_name]["keys"]:
settings[suppress_name]["keys"].remove(rk)
if not overlay_name.startswith("blur"):
clean_name, _ = util.validate_filename(overlay_name)
image_compare = None
if self.config.Cache:
_, image_compare, _ = self.config.Cache.query_image_map(overlay_name, f"{self.library.image_table_name}_overlays")
overlay_file = os.path.join(self.library.overlay_folder, f"{clean_name}.png")
overlay_size = os.stat(overlay_file).st_size
overlay_size = os.stat(settings[overlay_name]["path"]).st_size
settings[overlay_name]["updated"] = not image_compare or str(overlay_size) != str(image_compare)
settings[overlay_name]["image"] = Image.open(overlay_file).convert("RGBA")
settings[overlay_name]["image"] = Image.open(settings[overlay_name]["path"]).convert("RGBA")
if self.config.Cache:
self.config.Cache.update_image_map(overlay_name, f"{self.library.image_table_name}_overlays", overlay_name, overlay_size)