[Blender_Kitsu] Publish VSE Edit as Revision on Kitsu #7
@ -31,24 +31,6 @@ def get_all_edits_with_tasks(relations=False, client=default):
|
||||
edits_with_tasks = raw.fetch_all(path, params, client=client)
|
||||
return sort_by_name(edits_with_tasks)
|
||||
|
||||
def add_comment_on_edit_task(task_id:str,
|
||||
rendered_filepath = None, comment=""
|
||||
):
|
||||
"""
|
||||
Comment Full Edit Render on Edit Task
|
||||
|
||||
Args:
|
||||
#TODO
|
||||
|
||||
Returns:
|
||||
Comment on Edit Task.
|
||||
"""
|
||||
|
||||
task_entity = gazu.task.get_task(task_id)
|
||||
new_comment = gazu.task.add_comment(task_entity, task_entity["task_status"], comment)
|
||||
uploaded_preview = gazu.task.add_preview(task_entity, new_comment, rendered_filepath)
|
||||
return new_comment
|
||||
|
||||
@cache
|
||||
def get_all_previews_for_edit(edit, client=default):
|
||||
"""
|
||||
|
@ -309,7 +309,21 @@ class KITSU_OT_sqe_push_new_shot(bpy.types.Operator):
|
||||
% (noun.lower()),
|
||||
)
|
||||
|
||||
def get_dict_len(items:dict):
|
||||
try:
|
||||
return len(items)
|
||||
except TypeError:
|
||||
return None
|
||||
|
||||
def set_revision_int(prev_rev=None):
|
||||
if prev_rev is None:
|
||||
return 1
|
||||
return prev_rev+1
|
||||
|
||||
def get_enum_item_name(items, key):
|
||||
for item in items:
|
||||
if item[0] == key:
|
||||
return item[1]
|
||||
class KITSU_OT_sqe_push_new_edit(bpy.types.Operator):
|
||||
bl_idname = "kitsu.sqe_push_new_edit_comment"
|
||||
bl_label = "Submit New Kitsu Edit Comment"
|
||||
@ -330,7 +344,7 @@ class KITSU_OT_sqe_push_new_edit(bpy.types.Operator):
|
||||
return [(item.get("id"), item.get("name"), f'Created at: "{item.get("created_at")}" {item.get("description")}') for item in tasks]
|
||||
|
||||
comment: bpy.props.StringProperty(name="comment")
|
||||
edit_entry: bpy.props.EnumProperty(name="Edit Entry", items=get_edit_entry_enum_key)
|
||||
edit_entry: bpy.props.EnumProperty(name="Edit Entry", items=get_edit_entry_items)
|
||||
task: bpy.props.EnumProperty(name="Edit Tasks", items=get_edit_task_items)
|
||||
render_dir: bpy.props.StringProperty(
|
||||
name="Render Directory",
|
||||
@ -365,6 +379,12 @@ class KITSU_OT_sqe_push_new_edit(bpy.types.Operator):
|
||||
self.report({"ERROR"}, "Selected edit doesn't have any task associated with it .")
|
||||
return {"CANCELLED"}
|
||||
|
||||
active_project = cache.project_active_get()
|
||||
|
||||
existing_previews = gazu.edit.get_all_previews_for_edit(self.edit_entry)
|
||||
len_previews = get_dict_len(existing_previews)
|
||||
revision = set_revision_int(len_previews)
|
||||
|
||||
# Build render_path
|
||||
render_dir = bpy.path.abspath(self.render_dir)
|
||||
if not os.path.isdir(Path(render_dir)):
|
||||
@ -373,31 +393,26 @@ class KITSU_OT_sqe_push_new_edit(bpy.types.Operator):
|
||||
f"Render path is not set to a directory. '{self.render_dir}'"
|
||||
)
|
||||
return {"CANCELLED"}
|
||||
render_name = f"{self.render_name.replace('.','_')}.mp4"
|
||||
edits = self.get_edit_entry_items(context)
|
||||
edit_name = get_enum_item_name(edits, self.edit_entry)
|
||||
render_name = f"{active_project.name}_{edit_name}_v{revision}.mp4"
|
||||
render_path = Path(render_dir).joinpath(render_name)
|
||||
|
||||
# Build Comment
|
||||
time = str(datetime.datetime.now())
|
||||
message = f"{self.comment}\n\n\nFile: {render_name} \n\nSubmitted on: {time}"
|
||||
|
||||
|
||||
# Render Sequence to .mp4
|
||||
with override_render_path(self, context, render_path.as_posix()):
|
||||
with override_render_format(self, context):
|
||||
bpy.ops.render.opengl(animation=True, sequencer=True)
|
||||
|
||||
# Submit to Kitsu Edit Task
|
||||
gazu.edit.add_comment_on_edit_task(
|
||||
self.task,
|
||||
render_path,
|
||||
message
|
||||
)
|
||||
# Create comment with video
|
||||
task_entity = gazu.task.get_task(self.task,)
|
||||
new_comment = gazu.task.add_comment(task_entity, task_entity["task_status"])
|
||||
uploaded_preview = gazu.task.add_preview(task_entity, new_comment, render_path)
|
||||
|
||||
self.report(
|
||||
{"INFO"},
|
||||
f"Submitted new comment for render'{self.render_name}'"
|
||||
f"Submitted new comment 'Revision {revision}'"
|
||||
)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class KITSU_OT_sqe_push_new_sequence(bpy.types.Operator):
|
||||
bl_idname = "kitsu.sqe_push_new_sequence"
|
||||
bl_label = "Submit New Sequence"
|
||||
|
Loading…
Reference in New Issue
Block a user