Exemple #1
0
    def __init__(self, filename, context={}):
        """

        :param filename:
        """
        self.filename = filename
        self.metadata = get_metadata(filename)
        self.params = get_parsed_metadata(filename, self.metadata)
        self.context = context
        self.context.update(self.params)
    def test_photos_has_metadata_and_date(self):
        """
        This test ensures that photos generated with a specific camera contains EXIF data.
        """
        self.generate_test_data()

        for complete_filename in self.files:
            data = get_metadata(complete_filename)
            self.assertTrue(data)
            self.assertTrue('EXIF Date' in data)
    def test_photos_has_metadata_and_date(self):
        """
        This test ensures that photos generated with a specific camera contains EXIF data.
        """
        self.generate_test_data()

        for complete_filename in self.files:
            data = get_metadata(complete_filename)
            self.assertTrue(data)
            self.assertTrue('EXIF Date' in data)
    def test_generate_folder_from_date(self):
        """
        This test ensures that we can generate an expected folder-structure based on EXIF date.
        """
        self.generate_test_data()

        for complete_filename in self.files:
            data = get_metadata(complete_filename)
            dt = data.get('EXIF Date')
            self.assertEqual(generate_folders_from_date(dt), get_folder_pattern(dt))
    def test_generate_folder_from_date(self):
        """
        This test ensures that we can generate an expected folder-structure based on EXIF date.
        """
        self.generate_test_data()

        for complete_filename in self.files:
            data = get_metadata(complete_filename)
            dt = data.get('EXIF Date')
            self.assertEqual(generate_folders_from_date(dt),
                             get_folder_pattern(dt))
    def test_make(self):
        """
        This test ensures that photos contains EXIF data about the maker of the camera
        """
        self.generate_test_data()

        for complete_filename in self.files:
            data = get_metadata(complete_filename)
            self.assertTrue(data)
            self.assertTrue('Image Make' in data)
            if hasattr(self, 'expected_make'):
                self.assertEqual(str(data['Image Make']), self.expected_make)
    def test_gps_info_available(self):
        """
        This test ensures that photos contains EXIF data about the maker of the camera
        """
        self.generate_test_data()

        for complete_filename in self.files:
            data = get_metadata(complete_filename)
            self.assertTrue(data)
            self.assertTrue('GPS GPSAltitude' in data)
            self.assertTrue('GPS GPSLatitude' in data)
            self.assertTrue('GPS GPSLongitude' in data)
    def test_make(self):
        """
        This test ensures that photos contains EXIF data about the maker of the camera
        """
        self.generate_test_data()

        for complete_filename in self.files:
            data = get_metadata(complete_filename)
            self.assertTrue(data)
            self.assertTrue('Image Make' in data)
            if hasattr(self, 'expected_make'):
                self.assertEqual(str(data['Image Make']), self.expected_make)
    def test_generate_filename_from_date(self):
        """
        This test ensures that we can generate an expected filename based on EXIF date.
        """
        self.generate_test_data()

        for complete_filename in self.files:
            #log.debug(complete_filename)
            data = get_metadata(complete_filename)
            dt = data.get('EXIF Date')
            basename, ext = os.path.splitext(os.path.basename(complete_filename))
            self.assertEqual(generate_filename_from_date(complete_filename, dt), get_filename_pattern(basename, dt, ext))
Exemple #10
0
    def test_gps_info_available(self):
        """
        This test ensures that photos contains EXIF data about the maker of the camera
        """
        self.generate_test_data()

        for complete_filename in self.files:
            data = get_metadata(complete_filename)
            self.assertTrue(data)
            self.assertTrue('GPS GPSAltitude' in data)
            self.assertTrue('GPS GPSLatitude' in data)
            self.assertTrue('GPS GPSLongitude' in data)
    def test_generate_filename_from_date(self):
        """
        This test ensures that we can generate an expected filename based on EXIF date.
        """
        self.generate_test_data()

        for complete_filename in self.files:
            #log.debug(complete_filename)
            data = get_metadata(complete_filename)
            dt = data.get('EXIF Date')
            basename, ext = os.path.splitext(
                os.path.basename(complete_filename))
            self.assertEqual(
                generate_filename_from_date(complete_filename, dt),
                get_filename_pattern(basename, dt, ext))
Exemple #12
0
    def test_generate_filename_from_date(self):
        """
        This test ensures that we can generate an expected filename based on EXIF date.
        """
        self.generate_test_data()

        for complete_filename in self.files:
            data = get_metadata(complete_filename)
            if data:
                log.debug("Got unexpected metadata from %s" % complete_filename)

            st = os.stat(complete_filename)
            dt = datetime.datetime.fromtimestamp(st.st_ctime > st.st_mtime and st.st_ctime or st.st_mtime)
            basename, ext = os.path.splitext(os.path.basename(complete_filename))
            self.assertEqual(generate_filename_from_date(complete_filename, dt), get_filename_pattern(basename, dt, ext))
    def test_generate_filename_from_date(self):
        """
        This test ensures that we can generate an expected filename based on EXIF date.
        """
        self.generate_test_data()

        for complete_filename in self.files:
            data = get_metadata(complete_filename)
            if data:
                log.debug("Got unexpected metadata from %s" %
                          complete_filename)

            st = os.stat(complete_filename)
            dt = datetime.datetime.fromtimestamp(
                st.st_ctime > st.st_mtime and st.st_ctime or st.st_mtime)
            basename, ext = os.path.splitext(
                os.path.basename(complete_filename))
            self.assertEqual(
                generate_filename_from_date(complete_filename, dt),
                get_filename_pattern(basename, dt, ext))
Exemple #14
0
def list_photos(folder):
    """
    Lists all photos in folder with photo specific data.
    """
    config = get_user_config()
    photo_extensions_to_include = [ext.strip() for ext in config.get('options', 'photo extensions').split(',')]
    for folder, filenames in get_photos_in_folder(folder, photo_extensions_to_include=photo_extensions_to_include).items():
        print("\n%s\n" % folder)
        for filename in filenames:
            complete_filename = os.path.join(folder, filename)
            metadata = get_metadata(complete_filename)
            size = os.stat(complete_filename).st_size
            make_n_model = ''
            if metadata:
                make = get_term_mapping.get(str(metadata.get('Image Make', '')), str(metadata.get('Image Make', '')))
                model = get_term_mapping.get(str(metadata.get('Image Model', '')), str(metadata.get('Image Model', '')))
                make_n_model = model
                if not make in make_n_model:
                    make_n_model = "%s %s" % (make, model)

            print("    %-30s %-10s %-20s" % (filename, sizeof_fmt(size), make_n_model))
Exemple #15
0
def get_date_from_file(filename):
    """
    Get the creation date from the specified filename, either from the EXIF-metadata or the creation-date of the file
    it EXIF-data is not available.

    @param filename: the file to process
    @returns: datetime
    """

    def _get_date_from_stat(fname):
        st = os.stat(fname)
        return datetime.datetime.fromtimestamp(st.st_ctime > st.st_mtime and st.st_ctime or st.st_mtime)

    try:
        dt = get_metadata(filename).get('EXIF Date', None)
        if not dt:
            return _get_date_from_stat(filename)

        return dt
    except KeyError as ex:
        logger.warning("'get_metadata' threw an exception when processing file '%s': %s" % (filename, ex))
        return _get_date_from_stat(filename)
Exemple #16
0
def get_date_from_file(filename):
    """
    Get the creation date from the specified filename, either from the EXIF-metadata or the creation-date of the file
    it EXIF-data is not available.

    @param filename: the file to process
    @returns: datetime
    """
    def _get_date_from_stat(fname):
        st = os.stat(fname)
        return datetime.datetime.fromtimestamp(
            st.st_ctime > st.st_mtime and st.st_ctime or st.st_mtime)

    try:
        dt = get_metadata(filename).get('EXIF Date', None)
        if not dt:
            return _get_date_from_stat(filename)

        return dt
    except KeyError as ex:
        logger.warning(
            "'get_metadata' threw an exception when processing file '%s': %s" %
            (filename, ex))
        return _get_date_from_stat(filename)