-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_01_clip_metadata.py
executable file
·75 lines (57 loc) · 2.43 KB
/
sample_01_clip_metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""
__copyright__ = "Copyright 2023, Pomfort GmbH"
__license__ = "MIT"
__email__ = "[email protected]"
"""
#
# ShotHub API sample script #1: Document a shooting day with per-clip metadata
#
# (c) 2023 Pomfort GmbH, https://pomfort.com/
#
# To use, enter your script credentials into the accompanying file 'shothub_api_config.py', enter your project ID and
# an optional folder ID in the configuration section below, and make sure that the script has access to the selected
# project.
#
# No pip modules are required.
import shothub_api_utils
import shothub_api_config
import os
# insert your project ID here
project_id = '643533041b92c40aa318d8db'
# if your project uses a folder for every shooting day, enter the folder ID for the shooting day you want to export here
# otherwise set it to None.
#
# If both this and shooting_day are set to None, data be downloaded for all clips in the project, regardless of shooting
# day.
folder_id = None
# if your project uses the "Shooting Day" metadata field, enter the value for the shooting day you want to export here
shooting_day = None
output_dir = f'output/metadata'
output_file = f'{output_dir}/{project_id}.csv'
# customize which fields will be included in the csv here
csv_fields = ['assetType', 'type', 'name', 'shotId', 'episode', 'scene', 'shot', 'take']
def main():
global folder_id
shothub_api_utils.login()
os.makedirs(output_dir, exist_ok=True)
if folder_id is None:
folder_id = shothub_api_utils.get_project_root_folder(project_id)
# now we can start fetching the assets
page_counter = 0
page_size = 50
page_count = 1 # will be updated after the first request
assets = []
while page_counter < page_count:
asset_response = shothub_api_utils.request_get(f'{shothub_api_config.base_url}/v1.0/assets'
f'?folderId={folder_id}'
f'&page={page_counter}'
f'&pageSize={page_size}',
headers=shothub_api_utils.get_login_header())
for asset in asset_response.json():
if shooting_day is None or asset['shootingDay'] == shooting_day:
assets.append(asset)
page_counter += 1
with open(output_file, 'w') as f:
shothub_api_utils.write_csv(f, assets, csv_fields)
main()