-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimoto_client
executable file
·57 lines (43 loc) · 1.61 KB
/
minimoto_client
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
#!/usr/bin/python3
import os
import sys
import boto3
import random
import string
import subprocess
from minimoto_constants import *
RANDOMWORD_LENGTH = 30
def randomword():
return "".join(random.choice(
string.ascii_lowercase + string.ascii_uppercase)
for i in range(RANDOMWORD_LENGTH))
def main():
if len(sys.argv) < 4:
print("Not enough arguments")
exit(1)
images_dir = os.path.normpath(sys.argv[1])
s3_dirname = randomword()
input_bucket_name = sys.argv[2]
output_bucket_name = sys.argv[3]
wait_flag = False
if len(sys.argv) == 5 and sys.argv[4] == "--wait":
wait_flag = True
print("Getting boto3 clients and resources")
s3 = boto3.resource("s3", region_name="ap-southeast-2")
sqs = boto3.resource("sqs", region_name="ap-southeast-2")
print("Uploading images in {} to input bucket at {}".format(
images_dir, s3_dirname))
subprocess.run(["aws", "--region", "ap-southeast-2", "s3", "sync",
images_dir,
"s3://%s/%s" % (input_bucket_name, s3_dirname)])
print("Sending message to transcoding queue")
queue = sqs.get_queue_by_name(QueueName=TRANSCODING_REQUESTS_QUEUE_NAME)
queue.send_message(MessageBody=s3_dirname)
if wait_flag:
print("Waiting for transcoding to complete...")
output_obj = s3.Object(output_bucket_name, s3_dirname + ".mp4")
output_obj.wait_until_exists()
print("You'll find the output in s3://{bucket_name}/{s3_dirname}.mp4"
.format(bucket_name=output_bucket_name, s3_dirname=s3_dirname))
if __name__ == "__main__":
main()