· 4 years ago · Aug 14, 2021, 09:14 AM
1import uuid
2import argparse
3import os
4import logging
5import urllib3
6from datetime import datetime
7from minio import Minio
8
9MINIO_URL = 'storage.kuroko.sony-asia.com:443'
10MINIO_ACCESS_KEY = "dsxauto"
11MINIO_SECRET_KEY = "soem1auto"
12MINIO_BUCKET = "dsxauto"
13
14
15UPLOAD_METADATA_REQUIREMENT = {
16 'x-amz-storage-class': 'REDUCED_REDUNDANCY'
17}
18
19def create_jobid():
20 jobid = str(uuid.uuid4())
21 return jobid
22
23class UploadHandler():
24 def __init__(self):
25 self.minioClient = Minio(
26 endpoint = MINIO_URL,
27 access_key = MINIO_ACCESS_KEY,
28 secret_key = MINIO_SECRET_KEY,
29 secure = True,
30 http_client = urllib3.PoolManager(
31 cert_reqs = "CERT_REQUIRED"
32 )
33 )
34
35 def upload_file_to_minio(local_minio_upload_location, minio_upload_location):
36 minioClient.fput_object(local_minio_upload_location, minio_upload_location, MINIO_BUCKET)
37
38
39
40if __name__ == "__main__":
41 logging.basicConfig(format='%(asctime)s | %(module)15s | %(levelname)9s | %(message)s', level=logging.INFO)
42
43 parser = argparse.ArgumentParser(description='Sending Video for Judgement')
44 parser.add_argument("-i", "--input", type=str, required=True, help='Input dir of video for judgement')
45 parser.add_argument("-o", "--output", type=str, required=True, help='Output dir of video for judgement')
46 args = parser.parse_args()
47
48 handler = UploadHandler()
49
50 job_id = create_jobid()
51 logging.info("job_id :{}".format(job_id))
52
53 # MAYBE CHANGE NAME OF PATH
54 minio_upload_location = datetime.today().strftime('%Y%m%d%H%M%S') + '_' + str(job_id[0:8])
55 logging.info("path :{}".format(minio_upload_location))
56
57 # Create subdirectory in output folder
58 if os.path.exists(args.output):
59 logging.info("Folder location exists")
60 os.makedirs(os.path.join(args.output,minio_upload_location))
61 logging.info(os.path.join(args.output,minio_upload_location))
62
63 else:
64 raise Exception("Folder does not exist")
65
66 # inside result create a folder called YYYYMMDDHHMMSS_JOBID[0:8] and then save the videos
67 # Loop through input directory for video files
68 for filename in os.listdir(args.input):
69 if filename.endswith(".mp4"):
70 print('start')
71 handler.upload_file_to_minio(os.path.join(args.input,filename), f'result/{minio_upload_location}/{filename}')
72 print(minio_upload_location)
73 print(os.path.join(args.input, filename))
74 logging.info("Video File Found: " + os.path.join(args.input, filename))
75 continue
76 else:
77 logging.info("No other video files")
78 continue
79