rewrite import_shots and cleanup
This commit is contained in:
+78
-17
@@ -1,6 +1,7 @@
|
||||
|
||||
import bpy
|
||||
import os
|
||||
from os.path import expandvars
|
||||
import re
|
||||
import urllib3
|
||||
import traceback
|
||||
@@ -26,20 +27,36 @@ class Kitsu(Tracker):
|
||||
url: StringProperty()
|
||||
login: StringProperty()
|
||||
password: StringProperty(subtype='PASSWORD')
|
||||
|
||||
admin_login : StringProperty()
|
||||
admin_password : StringProperty(subtype='PASSWORD')
|
||||
|
||||
def connect(self, url=None, login=None, password=None):
|
||||
def admin_connect(self):
|
||||
url = self.url
|
||||
if not url.endswith('/api'):
|
||||
url += '/api'
|
||||
|
||||
login = expandvars(self.admin_login or self.login)
|
||||
password = expandvars(self.admin_password or self.password)
|
||||
|
||||
try:
|
||||
res = gazu.log_in(login, password)
|
||||
LOGIN = login
|
||||
return res['user']
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
def connect(self):
|
||||
'''Connect to kitsu api using provided url, login and password'''
|
||||
|
||||
global LOGIN
|
||||
|
||||
urllib3.disable_warnings()
|
||||
|
||||
if url is None:
|
||||
url = self.url
|
||||
if login is None:
|
||||
login = self.login
|
||||
if password is None:
|
||||
password = self.password
|
||||
url = expandvars(self.url)
|
||||
login = expandvars(self.login)
|
||||
password = expandvars(self.password)
|
||||
|
||||
if not url:
|
||||
print(f'Kitsu Url: {self.url} is empty')
|
||||
@@ -168,6 +185,16 @@ class Kitsu(Tracker):
|
||||
|
||||
return gazu.shot.get_sequence_by_name(**params)
|
||||
|
||||
def get_sequences(self, project=None, episode=None):
|
||||
#print(f'get_sequence({sequence=}, {project=})')
|
||||
project = self.get_project(project)
|
||||
|
||||
if episode:
|
||||
episode = self.get_episode(episode)
|
||||
return gazu.shot.all_sequences_for_episode(episode)
|
||||
else:
|
||||
return gazu.shot.all_sequences_for_project(project)
|
||||
|
||||
def get_shot(self, shot, sequence, project=None):
|
||||
#print(f'get_shot({shot=}, {sequence=}, {project=})')
|
||||
project = self.get_project(project)
|
||||
@@ -182,6 +209,12 @@ class Kitsu(Tracker):
|
||||
|
||||
return gazu.shot.get_shot_by_name(sequence, shot)
|
||||
|
||||
def get_shots(self, sequence):
|
||||
#print(f'get_sequence({sequence=}, {project=})')
|
||||
#project = self.get_project(project)
|
||||
|
||||
return gazu.shot.all_shots_for_sequence(sequence)
|
||||
|
||||
def get_asset(self, asset, asset_type=None, project=None):
|
||||
#print('get_asset', "name", name, 'asset_type', asset_type)
|
||||
|
||||
@@ -211,6 +244,29 @@ class Kitsu(Tracker):
|
||||
task = self.get_id(task)
|
||||
return gazu.task.get_last_comment_for_task(task)
|
||||
|
||||
def get_last_comment_with_preview(self, task):
|
||||
task = self.get_id(task)
|
||||
comments = gazu.task.all_comments_for_task(task)
|
||||
for comment in comments:
|
||||
if comment['previews']:
|
||||
return comment
|
||||
|
||||
def download_preview_file(self, preview, filepath):
|
||||
preview_id = self.get_id(preview)
|
||||
return gazu.files.download_preview_file(preview_id, str(filepath))
|
||||
|
||||
def get_shots_search_url(self, shot_names, project=None, episode=None):
|
||||
project = self.get_project(project)
|
||||
url = gazu.client.get_host().replace('/api', f'/productions/{project}')
|
||||
|
||||
if episode:
|
||||
episode = self.get_episode(episode)
|
||||
url += f'/episodes/{episode["id"]}'
|
||||
|
||||
url += f'/shots'
|
||||
|
||||
return f'{url}?search={" ".join(shot_names)}'
|
||||
|
||||
def get_task(self, task=None, entity=None):
|
||||
entity = self.get_id(entity)
|
||||
|
||||
@@ -225,6 +281,9 @@ class Kitsu(Tracker):
|
||||
|
||||
return task
|
||||
|
||||
def set_main_preview(self, preview_data):
|
||||
gazu.task.set_main_preview(preview_data)
|
||||
|
||||
def new_preview(self, task, comment, preview, set_main_preview=False):
|
||||
#print('new_preview', task, comment, preview, set_main_preview)
|
||||
|
||||
@@ -238,7 +297,7 @@ class Kitsu(Tracker):
|
||||
|
||||
if set_main_preview:
|
||||
#print('----', 'Settings')
|
||||
gazu.task.set_main_preview(preview_data)
|
||||
self.set_main_preview(preview_data)
|
||||
|
||||
return preview_data
|
||||
|
||||
@@ -327,16 +386,13 @@ class Kitsu(Tracker):
|
||||
|
||||
return shot
|
||||
|
||||
def update_data(self, entity, data, name=None, description=None, frames=None, clear=False):
|
||||
def update_data(self, entity, custom_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:
|
||||
@@ -345,9 +401,9 @@ class Kitsu(Tracker):
|
||||
entity['nb_frames'] = frames
|
||||
|
||||
if clear or not entity['data']:
|
||||
entity['data'] = data
|
||||
entity['data'] = custom_data
|
||||
else:
|
||||
entity['data'].update(data)
|
||||
entity['data'].update(custom_data)
|
||||
|
||||
#print('######UPDATE DATA')
|
||||
#pprint(entity)
|
||||
@@ -387,6 +443,11 @@ class Kitsu(Tracker):
|
||||
return gazu.casting.update_shot_casting(project, shot_id, norm_casting)
|
||||
|
||||
def draw_prefs(self, layout):
|
||||
layout.prop(self, 'url', text='Url')
|
||||
layout.prop(self, 'login', text='Login')
|
||||
layout.prop(self, 'password', text='Password')
|
||||
col = layout.column(align=False)
|
||||
col.prop(self, 'url', text='Url')
|
||||
col.prop(self, 'login', text='Login')
|
||||
col.prop(self, 'password', text='Password')
|
||||
|
||||
col.separator()
|
||||
col.prop(self, 'admin_login', text='Admin Login')
|
||||
col.prop(self, 'admin_password', text='Admin Password')
|
||||
Reference in New Issue
Block a user