forked from cvisionai/tator-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_media.py
48 lines (40 loc) · 1.44 KB
/
upload_media.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
#!/usr/bin/env python
""" This example shows how to upload a media file.
"""
import logging
import sys
import time
import tator
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logger = logging.getLogger(__name__)
if __name__ == "__main__":
# Create a parser that includes path to media file.
parser = tator.get_parser()
parser.add_argument("--type-id", help="Media type ID for upload.", required=True, type=int)
parser.add_argument(
"--chunk-size",
help="The maximum chunk size for uploads.",
required=False,
type=int,
default=10 * 1024 * 1024,
)
parser.add_argument("--media-path", help="Path to media file.", required=True)
args = parser.parse_args()
# Create the api.
tator_api = tator.get_api(args.host, args.token)
# Upload the media.
for progress, response in tator.util.upload_media(
api=tator_api, type_id=args.type_id, path=args.media_path, chunk_size=args.chunk_size
):
logger.info(f"Upload progress: {progress}%")
logger.info(response.message)
# Take a look at transcode progress, wait until complete.
project = tator_api.get_media_type(args.type_id).project
while True:
transcode = tator_api.get_transcode(response.id)
status = transcode.job.status.lower()
if status == "succeeded":
break
elif status == "failed":
raise ValueError("Upload failed!")
time.sleep(10)