-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaviary_media_api_upload_chunked.py
66 lines (50 loc) · 1.95 KB
/
aviary_media_api_upload_chunked.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
##############################################################################################
# desc: connect to the Aviary API and test media file upload
# exploritory / proof-of-concept code
# usage: python3 aviary_media_api_upload_chunked.py --server ${aviary_server_name} --input input.sample.csv
# license: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
# date: June 15, 2022
##############################################################################################
# Proof-of-concept only
from getpass import getpass
from requests_toolbelt import MultipartEncoder
from random import uniform
from time import sleep
from urllib.parse import urljoin
import argparse
import csv
import json
from aviary import api as aviaryApi
#
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--server', required=True, help='Servername.')
parser.add_argument('--input', required=True, help='Input CSV file describing the media to upload to Aviary')
return parser.parse_args()
#
def process(args, session):
with open(args.input, 'r', encoding="utf-8", newline='') as input_file:
input_csv = csv.DictReader(input_file)
for item in input_csv:
print(item['title'])
aviaryApi.put_media_item(args, session, item)
# aviaryApi.upload_based_on_avp_documentation(args, session, item)
# the input file DictReader returns an object similar to the following
# media_item_90m = {
# "resource_id" : "75072",
# "filepath" : "testsrc_7200.mp4",
# "access" : "true",
# "is_360" : "false",
# "title" : "ztestz $ title",
# "display_name" : "ztestz $ title"
# }
# put_media_item(args, session, media_item_90m)
#
def main():
args = parse_args()
username = input('Username:')
password = getpass('Password:')
session = aviaryApi.init_session(args, username, password)
process(args, session)
if __name__ == "__main__":
main()