Example #1
0
def upload(s3,bucketName,path):
  log = t_logger.getLogger(__name__)
  bucket = s3.create_bucket(bucketName)
  log.info('Bucket %s is OK',bucketName)

  log.debug('Starting trasfer of %s',path)
  pathName = os.path.basename(path)
  log.debug('S3 key will be %s', pathName)

  storedData = Key(bucket)
  storedData.key = pathName
  storedData.set_contents_from_filename(path)

  log.debug('S3 trasfer of %s completed',path)
def upload(s3, bucketName, path):
    log = t_logger.getLogger(__name__)
    bucket = s3.create_bucket(bucketName)
    log.info('Bucket %s is OK', bucketName)

    log.debug('Starting trasfer of %s', path)
    pathName = os.path.basename(path)
    log.debug('S3 key will be %s', pathName)

    storedData = Key(bucket)
    storedData.key = pathName
    storedData.set_contents_from_filename(path)

    log.debug('S3 trasfer of %s completed', path)
Example #3
0
def transcodeFile(
    originalFilename,
    sourcePath,
    destPath,
    preserveDate=True,
    transcodingString='''gst-launch filesrc location=$src ! decodebin2 name=d d. ! queue ! \
  ffmpegcolorspace ! videoscale ! video/x-raw-rgb ! deinterlace ! ffmpegcolorspace ! \
  x264enc profile=1 ! mp4mux name=mux ! filesink location=$dest d. ! queue ! audioconvert ! audioresample ! faac ! mux.'''
):
    #transcodingString='''gst-launch-1.0 filesrc location=$src ! decodebin name=d \
    #d. ! queue ! videoconvert ! videoscale ! video/x-raw ! \
    #videoconvert ! deinterlace ! x264enc ! video/x-h264,profile=main ! h264parse \
    #! mp4mux name=mux ! filesink location=$dest d. ! queue ! audioconvert ! \
    #audioresample ! faac ! mux.''') // lamemp3enc

    # transcode using GStreamer
    log = t_logger.getLogger(__name__)
    log.debug('current file is: %s', originalFilename)
    sourceFile = sourcePath + os.sep + originalFilename

    videoType = mimetypes.guess_type(sourceFile)
    if (videoType[0] is None or string.find(videoType[0], "video") < 0):
        log.debug('Not a video file')
        return originalFilename, sourceFile

    fileName, fileExtension = os.path.splitext(originalFilename)
    # Start transcoding
    newFilePath = destPath + os.sep + fileName + ".mp4"
    log.debug('new file will be: %s', newFilePath)

    transcodingTemplate = string.Template(transcodingString)
    pipeline = transcodingTemplate.substitute(src='"' + sourceFile + '"',
                                              dest='"' + newFilePath + '"')
    log.warn('template %s', pipeline)

    # calling a shell GST process
    result = subprocess.call(shlex.split(pipeline))

    log.info(('OK' if result == 0 else 'NO') + ' transcoding %s', newFilePath)
    if result != 0:
        raise RuntimeError('Unable to transcode file')

    # fixing file timestamp
    if (preserveDate) is True:
        log.info("Fixing timestamp for %s ", newFilePath)
        file_timestamp.copyFileTimestamp(sourceFile, newFilePath)

    return fileName + '.mp4', newFilePath
def transcodeFile (originalFilename,sourcePath,destPath, preserveDate=True,
  transcodingString='''gst-launch filesrc location=$src ! decodebin2 name=d d. ! queue ! \
  ffmpegcolorspace ! videoscale ! video/x-raw-rgb ! deinterlace ! ffmpegcolorspace ! \
  x264enc profile=1 ! mp4mux name=mux ! filesink location=$dest d. ! queue ! audioconvert ! audioresample ! faac ! mux.'''):
  #transcodingString='''gst-launch-1.0 filesrc location=$src ! decodebin name=d \
  #d. ! queue ! videoconvert ! videoscale ! video/x-raw ! \
  #videoconvert ! deinterlace ! x264enc ! video/x-h264,profile=main ! h264parse \
  #! mp4mux name=mux ! filesink location=$dest d. ! queue ! audioconvert ! \
  #audioresample ! faac ! mux.''') // lamemp3enc
  
  # transcode using GStreamer
  log = t_logger.getLogger(__name__)
  log.debug('current file is: %s', originalFilename)
  sourceFile = sourcePath + os.sep + originalFilename

  videoType = mimetypes.guess_type(sourceFile)
  if ( videoType[0] is None or string.find( videoType[0],"video" ) < 0):
    log.debug('Not a video file')
    return originalFilename, sourceFile

  fileName, fileExtension = os.path.splitext(originalFilename)
  # Start transcoding
  newFilePath = destPath + os.sep + fileName + ".mp4"
  log.debug('new file will be: %s', newFilePath)

  transcodingTemplate = string.Template(transcodingString)
  pipeline = transcodingTemplate.substitute(src='"'+sourceFile+'"',dest='"'+newFilePath+'"')
  log.warn('template %s', pipeline )

  # calling a shell GST process
  result = subprocess.call( shlex.split(pipeline) )

  log.info( ('OK' if result == 0 else 'NO')+' transcoding %s',newFilePath)
  if result != 0:
    raise RuntimeError('Unable to transcode file')
  
  # fixing file timestamp
  if (preserveDate) is True:
    log.info("Fixing timestamp for %s ", newFilePath)
    file_timestamp.copyFileTimestamp(sourceFile,newFilePath)
  
  return fileName + '.mp4', newFilePath
Example #5
0
def connect(ftpparams):
  ftp = ftplib.FTP()
  log= t_logger.getLogger(__name__)

  ftp.connect(ftpparams.host, ftpparams.port)
  if (hasattr(ftpparams,'username')):
    ftp.login(ftpparams.username, ftpparams.password)
  if (hasattr(ftpparams,'basedir')):
    ftp.cwd(ftpparams.basedir)
  
  if (hasattr(ftpparams,'path')):
    path = ftpparams.path
    try:
      ftp.mkd(path)
    except ftplib.error_perm, resp:
      if str(resp) == '550 ' + path + ': File exists':
        log.debug('Directory already exists')
      else:
        raise
    ftp.cwd(ftpparams.basedir+path)
Example #6
0
def parse ():
  parser = argparse.ArgumentParser(description='A simple transcoder and uploader software')
  parser.add_argument('-in', '--input', help='input folder',required=True)
  parser.add_argument('-out', '--output', help='optional output folder')
  parser.add_argument('-i', '--inplace', help='processing inplace. Input folder is output folder', action='store_const', const=True)
  parser.add_argument('-r', '--removelocal', help='remove created files after execution', dest='remove', action='store_const', const=True)

  parser.add_argument('-t','--transcode',help='whether to transcode or not', action='store_const', const=True)
  parser.add_argument('-up','--upload',help='whether to upload or not', action='store_const', const=True)
  parser.add_argument('-via', help='upload with [ftp] or [s3]', choices=['ftp', 's3'], default='ftp')

  # Misc
  parser.add_argument('-nopres','--nopreserve',help='do not preserve original dates in resulting files', action='store_const', const=False)
  parser.add_argument('-ctree','--createtree',help='recreate source folder tree in dest folder', action='store_const', const=True)

  # FTP params
  parser.add_argument('-ftphost', help='FTP host', dest='host')
  parser.add_argument('-ftpport', help='FTP port', default=21, type=int, dest='port')
  parser.add_argument('-ftpusername', help='FTP username', dest='username')
  parser.add_argument('-ftppassword', help='FTP password', dest='password')
  parser.add_argument('-ftpbasedir', help='FTP base directory to connect to', dest='basedir', default='/')
  parser.add_argument('-ftppath', help='FTP destination path to be created', dest='path')
 
  # S3 params
  parser.add_argument('-s3keyid', help='Your AWS Access Key ID')
  parser.add_argument('-s3secretkey', help='Your AWS Secret Access Key')
  parser.add_argument('-s3bucket', help='S3 bucket name', dest='bucket')
  
  # external file paramters
  parser.add_argument('-f','--externalfile', help='whether parameters should be taken from an external file', dest='file', action='store_const', const=True)
  parser.add_argument('-extpath','--externalfilepath', help='path of external file contining parameters', dest='extpath')

  log = t_logger.getLogger(__name__)
  log.debug('Args parsed succesfully')
  
  return parser.parse_args()
def connect(s3params):
    log = t_logger.getLogger(__name__)
    conn = S3Connection(s3params.s3keyid, s3params.s3secretkey)
    return conn
Example #8
0
def upload(ftp,fileName,filePath):
  log = t_logger.getLogger(__name__)
  log.info('FTP upload of %s started @ %s:%s',fileName,ftp.host,ftp.port)
  ftp.storbinary("STOR " + fileName, open(filePath, "rb"),1024)
  log.info('FTP trasfer of %s completed',fileName)
Example #9
0
def connect(s3params):
  log = t_logger.getLogger(__name__)
  conn = S3Connection(s3params.s3keyid, s3params.s3secretkey)
  return conn