Skip to content

fix: unlinked_proxy KeyError #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added dist/resolve-proxy-encoder-0.1.0.tar.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30 changes: 15 additions & 15 deletions resolve_proxy_encoder/queuer/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import os
import pathlib
import shutil
import sys
from tkinter import E
from typing import Union

from rich import print as pprint
Expand Down Expand Up @@ -119,7 +117,7 @@ def handle_orphaned_proxies(media_list: list) -> list:
orphaned_proxies = []

for media in media_list:
if media["proxy"] != "None" or media["proxy"] == "Offline":
if media["proxy_status"] != "None" or media["proxy_status"] == "Offline":
linked_proxy_path = os.path.splitext(media["proxy_media_path"])
linked_proxy_path[1].lower()

Expand Down Expand Up @@ -196,7 +194,9 @@ def handle_already_linked(
"""

logger.info(f"[cyan]Checking for source media with linked proxies.[/]")
already_linked = [x for x in media_list if str(x["proxy"]) not in unlinked_types]
already_linked = [
x for x in media_list if str(x["proxy_status"]) not in unlinked_types
]

if len(already_linked) > 0:

Expand Down Expand Up @@ -267,15 +267,13 @@ def get_newest_proxy_file(media, expected_proxy_path: str) -> Union[str, None]:
# Iterate media list
for media in media_list:

if media["proxy"] in unlinked_types:
if media["proxy_status"] in unlinked_types:

expected_proxy_dir = media["expected_proxy_dir"]
logger.debug(
f"[magenta]Expected proxy directory:[/] '{expected_proxy_dir}'"
)
proxy_dir = media["proxy_dir"]
logger.debug(f"[magenta]Expected proxy directory:[/] '{proxy_dir}'")

# Get expected proxy path
glob_partial_match = os.path.join(expected_proxy_dir, media["file_name"])
glob_partial_match = os.path.join(proxy_dir, media["file_name"])

# Get expected path partial match for globbing
glob_partial_match = os.path.splitext(glob_partial_match)[0]
Expand All @@ -289,7 +287,7 @@ def get_newest_proxy_file(media, expected_proxy_path: str) -> Union[str, None]:
logger.debug(
f"[green bold]Matched existing proxy: '{existing_proxy_file}'\n"
)
media.update({"unlinked_proxy": existing_proxy_file})
media.update({"proxy_media_path": existing_proxy_file})
existing_unlinked.append(existing_proxy_file)

# If any unlinked, prompt for linking
Expand All @@ -307,7 +305,9 @@ def get_newest_proxy_file(media, expected_proxy_path: str) -> Union[str, None]:
"[/bold]Would you like to link them? If not they will be re-rendered."
):

return link.link_proxies_with_mpi(media_list)
return link.link_proxies_with_mpi(
media_list, linkable_types=["Offline", "None"]
)

else:

Expand All @@ -332,7 +332,7 @@ def handle_offline_proxies(media_list: list) -> list:
"""

logger.info(f"[cyan]Checking for offline proxies[/]")
offline_proxies = [x for x in media_list if x["proxy"] == "Offline"]
offline_proxies = [x for x in media_list if x["proxy_status"] == "Offline"]

if len(offline_proxies) > 0:

Expand All @@ -351,7 +351,7 @@ def handle_offline_proxies(media_list: list) -> list:

for x in media_list:
if x["file_path"] == offline_proxy["file_path"]:
x["proxy"] = "None"
x["proxy_status"] = "None"

elif answer.lower().startswith("a"):

Expand All @@ -361,7 +361,7 @@ def handle_offline_proxies(media_list: list) -> list:

for x in media_list:
if x == "Offline":
x["proxy"] = "None"
x["proxy_status"] = "None"

global SOME_ACTION_TAKEN
SOME_ACTION_TAKEN = True
Expand Down
27 changes: 15 additions & 12 deletions resolve_proxy_encoder/queuer/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def find_and_link_proxies(project, proxy_files) -> Tuple[list, list]:
return linked, failed


def link_proxies_with_mpi(media_list):
def link_proxies_with_mpi(media_list, linkable_types: list = ["Offline", "None"]):
"""Iterate through media mutated during script call, attempt to link the source media.
Return all that are not succesfully linked."""

Expand All @@ -234,23 +234,26 @@ def link_proxies_with_mpi(media_list):
# Iterate through all available proxies
for media in media_list:

proxy = media.get("unlinked_proxy", None)
proxy_media_path = media.get("proxy_media_path", None)
proxy_status = media.get("proxy_status")

if not proxy:
if proxy_status not in linkable_types:
continue

if not os.path.exists(proxy):
logger.error(f"[red]Proxy media not found at '{proxy}'")

else:
# Set existing to none once linked
media.update({"unlinked_proxy": None})
if not os.path.exists(proxy_media_path):
logger.error(f"[red]Proxy media not found at '{proxy_media_path}'")
media.update({"proxy_media_path": None})

# TODO: Should probably use MediaInfo here instead of hardcode
media.update({"Proxy": "1280x720"})

# We only define the vertical res in `user_settings` so we can preserve aspect ratio.
# To get the proper resolution, we'd have to get the original file resolution.
# labels: enhancement

media.update({"proxy_status": "1280x720"})

# Actually link proxies
if media["media_pool_item"].LinkProxyMedia(proxy):
if media["media_pool_item"].LinkProxyMedia(proxy_media_path):

# TODO get this working!
logger.info(f"[green bold]Linked [/]'{media['clip_name']}'")
Expand Down Expand Up @@ -278,7 +281,7 @@ def link_proxies_with_mpi(media_list):
# Remove offline status, redefine media list
for x in media_list:
if x in link_fail:
x["proxy"] = "None"
x["proxy_status"] = "None"

media_list = [x for x in media_list if x not in link_success]

Expand Down
2 changes: 1 addition & 1 deletion resolve_proxy_encoder/queuer/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def main():
logger.info("[cyan]Linking proxies")

try:
proxies = [x["unlinked_proxy"] for x in jobs]
proxies = [x["proxy_media_path"] for x in jobs]
link.find_and_link_proxies(r_.project, proxies)
core.app_exit(0)

Expand Down
6 changes: 3 additions & 3 deletions resolve_proxy_encoder/queuer/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def get_resolve_proxy_jobs(media_pool_items):
file_path = clip_properties["File Path"]
p = pathlib.Path(file_path)

expected_proxy_dir = os.path.normpath(
proxy_dir = os.path.normpath(
os.path.join(
settings["paths"]["proxy_path_root"],
os.path.dirname(p.relative_to(*p.parts[:1])),
Expand All @@ -291,11 +291,11 @@ def get_resolve_proxy_jobs(media_pool_items):
"fps": float(cp["FPS"]),
"h_flip": True if cp["H-FLIP"] == "On" else False,
"v_flip": True if cp["H-FLIP"] == "On" else False,
"proxy": cp["Proxy"],
"proxy_status": cp["Proxy"],
"proxy_media_path": cp["Proxy Media Path"]
if not len(cp["Proxy Media Path"])
else cp["Proxy Media Path"],
"expected_proxy_dir": expected_proxy_dir,
"proxy_dir": proxy_dir,
"start": int(cp["Start"]),
"end": int(cp["End"]),
"start_tc": cp["Start TC"],
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion resolve_proxy_encoder/settings/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ def __getitem__(self, __items):
if type(__items) == str:
__items = __items.split(" ")

return reduce(operator.getitem, __items, self.user_settings)
try:
return reduce(operator.getitem, __items, self.user_settings)

except KeyError as e:

raise KeyError(e)

def _load_default_file(self):
"""Load default settings from yaml"""
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions resolve_proxy_encoder/worker/tasks/encode/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ def encode_proxy(self, job):
# TODO: Integrate cross-platform path mapping. Move `check_wsl` func.
# Convert paths for WSL
if check_wsl():
job["expected_proxy_dir"].update(get_wsl_path(job["expected_proxy_dir"]))
job["proxy_dir"].update(get_wsl_path(job["proxy_dir"]))

# Create proxy dir

logger.debug(f"Output Dir: '{job['expected_proxy_dir']}'")
logger.debug(f"Output Dir: '{job['proxy_dir']}'")
try:

os.makedirs(
job["expected_proxy_dir"],
job["proxy_dir"],
exist_ok=True,
)

Expand All @@ -70,7 +70,7 @@ def encode_proxy(self, job):
raise e

output_file = os.path.join(
job["expected_proxy_dir"],
job["proxy_dir"],
os.path.splitext(job["file_name"])[0] + proxy_settings["ext"],
)
logger.info(f"Output File: '{output_file}'\n")
Expand Down
Binary file not shown.
Binary file not shown.