Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/local/bin/python
# Yannick Guillerm - Scality
# yannick.guillerm@scality.com
# 04/04/18
import requests
import sys, getopt
import argparse
import os
import shutil
def main(argv):
filepath = ""
format1 = ""
format2 = ""
format3 = ""
format4 = ""
# Parse arguments. File full path and op (upload/download)
parser = argparse.ArgumentParser()
parser.add_argument('--f', help='f help')
parser.add_argument('--f1', help='f1 help')
parser.add_argument('--f2', help='f2 help')
parser.add_argument('--f3', help='f3 help')
parser.add_argument('--f4', help='f4 help')
args = vars(parser.parse_args())
filepath = args['f']
format1 = args['f1']
format2 = args['f2']
format3 = args['f3']
format4 = args['f4']
print filepath
print format1
print format2
print format3
print format4
# Clean transcode destination directory
for root, dirs, files in os.walk('/Users/scality/Documents/StreamingCDN/Transcode'):
for f in files:
os.unlink(os.path.join(root, f))
# Clean content of Amazon bucket
print "Deleting Amzon bucket objects ..."
Command = 'aws s3api delete-object --bucket nab-media-1 --key nab-amazon-media/San_Francisco_Timelapse_' + format1 + '.mp4'
print Command
#os.system(Command)
Command = 'aws s3api delete-object --bucket nab-media-1 --key nab-amazon-media/San_Francisco_Timelapse_' + format2 + '.mp4'
print Command
#os.system(Command)
Command = 'aws s3api delete-object --bucket nab-media-1 --key nab-amazon-media/San_Francisco_Timelapse_' + format3 + '.mp4'
print Command
#os.system(Command)
Command = 'aws s3api delete-object --bucket nab-media-1 --key nab-amazon-media/San_Francisco_Timelapse_' + format4 + '.mp4'
print Command
#os.system(Command)
print "Amazon bucket oject deleted"
# Transcode to all formats and save results to /Users/scality/Documents/StreamingCDN/Transcode/
Command = 'ffmpeg -i ' + filepath + ' -s ' + format1 + ' -b 1000k -strict -2 /Users/scality/Documents/StreamingCDN/Transcode/San_Francisco_Timelapse_' + format1 + '.mp4'
print Command
os.system(Command)
Command = 'ffmpeg -i ' + filepath + ' -s ' + format2 + ' -b 1000k -strict -2 /Users/scality/Documents/StreamingCDN/Transcode/San_Francisco_Timelapse_' + format2 + '.mp4'
print Command
os.system(Command)
Command = 'ffmpeg -i ' + filepath + ' -s ' + format3 + ' -b 1000k -strict -2 /Users/scality/Documents/StreamingCDN/Transcode/San_Francisco_Timelapse_' + format3 + '.mp4'
print Command
os.system(Command)
Command = 'ffmpeg -i ' + filepath + ' -s ' + format4 + ' -b 1000k -strict -2 /Users/scality/Documents/StreamingCDN/Transcode/San_Francisco_Timelapse_' + format4 + '.mp4'
print Command
os.system(Command)
# Upload all transcoded files to S3 in the Zenko Amazon bucket (which will be replicated to the Azure bucket)
# PUT file format1
Command = 's3cmd put ' + '/Users/scality/Documents/StreamingCDN/Transcode/San_Francisco_Timelapse_' + format1 + '.mp4' + ' s3://nab-amazon-media'
print Command
os.system(Command)
# Grant public read access
Command = 'aws s3api put-object-acl --bucket nab-media-1 --key nab-amazon-media/San_Francisco_Timelapse_' + format1 + '.mp4 --acl public-read'
print Command
os.system(Command)
# PUT file format2
Command = 's3cmd put ' + '/Users/scality/Documents/StreamingCDN/Transcode/San_Francisco_Timelapse_' + format2 + '.mp4' + ' s3://nab-amazon-media'
print Command
os.system(Command)
# Grant public read access
Command = 'aws s3api put-object-acl --bucket nab-media-1 --key nab-amazon-media/San_Francisco_Timelapse_' + format2 + '.mp4 --acl public-read'
print Command
os.system(Command)
# PUT file format3
Command = 's3cmd put ' + '/Users/scality/Documents/StreamingCDN/Transcode/San_Francisco_Timelapse_' + format3 + '.mp4' + ' s3://nab-amazon-media'
print Command
os.system(Command)
# Grant public read access
Command = 'aws s3api put-object-acl --bucket nab-media-1 --key nab-amazon-media/San_Francisco_Timelapse_' + format3 + '.mp4 --acl public-read'
print Command
os.system(Command)
# PUT file format4
Command = 's3cmd put ' + '/Users/scality/Documents/StreamingCDN/Transcode/San_Francisco_Timelapse_' + format4 + '.mp4' + ' s3://nab-amazon-media'
print Command
os.system(Command)
# Grant public read access
Command = 'aws s3api put-object-acl --bucket nab-media-1 --key nab-amazon-media/San_Francisco_Timelapse_' + format4 + '.mp4 --acl public-read'
print Command
os.system(Command)
# ZENKO will automatically replicate objects fron Amazon to Azure via a replication policy
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment