Snippets

Lucas Correia API Example - Reviewable shot

Created by Lucas Correia

File test_reviewable_shot.py Added

  • Ignore whitespace
  • Hide word diff
+# :coding: utf-8
+# :copyright: Copyright (c) 2018 ftrack
+'''Create a reviewable version and set the version's thumbnail as shot thumbnail.'''
+import ftrack_api
+import time
+
+FILE_PATH = '/Users/lucas/Downloads/Frame count.mp4'
+ASSET_NAME = 'Test asset'
+
+session = ftrack_api.Session()
+
+# Get a random shot and create a new AssetVersion
+shot = session.query('Shot').first()
+asset_type = session.query('AssetType where name is "Upload"').one()
+asset = session.create('Asset', {
+    'name': ASSET_NAME,
+    'type': asset_type,
+    'parent': shot
+})
+version = session.create('AssetVersion', { 'asset': asset })
+session.commit()
+
+job = version.encode_media(FILE_PATH)
+
+# Wait for job completion
+while job['status'] == 'running':
+    print 'Waiting for job completion'
+    time.sleep(5)
+    job = session.query('select status from Job where id is "{}"'.format(job['id'])).one()
+
+# Set shot thumbnail
+shot['thumbnail_id'] = version['thumbnail_id']
+session.commit()
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.