def create_shot(self, parent, shot_name): import traceback import ftrack shot = None try: shot = parent.createShot(shot_name) msg = "Creating new shot with name \"{}{}\".".format(parent, shot_name) self.log.info(msg) except: self.log.error(traceback.format_exc()) path = [] try: for p in reversed(parent.getParents()): path.append(p.getName()) except: pass path.append(parent.getName()) path.append(shot_name) shot = ftrack.getShot(path) return shot
def getShot(shotPath): shot = None try: shot = ftrack.getShot(shotPath) except Exception: pass return shot
def updateftrackshotinfo(self, FTRACK_SERVER='http://192.168.9.200', FTRACK_APIKEY='b445309f-1c5d-40ac-b68b-3fdfb4f3ccb9', LOGNAME='andyguo', PROJECTNAME='Piggy Bank'): os.environ['FTRACK_SERVER'] = FTRACK_SERVER os.environ['FTRACK_APIKEY'] = FTRACK_APIKEY os.environ['LOGNAME'] = LOGNAME import ftrack project = ftrack.getProject(PROJECTNAME) if project is not None: print(project) for clip in self._cliplist: try: shot = ftrack.getShot([PROJECTNAME, clip['sequence'][0], clip['shot'][0]]) shot.setMeta({}) temp = {} temp['01_sequence'] = clip['sequence'][0] temp['02_shot'] = clip['shot'][0] temp['05_s3d'] = clip['s3d'] temp['06_metadata'] = str(clip['metadata']) temp['03_startframe'] = clip['startframe'] temp['04_endframe'] = clip['endframe'] print(shot) shot.setMeta(temp) # break except: print('no such shot %s_%s', clip['sequence'][0], clip['shot'][0])
def create_shot(self, parent, shot_name): import traceback import ftrack shot = None try: shot = parent.createShot(shot_name) msg = "Creating new shot with name \"{}{}\".".format( parent, shot_name) self.log.info(msg) except: self.log.error(traceback.format_exc()) path = [] try: for p in reversed(parent.getParents()): path.append(p.getName()) except: pass path.append(parent.getName()) path.append(shot_name) shot = ftrack.getShot(path) return shot
def process(self, instance, context): # skipping if not launched from ftrack if not context.has_data('ftrackData'): return ftrack_data = context.data('ftrackData') parent = ftrack.Project(ftrack_data['Project']['id']) parent_path = [parent.getName()] if 'Episode' in ftrack_data: parent = ftrack.Sequence(ftrack_data['Episode']['id']) parent_path.append(parent.getName()) naming = '([a-z]+[0-9]{3})' for item in instance: [sequence_name, shot_name] = re.findall(naming, item.name()) path = list(parent_path) path.append(sequence_name) path.append(item.name()) shot = ftrack.getShot(path) path = self.get_path(shot, context) if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) if os.path.exists(path): msg = 'Audio file already exists. Please delete manually first.' self.log.warning(msg) else: item.sequence().writeAudioToFile(path, item.sourceIn(), item.sourceOut()) asset = shot.createAsset(item.name(), 'audio') version = None for v in asset.getVersions(): if v.getVersion() == context.data('version'): version = v if not version: version = asset.createVersion() version.set('version', value=context.data('version')) version.publish() try: version.createComponent(name='main', path=path) version.createComponent(name='wav', path=path) except: msg = 'Components "main" and "wav" already exists. ' msg += 'Please delete them manually first.' self.log.warning(msg)
def get_shot(self, path): path_str = "/".join(path) try: shot = ftrack.getShot(path) msg = "Found shot with id {} at path \"{}\".".format( shot.getId(), path_str) self.log.info(msg) return shot except: msg = "Didn't find shot with path \"{}\".".format(path_str) self.log.info(msg) return False
def get_shot(self, path): import ftrack path_str = "/".join(path) try: shot = ftrack.getShot(path) msg = "Found shot with id {} at path \"{}\".".format(shot.getId(), path_str) self.log.info(msg) return shot except: msg = "Didn't find shot with path \"{}\".".format(path_str) self.log.info(msg) return False
def create_from_structure(self, parent, structure, projectFolder, tmpFolder): """Create *structure* under *parent*.""" level = structure[0] children = structure[1:] object_type = level['object_type'] for data in level['data']: if object_type == 'sequence': try: new_object = parent.createSequence(data) except Exception: logging.info( 'Sequence {0} already exists. Doing nothing'.format( data)) path = self.getPath(parent, data) new_object = ftrack.getSequence(path) projectFolder = os.path.join(projectFolder, data) if object_type == 'shot': try: new_object = parent.createShot(data) tmpFolder = os.path.join(projectFolder, data) self.createImgFolders(tmpFolder) except Exception: logging.info( 'Shot {0} already exists. Doing nothing'.format(data)) path = self.getPath(parent, data) new_object = ftrack.getShot(path) if object_type == 'task': taskType = ftrack.TaskType(id=data['typeid']) try: new_object = parent.createTask( TASK_TYPE_LOOKUP[data['typeid']], taskType) new_object.set(data) except Exception: logging.info( 'Task {0} already exists. Doing nothing'.format( TASK_TYPE_LOOKUP[data['typeid']])) new_object = '' logging.debug('Created {new_object} on parent {parent}'.format( parent=parent, new_object=new_object)) if children: self.create_from_structure(new_object, children, projectFolder, tmpFolder)
def process(self, instance, context): # skipping if not launched from ftrack if not context.has_data('ftrackData'): return ftrack_data = context.data('ftrackData') task = ftrack.Task(ftrack_data['Task']['id']) parents = task.getParents() item = instance[0] path = [] for p in parents: path.append(p.getName()) # setup parent parent = parents[0] if '--' in item.name(): name_split = item.name().split('--') if len(name_split) == 2: try: copy_path = list(path) copy_path.append(name_split[0]) parent = ftrack.getSequence(copy_path) except: parent = parents[0].createSequence(name_split[0]) if len(name_split) == 3: try: copy_path = list(path) copy_path.append(name_split[0]) parent = ftrack.getSequence(copy_path) except: parent = parents[0].createEpisode(name_split[0]) parents = [parent] + parents try: copy_path.append(name_split[1]) parent = ftrack.getSequence(copy_path) except: parent = parents[0].createSequence(name_split[1]) # creating shot shot_name = item.name() duration = item.sourceOut() - item.sourceIn() duration = abs(int(round((abs(duration) + 1) / item.playbackSpeed()))) if '--' in item.name(): shot_name = item.name().split('--')[-1] shot = None try: shot = parent.createShot(shot_name) path = self.get_path(shot, context) instance.set_data('ftrackId', value=shot.getId()) if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) item.sequence().writeAudioToFile(path, item.timelineIn(), item.timelineOut()) msg = 'Creating new shot with name' msg += ' "%s"' % item.name() self.log.info(msg) instance.data['ftrackShot'] = shot except: path = [] try: for p in reversed(parent.getParents()): path.append(p.getName()) except: pass path.append(parent.getName()) path.append(shot_name) shot = ftrack.getShot(path) instance.set_data('ftrackId', value=shot.getId()) path = self.get_path(shot, context) if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) item.sequence().writeAudioToFile(path, item.timelineIn(), item.timelineOut()) instance.data['ftrackShot'] = shot # assign attributes to shot shot.set('fstart', value=1) shot.set('fend', value=duration) shot.set('handles', value=instance.data['handles']) # generate thumbnail nukeWriter = hiero.core.nuke.ScriptWriter() root_node = hiero.core.nuke.RootNode(1, 1) nukeWriter.addNode(root_node) handles = instance.data['handles'] item.addToNukeScript(script=nukeWriter, firstFrame=1, includeRetimes=True, retimeMethod='Frame', startHandle=handles, endHandle=handles) input_path = item.source().mediaSource().fileinfos()[0].filename() output_path = os.path.splitext(input_path)[0] output_path += '_thumbnail.png' output_path = os.path.join(tempfile.gettempdir(), os.path.basename(output_path)) fmt = hiero.core.Format(150, 100, 1, 'thumbnail') fmt.addToNukeScript(script=nukeWriter) write_node = hiero.core.nuke.WriteNode(output_path) write_node.setKnob('file_type', 'png') nukeWriter.addNode(write_node) script_path = output_path.replace('.png', '.nk') nukeWriter.writeToDisk(script_path) logFileName = output_path.replace('.png', '.log') process = hiero.core.nuke.executeNukeScript(script_path, open(logFileName, 'w')) while process.poll() is None: time.sleep(0.5) if os.path.exists(output_path): self.log.info("Thumbnail rendered successfully!") # creating thumbnails thumb = shot.createThumbnail(output_path) for t in shot.getTasks(): t.set('thumbid', value=thumb.get('entityId')) else: self.log.error("Thumbnail failed to render") # clean up """
def renameandcopytoVFX(self, copypath, FTRACK_SERVER='http://192.168.9.200', FTRACK_APIKEY='b445309f-1c5d-40ac-b68b-3fdfb4f3ccb9', LOGNAME='andyguo', PROJECTNAME='Piggy Bank' ): digitregex = re.compile(r'(\d{3,})') os.environ['FTRACK_SERVER'] = FTRACK_SERVER os.environ['FTRACK_APIKEY'] = FTRACK_APIKEY os.environ['LOGNAME'] = LOGNAME import ftrack try: project = ftrack.getProject(PROJECTNAME) print('== get asset types ==') platetypes = [x for x in ftrack.getAssetTypes() if x.get('name') == 'Plate'] # print(platetypes) print('== get task types ==') tasktypes = [x for x in ftrack.getTaskTypes() if x.get('name') == 'Plate'] # print(tasktypes) except: print('this project not available in ftrack') for j in xrange(len(self._cliplist)): # rename every frame as VFX needs item = self._cliplist[j] duration = int(item['endframe']) - int(item['startframe']) + 1 for i in xrange(duration): # diframe = str(item['startframe'] + i).zfill(m.end() - m.start()) oldname = item['metadata'][i]['filepath'] newname = item['sequence'][0] + '_' + item['shot'][0] + '_plate_' + ('%04d' % (1001 + i)) + \ os.path.splitext(oldname)[-1] try: newname = os.path.join(os.path.dirname(oldname), newname) os.rename(oldname, newname) except: print('something error in rename files') # print(oldname, newname) copyfoldername = os.path.dirname(oldname) if self._shouldrenamefolder: oldfolder = os.path .dirname(oldname) newfolder = os.path.join(os.path.dirname(os.path.dirname(oldname)), ('%04d' % (j + 1)) + '_' + item['sequence'][0] + '_' + item['shot'][0]) # print(oldfolder, newfolder) try: os.rename(oldfolder, newfolder) copyfoldername = newfolder except: print('something error in rename folders') # copy to NAS using rsync cmd = 'rsync -avr --progress %s %s' % (copyfoldername.replace(' ', r'\ '), copypath.replace(' ', '\ ')) print(cmd) terminal = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, bufsize=1) with terminal.stdout: for line in iter(terminal.stdout.readline, b''): print line, terminal.wait() # update ftrack Assetbuild and shot try: print('== update shot info ==') shot = ftrack.getShot([PROJECTNAME, item['sequence'][0], item['shot'][0]]) except: print('no such shot %s_%s' % (item['sequence'][0], item['shot'][0])) break try: assetbuildname = '%s_%s_plate' % (item['sequence'][0], item['shot'][0]) previousvesions = [x for x in ftrack.getShot([PROJECTNAME, 'Asset builds']).getShots() if assetbuildname in x.getName()] # print(previousvesions) print('== check previous versions ==') if len(previousvesions) > 0: # print('already got %d verions' % len(previousvesions)) assetbuildname = '%s_%s_plate_%02d' % (item['sequence'][0], item['shot'][0], len(previousvesions)+1) else: assetbuildname = '%s_%s_plate_01' % (item['sequence'][0], item['shot'][0]) print('== create new assetbuild ==') newassetbuild = project.createAssetBuild(assetbuildname) newassetbuild.set('typeid', tasktypes[0].get('typeid')) temp = {} temp['01_sequence'] = item['sequence'][0] temp['02_shot'] = item['shot'][0] temp['05_s3d'] = item['s3d'] temp['06_metadata'] = str(item['metadata']) temp['03_startframe'] = item['startframe'] temp['04_endframe'] = item['endframe'] newassetbuild.setMeta(temp) print('== create new asset ==') asset = newassetbuild.createAsset(name=assetbuildname, assetType=platetypes[0].get('short')) version = asset.createVersion(comment='uploaded by IOFTRACK') for index, frame in enumerate(item['metadata']): # print(item['sequence'][0] + '_' + item['shot'][0] # + '_plate_' + # ('%04d' % (1001 + index)) + # os.path.splitext(oldname)[-1] # ) version.createComponent(name=(item['sequence'][0] + '_' + item['shot'][0] + '_plate_' + ('%04d' % (1001 + index)) + os.path.splitext(oldname)[-1] ), path=(item['sequence'][0] + '_' + item['shot'][0] + '_plate_' + ('%04d' % (1001 + index)) + os.path.splitext(oldname)[-1] )) asset.publish() try: print('== link asset to shot and link reverse ==') # print('asset', newassetbuild) # print('shot', shot) newassetbuild.addSuccessor(shot) newassetbuild.addPredecessor(shot) except: print('something error in link asset to shot') break newassetbuild.createTask('upload by IO', taskType=[x for x in ftrack.getTaskTypes() if x.get('name') == 'Plate'][0], taskStatus=[y for y in ftrack.getTaskStatuses() if y.get('name') == 'Approved'][0]) try: print('== create thumbnails ==') convertcmd = 'convert %s -size 1280x720 %s' % ( os.path.join(os.path.dirname(item['metadata'][0]['filepath']), (item['sequence'][0] + '_' + item['shot'][0] + '_plate_' + ('%04d' % (1001)) + os.path.splitext(oldname)[-1] )).replace(' ', r'\ '), os.path.join(APP_PATH, assetbuildname+'.jpg').replace(' ', r'\ ')) print(convertcmd) convermessage = subprocess.Popen(convertcmd, shell=True, stdout=subprocess.PIPE).communicate()[0] newassetbuild.createThumbnail(os.path.join(APP_PATH, assetbuildname + '.jpg')) except: print('== something error in creating thumbnails') except: print('something error with creating assetbuild') break
def process(self, instance, context): # skipping if not launched from ftrack if not context.has_data('ftrackData'): return ftrack_data = context.data('ftrackData') task = ftrack.Task(ftrack_data['Task']['id']) parents = task.getParents() item = instance[0] path = [] for p in parents: path.append(p.getName()) # setup parent parent = parents[0] if '--' in item.name(): name_split = item.name().split('--') if len(name_split) == 2: try: copy_path = list(path) copy_path.append(name_split[0]) parent = ftrack.getSequence(copy_path) except: parent = parents[0].createSequence(name_split[0]) if len(name_split) == 3: try: copy_path = list(path) copy_path.append(name_split[0]) parent = ftrack.getSequence(copy_path) except: parent = parents[0].createEpisode(name_split[0]) parents = [parent] + parents try: copy_path.append(name_split[1]) parent = ftrack.getSequence(copy_path) except: parent = parents[0].createSequence(name_split[1]) self.log.info(parent) self.log.info(parents[0]) # creating shot shot_name = item.name() duration = item.sourceOut() - item.sourceIn() + 1 if '--' in item.name(): shot_name = item.name().split('--')[-1] tasks = [] try: shot = parent.createShot(shot_name) shot.set('fstart', value=1) shot.set('fend', value=duration) path = self.get_path(shot, context) instance.set_data('ftrackId', value=shot.getId()) if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) item.sequence().writeAudioToFile(path, item.timelineIn(), item.timelineOut()) msg = 'Creating new shot with name' msg += ' "%s"' % item.name() self.log.info(msg) except: path = [] try: for p in reversed(parent.getParents()): path.append(p.getName()) except: pass path.append(parent.getName()) path.append(shot_name) shot = ftrack.getShot(path) instance.set_data('ftrackId', value=shot.getId()) shot.set('fstart', value=1) shot.set('fend', value=duration) path = self.get_path(shot, context) if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) item.sequence().writeAudioToFile(path, item.timelineIn(), item.timelineOut()) d = os.path.dirname tools_path = d(d(d(d(d(d(inspect.getfile(inspect.currentframe()))))))) exe = os.path.join(tools_path, 'ffmpeg', 'bin', 'ffmpeg.exe') input_path = item.source().mediaSource().fileinfos()[0].filename() ext = os.path.splitext(input_path)[1] output_path = os.path.splitext(input_path)[0] output_path += '_thumbnail.png' output_path = os.path.join(tempfile.gettempdir(), os.path.basename(output_path)) input_cmd = '' fps = item.sequence().framerate().toFloat() if ext == '.mov': arg = ' scale=-1:108' input_cmd = ' -vf' + arg + ' -vframes' + ' 1' else: arg = ' scale=-1:108' if os.path.splitext(input_path)[1] == '.exr': arg += ',lutrgb=r=gammaval(0.45454545):' arg += 'g=gammaval(0.45454545):' arg += 'b=gammaval(0.45454545)' input_cmd = ' -vf' + arg tc = self.frames_to_timecode(item.sourceIn(), fps) cmd = exe + ' -ss '+ tc +' -i "' + input_path + '" ' + input_cmd cmd += ' -y "' + output_path + '"' self.log.info(cmd) subprocess.call(cmd) # creating thumbnails thumb = shot.createThumbnail(output_path) for t in shot.getTasks(): t.set('thumbid', value=thumb.get('entityId')) if os.path.exists(output_path): os.remove(output_path)