Ejemplo n.º 1
0
def get_exe_version(path):
    stream = FileInputStream(path)
    parser = hachoir.parser.guessParser(stream)
    metadata = hachoir.metadata.extractMetadata(parser)
    version = metadata.get("version")
    stream.close()
    return version
Ejemplo n.º 2
0
def is_video(file):
    """Returns `True` if the file has a video mime type."""
    ext = _get_extension(file)
    if not ext:
        metadata = _get_metadata(file)
        if metadata and metadata.has('mime_type'):
            return metadata.get('mime_type').startswith('video/')
        else:
            return False
    else:
        file = 'a' + ext
        return (mimetypes.guess_type(file)[0] or '').startswith('video/')
Ejemplo n.º 3
0
    def get_timestamp(self):
        modified_time = datetime.fromtimestamp(os.path.getmtime(self.filepath))
        metadata_time = None
        invalid_time = datetime.strptime("1980-01-01", "%Y-%m-%d")

        if self.is_jpg_file():
            try:
                with open(self.filepath, "rb") as f:
                    tags = exifread.process_file(f, details=False, stop_tag="DateTimeOriginal")
                    dt_str = str(tags["EXIF DateTimeOriginal"])

                metadata_time = datetime.strptime(dt_str, "%Y:%m:%d %H:%M:%S")
            except Exception as e:
                print("ERROR: %s" % e)

        elif self.is_video_file() or self.is_pic_file():
            try:  # this try for when the createParser below return None and hence "with" clause fails
                with hachoir.parser.createParser(self.filepath) as parser:
                    metadata = hachoir.metadata.extractMetadata(parser)
                    try:
                        metadata_time = metadata.get("creation_date", default=None)
                    except Exception as e:
                        print("ERROR: Could not fine creation_date from following metadata:")
                        print(metadata)
                        print("Original error:\n%s" % e)
            except Exception as e:
                print("ERROR: \n%s" % e)

        print("metadata time = %s" % metadata_time)
        print("file modified time = %s" % modified_time)

        # date of metadata time and modified time are same then use modified time as metadata time is always UTC.
        if metadata_time and metadata_time.date() != modified_time.date() and invalid_time < metadata_time < modified_time:
            dt = metadata_time
            print("using metadata time")
        else:
            dt = modified_time
            print("using file modified time")

        dt = dt.replace(microsecond=0)  # precision till seconds only.
        return dt
Ejemplo n.º 4
0
def get_exe_version(path) -> str:
    """Return version from an executable"""

    parser = hachoir.parser.createParser(path)
    metadata = hachoir.metadata.extractMetadata(parser=parser)
    return metadata.get('version')