Skip to content

Commit 16a1d35

Browse files
fix: unlinked_proxy KeyError (#136)
* what the heck... * chore: [pre-commit.ci] automatic fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 896c83c commit 16a1d35

File tree

65 files changed

+44
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+44
-36
lines changed
147 KB
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.

resolve_proxy_encoder/queuer/handlers.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import os
44
import pathlib
55
import shutil
6-
import sys
7-
from tkinter import E
86
from typing import Union
97

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

121119
for media in media_list:
122-
if media["proxy"] != "None" or media["proxy"] == "Offline":
120+
if media["proxy_status"] != "None" or media["proxy_status"] == "Offline":
123121
linked_proxy_path = os.path.splitext(media["proxy_media_path"])
124122
linked_proxy_path[1].lower()
125123

@@ -196,7 +194,9 @@ def handle_already_linked(
196194
"""
197195

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

201201
if len(already_linked) > 0:
202202

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

270-
if media["proxy"] in unlinked_types:
270+
if media["proxy_status"] in unlinked_types:
271271

272-
expected_proxy_dir = media["expected_proxy_dir"]
273-
logger.debug(
274-
f"[magenta]Expected proxy directory:[/] '{expected_proxy_dir}'"
275-
)
272+
proxy_dir = media["proxy_dir"]
273+
logger.debug(f"[magenta]Expected proxy directory:[/] '{proxy_dir}'")
276274

277275
# Get expected proxy path
278-
glob_partial_match = os.path.join(expected_proxy_dir, media["file_name"])
276+
glob_partial_match = os.path.join(proxy_dir, media["file_name"])
279277

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

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

310-
return link.link_proxies_with_mpi(media_list)
308+
return link.link_proxies_with_mpi(
309+
media_list, linkable_types=["Offline", "None"]
310+
)
311311

312312
else:
313313

@@ -332,7 +332,7 @@ def handle_offline_proxies(media_list: list) -> list:
332332
"""
333333

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

337337
if len(offline_proxies) > 0:
338338

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

352352
for x in media_list:
353353
if x["file_path"] == offline_proxy["file_path"]:
354-
x["proxy"] = "None"
354+
x["proxy_status"] = "None"
355355

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

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

362362
for x in media_list:
363363
if x == "Offline":
364-
x["proxy"] = "None"
364+
x["proxy_status"] = "None"
365365

366366
global SOME_ACTION_TAKEN
367367
SOME_ACTION_TAKEN = True

resolve_proxy_encoder/queuer/link.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def find_and_link_proxies(project, proxy_files) -> Tuple[list, list]:
222222
return linked, failed
223223

224224

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

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

237-
proxy = media.get("unlinked_proxy", None)
237+
proxy_media_path = media.get("proxy_media_path", None)
238+
proxy_status = media.get("proxy_status")
238239

239-
if not proxy:
240+
if proxy_status not in linkable_types:
240241
continue
241242

242-
if not os.path.exists(proxy):
243-
logger.error(f"[red]Proxy media not found at '{proxy}'")
244-
245-
else:
246-
# Set existing to none once linked
247-
media.update({"unlinked_proxy": None})
243+
if not os.path.exists(proxy_media_path):
244+
logger.error(f"[red]Proxy media not found at '{proxy_media_path}'")
245+
media.update({"proxy_media_path": None})
248246

249247
# TODO: Should probably use MediaInfo here instead of hardcode
250-
media.update({"Proxy": "1280x720"})
248+
249+
# We only define the vertical res in `user_settings` so we can preserve aspect ratio.
250+
# To get the proper resolution, we'd have to get the original file resolution.
251+
# labels: enhancement
252+
253+
media.update({"proxy_status": "1280x720"})
251254

252255
# Actually link proxies
253-
if media["media_pool_item"].LinkProxyMedia(proxy):
256+
if media["media_pool_item"].LinkProxyMedia(proxy_media_path):
254257

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

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

resolve_proxy_encoder/queuer/queue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def main():
136136
logger.info("[cyan]Linking proxies")
137137

138138
try:
139-
proxies = [x["unlinked_proxy"] for x in jobs]
139+
proxies = [x["proxy_media_path"] for x in jobs]
140140
link.find_and_link_proxies(r_.project, proxies)
141141
core.app_exit(0)
142142

resolve_proxy_encoder/queuer/resolve.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def get_resolve_proxy_jobs(media_pool_items):
271271
file_path = clip_properties["File Path"]
272272
p = pathlib.Path(file_path)
273273

274-
expected_proxy_dir = os.path.normpath(
274+
proxy_dir = os.path.normpath(
275275
os.path.join(
276276
settings["paths"]["proxy_path_root"],
277277
os.path.dirname(p.relative_to(*p.parts[:1])),
@@ -291,11 +291,11 @@ def get_resolve_proxy_jobs(media_pool_items):
291291
"fps": float(cp["FPS"]),
292292
"h_flip": True if cp["H-FLIP"] == "On" else False,
293293
"v_flip": True if cp["H-FLIP"] == "On" else False,
294-
"proxy": cp["Proxy"],
294+
"proxy_status": cp["Proxy"],
295295
"proxy_media_path": cp["Proxy Media Path"]
296296
if not len(cp["Proxy Media Path"])
297297
else cp["Proxy Media Path"],
298-
"expected_proxy_dir": expected_proxy_dir,
298+
"proxy_dir": proxy_dir,
299299
"start": int(cp["Start"]),
300300
"end": int(cp["End"]),
301301
"start_tc": cp["Start TC"],
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.

resolve_proxy_encoder/settings/manager.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ def __getitem__(self, __items):
9191
if type(__items) == str:
9292
__items = __items.split(" ")
9393

94-
return reduce(operator.getitem, __items, self.user_settings)
94+
try:
95+
return reduce(operator.getitem, __items, self.user_settings)
96+
97+
except KeyError as e:
98+
99+
raise KeyError(e)
95100

96101
def _load_default_file(self):
97102
"""Load default settings from yaml"""
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.

resolve_proxy_encoder/worker/tasks/encode/tasks.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ def encode_proxy(self, job):
5353
# TODO: Integrate cross-platform path mapping. Move `check_wsl` func.
5454
# Convert paths for WSL
5555
if check_wsl():
56-
job["expected_proxy_dir"].update(get_wsl_path(job["expected_proxy_dir"]))
56+
job["proxy_dir"].update(get_wsl_path(job["proxy_dir"]))
5757

5858
# Create proxy dir
5959

60-
logger.debug(f"Output Dir: '{job['expected_proxy_dir']}'")
60+
logger.debug(f"Output Dir: '{job['proxy_dir']}'")
6161
try:
6262

6363
os.makedirs(
64-
job["expected_proxy_dir"],
64+
job["proxy_dir"],
6565
exist_ok=True,
6666
)
6767

@@ -70,7 +70,7 @@ def encode_proxy(self, job):
7070
raise e
7171

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

0 commit comments

Comments
 (0)