Esempio n. 1
0
    def _file_metadata(self, an_uri, file_descr):
        """Get metadata about the actual file and add it to the FileDescription
        """
        def convert_time(st_time):
            dt = datetime.fromtimestamp(stat.st_mtime)
            return dt.isoformat()

        stat = os.stat(an_uri)
        if file_descr.metadata is None:
            file_descr.metadata = {}
        file_descr.metadata['pw_name'] = MetaDataValue(type=MetaDataType.STRING, string_value=pwd.getpwuid(stat.st_uid).pw_name)
        file_descr.metadata['gr_name'] = MetaDataValue(type=MetaDataType.STRING, string_value=grp.getgrgid(stat.st_gid).gr_name)
        file_descr.metadata['st_size'] = MetaDataValue(type=MetaDataType.INT, int_value=stat.st_size)

        file_descr.metadata['st_ctime'] = MetaDataValue(type=MetaDataType.STRING, string_value=convert_time(stat.st_ctime))
        file_descr.metadata['st_mtime'] = MetaDataValue(type=MetaDataType.STRING, string_value=convert_time(stat.st_mtime))

        #TODO:
        try:
            from damn_at.repository import Repository
            repo = Repository('/home/sueastside/dev/DAMN/damn-test-files')

            repo.get_meta_data(an_uri, file_descr)
        except Exception as repo_exception:
            logger.debug("Unable to extract repository information: %s", str(repo_exception))
Esempio n. 2
0
def get_supported_formats():
    try:
        pro = subprocess.Popen(['ffmpeg', '-formats'], stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
        out, err = pro.communicate()
        if pro.returncode != 0:
            logger.debug(
                'GetAcoustIDTypes failed with error code %d! '
                % pro.returncode,
                out,
                err
            )
            return []
    except OSError as oserror:
        logger.debug('GetAcoustIDTypes failed! %s', oserror)
        return []
    extensions = [
        line.split()[1] for line in out.decode('utf-8').split('\n')[4:]
        if len(line.split()) > 1]

    mimes = []
    for ext in extensions:
        mime = mimetypes.guess_type('file.' + ext, False)[0]
        if mime and mime.startswith('audio/'):
            mimes.append(mime)
    return mimes
Esempio n. 3
0
    def _file_metadata(self, an_uri, file_descr):
        """Get metadata about the actual file and add it to the FileDescription
        """
        def convert_time(st_time):
            dt = datetime.fromtimestamp(stat.st_mtime)
            return dt.isoformat()

        stat = os.stat(an_uri)
        if file_descr.metadata is None:
            file_descr.metadata = {}
        file_descr.metadata['pw_name'] = MetaDataValue(
            type=MetaDataType.STRING,
            string_value=pwd.getpwuid(stat.st_uid).pw_name)
        file_descr.metadata['gr_name'] = MetaDataValue(
            type=MetaDataType.STRING,
            string_value=grp.getgrgid(stat.st_gid).gr_name)
        file_descr.metadata['st_size'] = MetaDataValue(type=MetaDataType.INT,
                                                       int_value=stat.st_size)

        file_descr.metadata['st_ctime'] = MetaDataValue(
            type=MetaDataType.STRING, string_value=convert_time(stat.st_ctime))
        file_descr.metadata['st_mtime'] = MetaDataValue(
            type=MetaDataType.STRING, string_value=convert_time(stat.st_mtime))

        #TODO:
        try:
            from damn_at.repository import Repository
            repo = Repository('/home/sueastside/dev/DAMN/damn-test-files')

            repo.get_meta_data(an_uri, file_descr)
        except Exception as repo_exception:
            logger.debug("Unable to extract repository information: %s",
                         str(repo_exception))
Esempio n. 4
0
 def analyze(self, an_uri):
     stdoutdata, stderrdata, returncode = run_blender(an_uri, script_path(__file__))
     
     if returncode != 0: 
         raise AnalyzerException('BlendAnalyzer failed with %s'%(returncode))
     
     logger.debug(stdoutdata)
     logger.debug(stderrdata)
     
     data = str(stdoutdata).split('-**-')[1].replace('\n', '').replace('\r', '').replace("b'", '').replace("'", '')
     data = binascii.unhexlify(data)
     
     file_descr = DeserializeThriftMsg(FileDescription(), data, TBinaryProtocol.TBinaryProtocol)
     
     return file_descr
Esempio n. 5
0
def extract_feature(ex, in_file, out_file, conf_file=''):
    """Extract feature using 'ex' extractor and stores it to 'out_file'"""

    try:
        pro = subprocess.Popen([ex, in_file, out_file, conf_file],
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
        err, out = pro.communicate()
        if pro.returncode != 0:
            print(
                "FeatureExtractor failed with error code %d! " %
                pro.returncode, out, err)
        else:
            logger.debug("Extracting audio features: \n%s",
                         out.decode("utf-8"))
    except OSError as e:
        print(('E: Feature Extraction failed %s with error %s' % (in_file, e)))
 def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options):
     path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options)
     abs_file_path = os.path.join(dest_path, path_template)
     template = Template(path_template+'__${angles}')
     
     angles = [0.0, 0.1, 0.5]
     
     width = options['size'][0] * options['footage']
     height = options['size'][1] * (options['frames']/options['footage'])
       
     angles = []
     file_paths = []
     for angle in range(0, 628, 628/12):
         angle = angle/100.0
         file_path = template.safe_substitute(angles=angle)
         file_paths.append(file_path)
         angles.append(angle)
         
     if asset_id.mimetype == 'application/x-blender.mesh':
         datatype = 'mesh' 
     elif asset_id.mimetype == 'application/x-blender.group':
         datatype = 'group' 
     else:
         datatype = 'object' 
         
     arguments = ['--', datatype, asset_id.subname, os.path.join(dest_path, template.safe_substitute())]
     arguments.extend(map(str, angles))
     arguments.append('--format=PNG')#TODO
     arguments.append('--camera_type=PERSPECTIVE')
     arguments.append('--width='+str(options['size'][0]))
     arguments.append('--height='+str(options['size'][1]))
     
     script = os.path.join(os.path.dirname(__file__), '../render/b-script-transcoderblenderrender.py')
     
     logger.debug(abs_file_path)
         
     stdoutdata, stderrdata, returncode = run_blender(file_descr.file.filename, script, arguments)
     
     logger.debug(stdoutdata)
     logger.debug(stderrdata)
     logger.debug(returncode)
     #print(returncode) #Todo: check return code
     
     sprite = Image.new('RGB', (width, height))
     for i, file_path in enumerate(file_paths):
         path = os.path.join(dest_path, file_path)
         tile = Image.open(path)
         x = (i%options['footage'])*options['size'][0]
         y = (i/options['footage'])*options['size'][1]
         sprite.paste(tile, (x,y))
     
     #sprite.show()    
     sprite.save(abs_file_path)
     
     return [path_template]
Esempio n. 7
0
def get_sox_types():
    """Extract all possible formats for the audio file and store their mime
    types"""
    try:
        pro = subprocess.Popen(['sox', '-h'],
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
        out, err = pro.communicate()
        if pro.returncode != 0:
            logger.debug(
                "GetSoxTypes failed with error code %d! " % (pro.returncode),
                out, err)
            return []
    except OSError as oserror:
        logger.debug("GetSoxTypes failed! %s", oserror)
        return []

    match = re.search(r'AUDIO FILE FORMATS:(.*)PLAYLIST FORMATS',
                      out.decode("utf-8"), re.DOTALL)
    if not match:
        logger.debug("GetSoxTypes failed to parse output! %s %s", out, err)
        return []

    extensions = match.group(1).strip().split(' ')
    mimes = []
    for ext in extensions:
        mime = mimetypes.guess_type('file.' + ext, False)[0]
        if mime and mime.startswith('audio/'):
            mimes.append(mime)
    return mimes
    def transcode(self, dest_path, file_descr, asset_id, target_mimetype,
                  **options):

        path_template = expand_path_template(target_mimetype.template,
                                             target_mimetype.mimetype,
                                             asset_id, **options)
        path_template = os.path.join(dest_path, path_template)

        arguments = [
            '--', file_descr.file.filename, asset_id.subname, path_template
        ]
        arguments.append('--format=PNG')  #TODO
        arguments.append('--width=' + str(options['size'][0]))
        arguments.append('--height=' + str(options['size'][1]))

        stdoutdata, stderrdata, returncode = run_blender(
            os.path.join(os.path.dirname(__file__),
                         'BlenderMaterialPreviewScenes.blend'),
            script_path(__file__), arguments)

        logger.debug(stdoutdata)
        logger.debug(stderrdata)
        logger.debug(returncode)
        #print(returncode) #Todo: check return code

        return path_template
Esempio n. 9
0
def get_sox_types():
    '''Extract all possible formats for the audio file and store their mime
    types'''
    try:
        pro = subprocess.Popen(['sox', '-h'], stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
        out, err = pro.communicate()
        if pro.returncode != 0:
            logger.debug(
                "GetSoxTypes failed with error code %d! " % (pro.returncode),
                out,
                err
            )
            return []
    except OSError as oserror:
        logger.debug("GetSoxTypes failed! %s", oserror)
        return []

    match = re.search(r'AUDIO FILE FORMATS:(.*)PLAYLIST FORMATS',
                      out, re.DOTALL)
    if not match:
        logger.debug("GetSoxTypes failed to parse output! %s %s", out, err)
        return []

    extensions = match.group(1).strip().split(' ')
    mimes = []
    for ext in extensions:
        mime = mimetypes.guess_type('file.'+ext, False)[0]
        if mime and mime.startswith('audio/'): mimes.append(mime)
    return mimes
Esempio n. 10
0
def get_assimp_types():
    """
    Extract all possible formats and store their mime types
    """
    try:
        pro = subprocess.Popen(['assimp', 'listext'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
        out, err = pro.communicate()
        if pro.returncode != 0:
            logger.debug("'assimp listext' failed with error code %d! "%(pro.returncode),
                    out, err)
            return []
    except OSError as oserror:
        logger.debug("'assimp listext' failed! %s", oserror)
        return []

    extensions = out.split(';')
    mimes = []
    for ext in extensions:
        mime = mimetypes.guess_type('file.'+ext, False)[0]
        print ext, mime
        mimes.append(mime)
    return mimes
 def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options):
     
     path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options)
     path_template = os.path.join(dest_path, path_template)
         
     arguments = ['--', asset_id.subname, path_template]
         
     stdoutdata, stderrdata, returncode = run_blender(file_descr.file.filename, script_path(__file__), arguments)
     
     logger.debug(stdoutdata)
     logger.debug(stderrdata)
     logger.debug(returncode)
     #print(returncode) #Todo: check return code
     
     return path_template
    def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options):

        path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options)
        path_template = os.path.join(dest_path, path_template)

        arguments = ["--", asset_id.subname, path_template]
        arguments.append("--format=PNG")  # TODO
        arguments.append("--width=" + str(options["size"][0]))
        arguments.append("--height=" + str(options["size"][1]))

        stdoutdata, stderrdata, returncode = run_blender(file_descr.file.filename, script_path(__file__), arguments)

        logger.debug(stdoutdata)
        logger.debug(stderrdata)
        logger.debug(returncode)
        # print(returncode) #Todo: check return code

        return path_template
 def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options):
     
     path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options)
     path_template = os.path.join(dest_path, path_template)
         
     arguments = ['--', file_descr.file.filename, asset_id.subname, path_template]
     arguments.append('--format=PNG')#TODO
     arguments.append('--width='+str(options['size'][0]))
     arguments.append('--height='+str(options['size'][1]))
         
     stdoutdata, stderrdata, returncode = run_blender(os.path.join(os.path.dirname(__file__), 'BlenderMaterialPreviewScenes.blend'), script_path(__file__), arguments)
     
     logger.debug(stdoutdata)
     logger.debug(stderrdata)
     logger.debug(returncode)
     #print(returncode) #Todo: check return code
     
     return path_template
Esempio n. 14
0
    def transcode(self, dest_path, file_descr, asset_id, target_mimetype,
                  **options):
        angles = options['angles']
        del options['angles']

        path_template = expand_path_template(target_mimetype.template,
                                             target_mimetype.mimetype,
                                             asset_id, **options)
        path_template = os.path.join(dest_path, path_template)

        file_paths = []
        for angle in angles:
            opts = dict(options)
            opts['angles'] = angle
            file_path = expand_path_template(target_mimetype.template,
                                             target_mimetype.mimetype,
                                             asset_id, **opts)
            file_paths.append(file_path)

        if asset_id.mimetype == 'application/x-blender.mesh':
            datatype = 'mesh'
        elif asset_id.mimetype == 'application/x-blender.group':
            datatype = 'group'
        else:
            datatype = 'object'

        arguments = ['--', datatype, asset_id.subname, path_template]
        arguments.extend(list(map(str, angles)))
        arguments.append('--format=PNG')  # TODO
        arguments.append('--camera_type=PERSPECTIVE')
        arguments.append('--width=' + str(options['size'][0]))
        arguments.append('--height=' + str(options['size'][1]))

        stdoutdata, stderrdata, returncode = run_blender(
            file_descr.file.filename, script_path(__file__), arguments)

        logger.debug(stdoutdata)
        logger.debug(stderrdata)
        logger.debug(returncode)
        # print(returncode) #Todo: check return code

        return file_paths
 def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options):
     angles = options['angles']
     del options['angles']
     
     path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options)
     path_template = os.path.join(dest_path, path_template)
     
     file_paths = []
     for angle in angles:
         opts = dict(options)
         opts['angles'] = angle
         file_path = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **opts)
         file_paths.append(file_path)
         
     if asset_id.mimetype == 'application/x-blender.mesh':
         datatype = 'mesh' 
     elif asset_id.mimetype == 'application/x-blender.group':
         datatype = 'group' 
     else:
         datatype = 'object' 
         
     arguments = ['--', datatype, asset_id.subname, path_template]
     arguments.extend(map(str, angles))
     arguments.append('--format=PNG')#TODO
     arguments.append('--camera_type=PERSPECTIVE')
     arguments.append('--width='+str(options['size'][0]))
     arguments.append('--height='+str(options['size'][1]))
     
     
         
     stdoutdata, stderrdata, returncode = run_blender(file_descr.file.filename, script_path(__file__), arguments)
     
     logger.debug(stdoutdata)
     logger.debug(stderrdata)
     logger.debug(returncode)
     #print(returncode) #Todo: check return code
     
     return file_paths
    def transcode(self, dest_path, file_descr, asset_id, target_mimetype,
                  **options):
        path_template = expand_path_template(target_mimetype.template,
                                             target_mimetype.mimetype,
                                             asset_id, **options)
        abs_file_path = os.path.join(dest_path, path_template)
        template = Template(path_template + '__${angles}')

        angles = [0.0, 0.1, 0.5]

        width = options['size'][0] * options['footage']
        height = options['size'][1] * (options['frames'] // options['footage'])

        angles = []
        file_paths = []
        for angle in range(0, 628, 628 // 12):
            angle = angle // 100.0
            file_path = template.safe_substitute(angles=angle)
            file_paths.append(file_path)
            angles.append(angle)

        if asset_id.mimetype == 'application/x-blender.mesh':
            datatype = 'mesh'
        elif asset_id.mimetype == 'application/x-blender.group':
            datatype = 'group'
        else:
            datatype = 'object'

        arguments = [
            '--', datatype, asset_id.subname,
            os.path.join(dest_path, template.safe_substitute())
        ]
        arguments.extend(list(map(str, angles)))
        arguments.append('--format=PNG')  # TODO
        arguments.append('--camera_type=PERSPECTIVE')
        arguments.append('--width=' + str(options['size'][0]))
        arguments.append('--height=' + str(options['size'][1]))

        script = os.path.join(os.path.dirname(__file__),
                              '../render/b-script-transcoderblenderrender.py')

        logger.debug(abs_file_path)

        stdoutdata, stderrdata, returncode = run_blender(
            file_descr.file.filename, script, arguments)

        logger.debug(stdoutdata)
        logger.debug(stderrdata)
        logger.debug(returncode)
        # print(returncode) # Todo: check return code

        sprite = Image.new('RGB', (width, height))
        for i, file_path in enumerate(file_paths):
            path = os.path.join(dest_path, file_path)
            tile = Image.open(path)
            x = (i % options['footage']) * options['size'][0]
            y = (i // options['footage']) * options['size'][1]
            sprite.paste(tile, (x, y))

        # sprite.show()
        sprite.save(abs_file_path)

        return [path_template]
    def transcode(self, dest_path, file_descr, asset_id, target_mimetype,
                  **options):
        path_template = expand_path_template(target_mimetype.template,
                                             target_mimetype.mimetype,
                                             asset_id, **options)
        abs_file_path = os.path.join(dest_path, path_template)
        abs_file_path_txt = abs_file_path + '.txt'

        arguments = [
            '--', asset_id.mimetype, asset_id.subname, abs_file_path_txt
        ]

        logger.debug(abs_file_path)

        stdoutdata, stderrdata, returncode = run_blender(
            file_descr.file.filename, script_path(__file__), arguments)

        logger.debug(stdoutdata)
        logger.debug(stderrdata)
        logger.debug(returncode)
        #print(returncode) #Todo: check return code

        arguments = [
            'convert', '-pointsize', '26', '-resize',
            str(options['size'][0]), abs_file_path_txt + '[0]', abs_file_path
        ]
        # print arguments
        pro = subprocess.Popen(arguments,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
        stdoutdata, stderrdata = pro.communicate()
        logger.debug(stdoutdata)
        logger.debug(stderrdata)
        logger.debug(pro.returncode)

        return [path_template]
Esempio n. 18
0
 def transcode(self, dest_path, file_descr, asset_id, target_mimetype, **options):
     path_template = expand_path_template(target_mimetype.template, target_mimetype.mimetype, asset_id, **options)
     abs_file_path = os.path.join(dest_path, path_template)
     abs_file_path_txt = abs_file_path+'.txt'
                 
     arguments = ['--', asset_id.mimetype, asset_id.subname, abs_file_path_txt]
     
     
     logger.debug(abs_file_path)
         
     stdoutdata, stderrdata, returncode = run_blender(file_descr.file.filename, script_path(__file__), arguments)
     
     logger.debug(stdoutdata)
     logger.debug(stderrdata)
     logger.debug(returncode)
     #print(returncode) #Todo: check return code
     
     arguments = ['convert', '-pointsize', '26', '-resize', str(options['size'][0]), abs_file_path_txt+'[0]', abs_file_path]
     print arguments
     pro = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     stdoutdata, stderrdata = pro.communicate()
     logger.debug(stdoutdata)
     logger.debug(stderrdata)
     logger.debug(pro.returncode)
     
     
     return [path_template]