def test_exiftool(mock_os, mock_find_executable): mock_find_executable.return_value = '/path/to/exiftool' assert get_exiftool() == '/path/to/exiftool' mock_find_executable.return_value = None mock_os.path.isfile.return_value = True mock_os.path.access.return_value = True assert get_exiftool() == '/usr/local/bin/exiftool' mock_os.path.isfile.return_value = False assert get_exiftool() is None
def __init__(self): # The default folder path is along the lines of 2017-06-17_01-04-14-dsc_1234-some-title.jpg self.default_file_name_definition = { 'date': '%Y-%m-%d_%H-%M-%S', 'name': '%date-%original_name-%title.%extension', } # The default folder path is along the lines of 2015-01-Jan/Chicago self.default_folder_path_definition = { 'date': '%Y-%m-%b', 'location': '%city', 'full_path': '%date/%album|%location|"{}"'.format( geolocation.__DEFAULT_LOCATION__ ), } self.cached_file_name_definition = None self.cached_folder_path_definition = None # Python3 treats the regex \s differently than Python2. # It captures some additional characters like the unicode checkmark \u2713. # See build failures in Python3 here. # https://travis-ci.org/jmathai/elodie/builds/483012902 self.whitespace_regex = '[ \t\n\r\f\v]+' # Instantiate a plugins object self.plugins = Plugins() #Initialize ExifTool Subprocess exiftool_addedargs = [ u'-config', u'"{}"'.format(constants.exiftool_config) ] ExifTool(executable_=get_exiftool(), addedargs=exiftool_addedargs).start()
def __set_tags(self, tags): if (not self.is_valid()): return None source = self.source exiftool = get_exiftool() if (exiftool is None): return False status = '' with ExifTool(executable_=exiftool, addedargs=self.exiftool_addedargs) as et: status = et.set_tags(tags, source) return status != ''
def get_exiftool_attributes(self): """Get attributes for the media object from exiftool. :returns: dict, or False if exiftool was not available. """ source = self.source exiftool = get_exiftool() if exiftool is None: return False with ExifTool(addedargs=self.exiftool_addedargs) as et: metadata = et.get_metadata(source) if not metadata: return False return metadata
def get_exiftool_attributes(self): """Get attributes for the media object from exiftool. :returns: dict, or False if exiftool was not available. """ source = self.source exiftool = get_exiftool() if(exiftool is None): return False with ExifTool(addedargs=self.exiftool_addedargs) as et: metadata = et.get_metadata(source) if not metadata: return False return metadata
def get_exif(self): """Get exif data from video file. Not all video files have exif and this currently relies on the CLI exiftool program. :returns: str or None if exiftool is not found """ exiftool = get_exiftool() if (exiftool is None): return None source = self.source process_output = subprocess.Popen(['%s "%s"' % (exiftool, source)], stdout=subprocess.PIPE, shell=True) return process_output.stdout.read()
def get_exiftool_attributes(self): """Get attributes for the media object from exiftool. :returns: dict, or False if exiftool was not available. """ if(self.exiftool_attributes is not None): return self.exiftool_attributes exiftool = get_exiftool() if(exiftool is None): return False source = self.source process_output = subprocess.Popen( '%s "%s"' % (exiftool, source), stdout=subprocess.PIPE, shell=True, universal_newlines=True ) output = process_output.stdout.read() # Get album from exiftool output album = None album_regex = re.search('Album +: +(.+)', output) if(album_regex is not None): album = album_regex.group(1) # Get title from exiftool output title = None for key in ['Displayname', 'Headline', 'Title', 'ImageDescription']: title_regex = re.search('%s +: +(.+)' % key, output) if(title_regex is not None): title_return = title_regex.group(1).strip() if(len(title_return) > 0): title = title_return break self.exiftool_attributes = { 'album': album, 'title': title } return self.exiftool_attributes
def get_exif(self): """Get exif data from video file. Not all video files have exif and this currently relies on the CLI exiftool program. :returns: str or None if exiftool is not found """ exiftool = get_exiftool() if(exiftool is None): return None source = self.source process_output = subprocess.Popen( ['%s "%s"' % (exiftool, source)], stdout=subprocess.PIPE, shell=True ) return process_output.stdout.read()
def set_album(self, name): """Set album for a photo :param str name: Name of album :returns: bool """ if(name is None): return False exiftool = get_exiftool() if(exiftool is None): return False source = self.source stat = os.stat(source) exiftool_config = constants.exiftool_config if(constants.debug is True): print '%s -config "%s" -xmp-elodie:Album="%s" "%s"' % (exiftool, exiftool_config, name, source) # noqa process_output = subprocess.Popen( '%s -config "%s" -xmp-elodie:Album="%s" "%s"' % (exiftool, exiftool_config, name, source), stdout=subprocess.PIPE, shell=True ) process_output.communicate() if(process_output.returncode != 0): return False os.utime(source, (stat.st_atime, stat.st_mtime)) exiftool_backup_file = '%s%s' % (source, '_original') if(os.path.isfile(exiftool_backup_file) is True): os.remove(exiftool_backup_file) self.set_metadata(album=name) self.reset_cache() return True
def get_exiftool_attributes(self): """Get attributes for the media object from exiftool. :returns: dict, or False if exiftool was not available. """ if (self.exiftool_attributes is not None): return self.exiftool_attributes exiftool = get_exiftool() if (exiftool is None): return False source = self.source process_output = subprocess.Popen('%s "%s"' % (exiftool, source), stdout=subprocess.PIPE, shell=True, universal_newlines=True) output = process_output.stdout.read() # Get album from exiftool output album = None album_regex = re.search('Album +: +(.+)', output) if (album_regex is not None): album = album_regex.group(1) # Get title from exiftool output title = None for key in ['Displayname', 'Headline', 'Title', 'ImageDescription']: title_regex = re.search('%s +: +(.+)' % key, output) if (title_regex is not None): title_return = title_regex.group(1).strip() if (len(title_return) > 0): title = title_return break self.exiftool_attributes = {'album': album, 'title': title} return self.exiftool_attributes
def set_album(self, name): """Set album for a photo :param str name: Name of album :returns: bool """ if (name is None): return False exiftool = get_exiftool() if (exiftool is None): return False source = self.source stat = os.stat(source) exiftool_config = constants.exiftool_config if (constants.debug is True): print '%s -config "%s" -xmp-elodie:Album="%s" "%s"' % ( exiftool, exiftool_config, name, source) # noqa process_output = subprocess.Popen( '%s -config "%s" -xmp-elodie:Album="%s" "%s"' % (exiftool, exiftool_config, name, source), stdout=subprocess.PIPE, shell=True) process_output.communicate() if (process_output.returncode != 0): return False os.utime(source, (stat.st_atime, stat.st_mtime)) exiftool_backup_file = '%s%s' % (source, '_original') if (os.path.isfile(exiftool_backup_file) is True): os.remove(exiftool_backup_file) self.set_metadata(album=name) self.reset_cache() return True
def get_exiftool_attributes(self): # return self.get_exif_attributes() """Get attributes for the media object from exiftool. :returns: dict, or False if exiftool was not available. """ if self.exif_metadata is not None: return self.exif_metadata source = self.source exiftool = get_exiftool() if (exiftool is None): return False with ExifTool(addedargs=self.exiftool_addedargs) as et: metadata = et.get_metadata(source) if not metadata: return False metadata["origin"] = self.get_origin() self.exif_metadata = metadata return metadata
def setup_module(): exiftool_addedargs = [ u'-config', u'"{}"'.format(constants.exiftool_config) ] ExifTool(executable_=get_exiftool(), addedargs=exiftool_addedargs).start()
else: has_errors = False result.append((current_file, False)) result.write() if has_errors: sys.exit(1) @click.group() def main(): pass main.add_command(_import) main.add_command(_update) main.add_command(_generate_db) main.add_command(_verify) main.add_command(_batch) if __name__ == '__main__': #Initialize ExifTool Subprocess exiftool_addedargs = [ u'-config', u'"{}"'.format(constants.exiftool_config) ] with ExifTool(executable_=get_exiftool(), addedargs=exiftool_addedargs) as et: main()
has_errors = has_errors is True or not dest_path else: has_errors = False result.append((current_file, False)) result.write() if has_errors: sys.exit(1) @click.group() def main(): pass main.add_command(_import) main.add_command(_update) main.add_command(_generate_db) main.add_command(_verify) main.add_command(_batch) if __name__ == '__main__': #Initialize ExifTool Subprocess exiftool_addedargs = [ u'-config', u'"{}"'.format(constants.exiftool_config) ] with ExifTool(executable_=get_exiftool(), addedargs=exiftool_addedargs) as et: main()