Blender Kitsu: Add Import Edit Render Operator for Shots #236
@ -4,32 +4,32 @@ import re
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def edit_export_get_latest(context: bpy.types.Context):
|
def edit_render_get_latest(context: bpy.types.Context):
|
||||||
"""Find latest export in editorial export directory"""
|
"""Find latest render in editorial render directory"""
|
||||||
|
|
||||||
files_list = edit_exports_get_all(context)
|
files_list = edit_renders_get_all(context)
|
||||||
if len(files_list) >= 1:
|
if len(files_list) >= 1:
|
||||||
files_list = sorted(files_list, reverse=True)
|
files_list = sorted(files_list, reverse=True)
|
||||||
return files_list[0]
|
return files_list[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def edit_exports_get_all(context: bpy.types.Context):
|
def edit_renders_get_all(context: bpy.types.Context):
|
||||||
"""Find latest export in editorial export directory"""
|
"""Find latest render in editorial render directory"""
|
||||||
addon_prefs = prefs.addon_prefs_get(context)
|
addon_prefs = prefs.addon_prefs_get(context)
|
||||||
|
|
||||||
edit_export_path = Path(addon_prefs.edit_export_dir)
|
edit_render_path = Path(addon_prefs.edit_export_dir)
|
||||||
|
|
||||||
files_list = [
|
files_list = [
|
||||||
f
|
f
|
||||||
for f in edit_export_path.iterdir()
|
for f in edit_render_path.iterdir()
|
||||||
if f.is_file()
|
if f.is_file()
|
||||||
and edit_export_is_valid_edit_name(addon_prefs.edit_export_file_pattern, f.name)
|
and edit_render_is_valid_edit_name(addon_prefs.edit_export_file_pattern, f.name)
|
||||||
]
|
]
|
||||||
return files_list
|
return files_list
|
||||||
|
|
||||||
|
|
||||||
def edit_export_is_valid_edit_name(file_pattern: str, filename: str) -> bool:
|
def edit_render_is_valid_edit_name(file_pattern: str, filename: str) -> bool:
|
||||||
"""Verify file name matches file pattern set in preferences"""
|
"""Verify file name matches file pattern set in preferences"""
|
||||||
# Prevents un-expected matches
|
# Prevents un-expected matches
|
||||||
file_pattern = re.escape(file_pattern)
|
file_pattern = re.escape(file_pattern)
|
||||||
@ -40,13 +40,13 @@ def edit_export_is_valid_edit_name(file_pattern: str, filename: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def edit_export_import_latest(
|
def edit_render_import_latest(
|
||||||
context: bpy.types.Context, shot
|
context: bpy.types.Context, shot
|
||||||
) -> list[bpy.types.Sequence]: # TODO add info to shot
|
) -> list[bpy.types.Sequence]: # TODO add info to shot
|
||||||
"""Loads latest export from editorial department"""
|
"""Loads latest render from editorial department"""
|
||||||
addon_prefs = prefs.addon_prefs_get(context)
|
addon_prefs = prefs.addon_prefs_get(context)
|
||||||
strip_channel = 1
|
strip_channel = 1
|
||||||
latest_file = edit_export_get_latest(context)
|
latest_file = edit_render_get_latest(context)
|
||||||
if not latest_file:
|
if not latest_file:
|
||||||
return None
|
return None
|
||||||
# Check if Kitsu server returned empty shot
|
# Check if Kitsu server returned empty shot
|
||||||
|
@ -8,7 +8,7 @@ from ..types import Task, TaskStatus
|
|||||||
from ..playblast.core import override_render_path, override_render_format
|
from ..playblast.core import override_render_path, override_render_format
|
||||||
from . import opsdata
|
from . import opsdata
|
||||||
from ..logger import LoggerFactory
|
from ..logger import LoggerFactory
|
||||||
from .core import edit_export_import_latest, edit_exports_get_all, edit_export_get_latest
|
from .core import edit_render_import_latest, edit_renders_get_all, edit_render_get_latest
|
||||||
|
|
||||||
logger = LoggerFactory.getLogger()
|
logger = LoggerFactory.getLogger()
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ class KITSU_OT_edit_render_publish(bpy.types.Operator):
|
|||||||
bl_description = (
|
bl_description = (
|
||||||
"Renders current VSE Edit as .mp4"
|
"Renders current VSE Edit as .mp4"
|
||||||
"Saves the set version to disk and uploads it to Kitsu with the specified "
|
"Saves the set version to disk and uploads it to Kitsu with the specified "
|
||||||
"comment and task type. Overrides some render settings during export. "
|
"comment and task type. Overrides some render settings during render. "
|
||||||
)
|
)
|
||||||
|
|
||||||
task_status: bpy.props.EnumProperty(name="Task Status", items=cache.get_all_task_statuses_enum)
|
task_status: bpy.props.EnumProperty(name="Task Status", items=cache.get_all_task_statuses_enum)
|
||||||
@ -253,7 +253,7 @@ class KITSU_OT_edit_render_import_latest(bpy.types.Operator):
|
|||||||
def check_if_latest_edit_render_is_imported(self, context: Context) -> bool:
|
def check_if_latest_edit_render_is_imported(self, context: Context) -> bool:
|
||||||
# Check if latest edit render is already loaded.
|
# Check if latest edit render is already loaded.
|
||||||
for strip in self._existing_edit_renders:
|
for strip in self._existing_edit_renders:
|
||||||
latest_edit_render_path = edit_export_get_latest(context)
|
latest_edit_render_path = edit_render_get_latest(context)
|
||||||
if self.compare_strip_to_path(strip, latest_edit_render_path):
|
if self.compare_strip_to_path(strip, latest_edit_render_path):
|
||||||
self._latest_render_name = latest_edit_render_path.name
|
self._latest_render_name = latest_edit_render_path.name
|
||||||
return True
|
return True
|
||||||
@ -278,7 +278,7 @@ class KITSU_OT_edit_render_import_latest(bpy.types.Operator):
|
|||||||
addon_prefs = prefs.addon_prefs_get(context)
|
addon_prefs = prefs.addon_prefs_get(context)
|
||||||
|
|
||||||
# Get paths to all edit renders
|
# Get paths to all edit renders
|
||||||
all_edit_render_paths = edit_exports_get_all(context)
|
all_edit_render_paths = edit_renders_get_all(context)
|
||||||
if all_edit_render_paths == []:
|
if all_edit_render_paths == []:
|
||||||
self.report(
|
self.report(
|
||||||
{"WARNING"},
|
{"WARNING"},
|
||||||
@ -302,7 +302,7 @@ class KITSU_OT_edit_render_import_latest(bpy.types.Operator):
|
|||||||
|
|
||||||
# Import new edit render
|
# Import new edit render
|
||||||
shot = cache.shot_active_get()
|
shot = cache.shot_active_get()
|
||||||
strips = edit_export_import_latest(context, shot)
|
strips = edit_render_import_latest(context, shot)
|
||||||
|
|
||||||
if strips is None:
|
if strips is None:
|
||||||
self.report({"WARNING"}, f"Loaded Latest Editorial Render failed to import!")
|
self.report({"WARNING"}, f"Loaded Latest Editorial Render failed to import!")
|
||||||
|
@ -43,17 +43,17 @@ def init_edit_render_file_model(
|
|||||||
|
|
||||||
addon_prefs = prefs.addon_prefs_get(context)
|
addon_prefs = prefs.addon_prefs_get(context)
|
||||||
kitsu_props = context.scene.kitsu
|
kitsu_props = context.scene.kitsu
|
||||||
edit_export_dir = Path(addon_prefs.edit_export_dir)
|
edit_render_dir = Path(addon_prefs.edit_export_dir)
|
||||||
|
|
||||||
# Is None if invalid.
|
# Is None if invalid.
|
||||||
if addon_prefs.edit_export_dir == "" or not edit_export_dir.exists():
|
if addon_prefs.edit_export_dir == "" or not edit_render_dir.exists():
|
||||||
logger.error(
|
logger.error(
|
||||||
"Failed to initialize edit render file model. Invalid path. Check addon preferences"
|
"Failed to initialize edit render file model. Invalid path. Check addon preferences"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
EDIT_RENDER_FILE_MODEL.reset()
|
EDIT_RENDER_FILE_MODEL.reset()
|
||||||
EDIT_RENDER_FILE_MODEL.root_path = edit_export_dir
|
EDIT_RENDER_FILE_MODEL.root_path = edit_render_dir
|
||||||
|
|
||||||
if not EDIT_RENDER_FILE_MODEL.versions:
|
if not EDIT_RENDER_FILE_MODEL.versions:
|
||||||
EDIT_RENDER_FILE_MODEL.append_item("v001")
|
EDIT_RENDER_FILE_MODEL.append_item("v001")
|
||||||
|
@ -41,7 +41,7 @@ from .auth.ops import (
|
|||||||
)
|
)
|
||||||
from .context.ops import KITSU_OT_con_productions_load
|
from .context.ops import KITSU_OT_con_productions_load
|
||||||
from .lookdev.prefs import LOOKDEV_preferences
|
from .lookdev.prefs import LOOKDEV_preferences
|
||||||
from .edit.core import edit_export_get_latest
|
from .edit.core import edit_render_get_latest
|
||||||
|
|
||||||
|
|
||||||
logger = LoggerFactory.getLogger()
|
logger = LoggerFactory.getLogger()
|
||||||
@ -613,7 +613,7 @@ class KITSU_addon_preferences(bpy.types.AddonPreferences):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_editorial_dir_valid(self) -> bool:
|
def is_editorial_dir_valid(self) -> bool:
|
||||||
if edit_export_get_latest(bpy.context) is None:
|
if edit_render_get_latest(bpy.context) is None:
|
||||||
logger.error(
|
logger.error(
|
||||||
"Failed to initialize editorial export file model. Invalid path/pattern. Check addon preferences"
|
"Failed to initialize editorial export file model. Invalid path/pattern. Check addon preferences"
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,7 @@ from .core import (
|
|||||||
)
|
)
|
||||||
from ..context import core as context_core
|
from ..context import core as context_core
|
||||||
|
|
||||||
from ..edit.core import edit_export_import_latest
|
from ..edit.core import edit_render_import_latest
|
||||||
from .file_save import save_shot_builder_file
|
from .file_save import save_shot_builder_file
|
||||||
from .template import replace_workspace_with_template
|
from .template import replace_workspace_with_template
|
||||||
from .assets import get_shot_assets
|
from .assets import get_shot_assets
|
||||||
@ -236,7 +236,7 @@ class KITSU_OT_build_new_shot(bpy.types.Operator):
|
|||||||
link_task_type_output_collections(shot, task_type)
|
link_task_type_output_collections(shot, task_type)
|
||||||
|
|
||||||
if bkglobals.LOAD_EDITORIAL_REF.get(task_type_short_name):
|
if bkglobals.LOAD_EDITORIAL_REF.get(task_type_short_name):
|
||||||
edit_export_import_latest(context, shot)
|
edit_render_import_latest(context, shot)
|
||||||
|
|
||||||
# Run Hooks
|
# Run Hooks
|
||||||
hooks_instance = Hooks()
|
hooks_instance = Hooks()
|
||||||
|
Loading…
Reference in New Issue
Block a user