diff --git a/operators/operators.py b/operators/operators.py index a47c5b3..64aece5 100644 --- a/operators/operators.py +++ b/operators/operators.py @@ -98,13 +98,18 @@ def get_task_status_items(self, context): project = settings.active_project status_items = [('CURRENT', 'Current', '')] - status_items += [(t.name, t.name, '') for t in project.task_statuses] + + if project: + status_items += [(t.name, t.name, '') for t in project.task_statuses] return status_items def get_task_type_items(self, context): settings = get_scene_settings() project = settings.active_project + if not project: + return [('NONE', 'None', '')] + return [(t.name, t.name, '') for t in project.task_types] class VSETB_OT_upload_to_tracker(Operator): @@ -158,7 +163,7 @@ class VSETB_OT_upload_to_tracker(Operator): #self.report({'ERROR'}, f'Export not implemented yet.') prefs = get_addon_prefs() settings = get_scene_settings() - #project = settings.active_project + project = settings.active_project tracker = prefs.tracker status = self.status @@ -170,6 +175,10 @@ class VSETB_OT_upload_to_tracker(Operator): shot_name = strip.name sequence = tracker.get_sequence(sequence_name) + + metadata = strip.vsetb_strip_settings.metadata.to_dict() + print(metadata) + if not sequence: self.report({"INFO"}, f'Create sequence {sequence_name} in Kitsu') sequence = tracker.new_sequence(sequence_name) @@ -180,16 +189,29 @@ class VSETB_OT_upload_to_tracker(Operator): shot = tracker.new_shot(shot_name, sequence=sequence) task = tracker.get_task(self.task, entity=shot) - - print(task) - tracker.new_comment(task, comment=self.comment, status=status) - #status = tracker.get_task(shot, self.task) - # if self.add_preview: - # strip_movie_path = Path(get_strip_render_path(strip, template)) - # if path.exists(): + if not task: + task = tracker.new_task(shot, task_type=self.task) - # else: - # self.report({"WARNING"}, f"{strip_movie_path} not exist, skipped") + # print('\n', 'task comment') + # print(task['last_comment']) + + preview = None + if self.add_preview: + preview = Path(get_strip_render_path(strip, project.render_template)) + if not preview.exists(): + preview = None + + elif task['last_comment'].get('previews'): + if self.preview_mode == 'REPLACE': + tracker.remove_comment(task['last_comment']) + elif self.preview_mode == 'ONLY_NEW': + preview = None + + if status != 'CURRENT' or preview: + tracker.new_comment(task, comment=self.comment, status=status, preview=preview) + + if self.custom_data: + tracker.update_data(shot, strip.vsetb_strip_settings.metadata.to_dict()) return {"FINISHED"} @@ -444,7 +466,9 @@ class VSETB_OT_load_projects(Operator): settings = get_scene_settings() prefs = get_addon_prefs() tracker = prefs.tracker - + + old_project_name = settings.project_name.replace(' ', '_').upper() + settings.projects.clear() tracker.connect() @@ -478,11 +502,20 @@ class VSETB_OT_load_projects(Operator): for asset_type_data in tracker.get_asset_types(project_data): asset_type = project.asset_types.add() asset_type.name = asset_type_data['name'] + + for project in settings.projects: + print(project.name, project.name.replace(' ', '_').upper(), old_project_name) + if project.name.replace(' ', '_').upper() == old_project_name: + + print('Restore Project Name') + settings.project_name = project.name + #else: + # print('Could Not restore Project Name') + + #if settings.active_project: + # settings.active_project.set_strip_metadata() - if settings.active_project: - settings.active_project.set_strip_metadata() - - bpy.ops.vse_toolbox.load_assets() + #bpy.ops.vse_toolbox.load_assets() return {'FINISHED'} diff --git a/properties.py b/properties.py index 1679fad..469b078 100644 --- a/properties.py +++ b/properties.py @@ -23,17 +23,17 @@ def get_episodes_items(self, context): project = settings.active_project if not project: - return [('NONE', 'None', '', 0)] + return [('/', '/', '', 0)] episodes = project.episodes if not episodes: - return [('NONE', 'None', '', 0)] + return [('/', '/', '', 0)] return [(e, e, '', i) for i, e in enumerate(episodes.keys())] def get_project_items(self, context): if not self.projects: - return [('NONE', 'None', '', 0)] + return [('/', '/', '', 0)] return [(p, p, '', i) for i, p in enumerate(self.projects.keys())] @@ -113,6 +113,8 @@ class TaskStatus(PropertyGroup): class Metadata(PropertyGroup): __annotations__ = {} + def to_dict(self): + return {p.name: getattr(self, p.identifier) for p in self.bl_rna.properties.keys() if p.name != 'RNA'} class Episode(PropertyGroup): id : StringProperty(default='') @@ -169,7 +171,7 @@ class Project(PropertyGroup): for metadata_type in self.metadata_types: prop_name = metadata_type.name if metadata_type.get('choices'): - prop = bpy.props.EnumProperty(items=[(c, c.replace(' ', '_').upper(), '') for c in metadata_type['choices']]) + prop = bpy.props.EnumProperty(items=[(c, c.replace(' ', '_').upper(), '') for c in ['/'] + metadata_type['choices']]) else: prop = bpy.props.StringProperty() diff --git a/resources/trackers/kitsu.py b/resources/trackers/kitsu.py index 29caeb8..9992519 100644 --- a/resources/trackers/kitsu.py +++ b/resources/trackers/kitsu.py @@ -116,7 +116,10 @@ class Kitsu(Tracker): return gazu.shot.all_episodes_for_project(project) def get_task_type(self, task_type=None): - print('get_task_type', task_type) + task_type_id = self.get_id(task_type) + if task_type_id: + return task_type_id + return gazu.task.get_task_type_by_name(task_type) def get_shot_task_types(self, project=None): @@ -192,17 +195,32 @@ class Kitsu(Tracker): entity = self.get_id(entity) task_type = self.get_task_type(task) - - print('task_type', task_type) - print('task_type', task_type) - task = gazu.task.get_task_by_name(entity, task_type) + + if not task: + return #task = gazu.task.get_task(task['id']) task['last_comment'] = self.get_last_comment(task) return task + def new_preview(self, task, comment, preview, set_main_preview=False): + #print('new_preview', task, comment, preview, set_main_preview) + + task = self.get_id(task) + comment = self.get_id(comment) + + preview_data = gazu.task.add_preview( + task=task, + comment=comment, + preview_file_path=preview ) + + if set_main_preview: + gazu.task.set_main_preview(preview_data) + + return preview_data + def new_comment(self, task, status=None, comment='', preview=None, set_main_preview=False): #task = self.get_task(task) @@ -213,26 +231,24 @@ class Kitsu(Tracker): else: status = self.get_task_status(status) - - comment = gazu.task.add_comment( task=task, task_status=status, comment=comment ) if preview: - logging.info(f'Adding Preview to Kitsu {preview}') - preview = self.add_preview( + #logging.info(f'Adding Preview to Kitsu {preview}') + preview = self.new_preview( task=task, comment=comment, - preview=str(preview) ) - - if set_main_preview: - gazu.task.set_main_preview(preview) - + preview=str(preview), + set_main_preview=set_main_preview ) return comment + def remove_comment(self, comment): + return gazu.task.remove_comment(comment) + def download_preview(self, preview_id, filepath): if isinstance(filepath, str): filepath = Path(filepath) @@ -243,6 +259,12 @@ class Kitsu(Tracker): filepath.parent.mkdir(parents=True, exist_ok=True) gazu.files.download_preview_file_thumbnail(preview_id, filepath.as_posix()) + def new_task(self, entity, task_type, status=None, project=None): + task_type = self.get_task_type(task_type) + if status: + status = self.get_task_status(status) + return gazu.task.new_task(entity, task_type=task_type, task_status=status) + def new_sequence(self, sequence, episode=None, project=None): project = self.get_project(project) @@ -254,7 +276,7 @@ class Kitsu(Tracker): return gazu.shot.new_sequence(**params) def new_shot(self, shot, sequence, nb_frames=None, frame_in=None, - frame_out=None, description='', custom_data=None, project=None): + frame_out=None, description='', custom_data=None, with_tasks=True, project=None): project = self.get_project(project) sequence = self.get_sequence(sequence) @@ -273,11 +295,41 @@ class Kitsu(Tracker): params["nb_frames"] = nb_frames shot = self.get_shot(shot=shot, sequence=sequence) - if shot: - return shot - else: + if not shot: path = f"data/projects/{self.get_id(project)}/shots" - return gazu.client.post(path, params) + shot = gazu.client.post(path, params) + + if with_tasks: + for task_type in self.get_shot_task_types(project=project): + self.new_task(shot, task_type) + + return shot + + def update_data(self, entity, data, name=None, description=None, frames=None, clear=False): + if isinstance(entity, dict): + entity_id = entity['id'] + else: + entity_id = self.get_id(entity) + entity = gazu.client.fetch_one('entities', entity_id) + + if data.get('custom_data'): + data['data'] = data.pop('custom_data') + + if name: + entity['name'] = name + if description: + entity['description'] = description + if frames: + entity['nb_frames'] = frames + + if clear or not entity['data']: + entity['data'] = data + else: + entity['data'].update(data) + + entity_data = gazu.client.put(f"data/entities/{entity_id}", entity) + + return entity_data['data'] def draw_prefs(self, layout): layout.prop(self, 'url', text='Url') diff --git a/sequencer_utils.py b/sequencer_utils.py index 7497425..f25a627 100644 --- a/sequencer_utils.py +++ b/sequencer_utils.py @@ -124,6 +124,7 @@ def set_channels(): scn.sequence_editor.channels[i].name = c.title() def get_strip_render_path(strip, template): + scn = bpy.context.scene return template.format(strip_name=strip.name, ext=Path(scn.render.frame_path()).suffix) def render_strips(strips, template):