def create_file(self, filePath, fileName): file = File() file.name = fileName file.relPath = os.path.normpath(os.path.relpath(filePath, self.root)) file.originalPath = os.path.normpath(os.path.join(filePath, fileName)) t = os.path.getmtime(file.originalPath) file.mTime = datetime.datetime.fromtimestamp(t) t = os.path.getctime(file.originalPath) file.cTime = datetime.datetime.fromtimestamp(t) file.size = os.path.getsize(file.originalPath) _, fileExtension = os.path.splitext(file.originalPath) file.type = File.type_from_extension(fileExtension) if file.type == fileConstants.TYPE_OTHER or file.type == fileConstants.TYPE_UNKNOWN: return None self.update_exif_metadata(file) file.file_type = fileConstants.TYPE_FILESYSTEM return file
def fetch_album_images(self, album): with self.max_threads_lock: album_last_updated_string = self.get_json_key(album, ['ImagesLastUpdated']) album_uri = self.get_json_key(album, ['Uris', 'AlbumImages', 'Uri']) # Check cache for album!images results, if not, request from network. cached_album_images = None with self.cache_lock: try: _, cached_album_images_json = self.check_cache(album_uri, album_last_updated_string) if cached_album_images_json is not None: cached_album_images = json.loads(cached_album_images_json) except Exception as e: print 'Exception checking cache for album: ' + album_uri + ' :: ' + e.message if cached_album_images is None: if album_uri is None: print 'Could not find album images Uri for album: ' + self.get_json_key(album, ['Name']) return cached_album_images_response = self.session.get(API_ORIGIN + album_uri, params = {'count':'1000000', '_expand' : 'ImageMetadata', '_expandmethod' : 'inline'}, headers={'Accept': 'application/json'}) cached_album_images = {} try: cached_album_images = cached_album_images_response.json() with self.cache_lock: self.put_cache(album_uri, album_last_updated_string, album, cached_album_images_response.text) except Exception as e: print 'Exception getting album :: ' + album_uri + ' :: ' + e.message + ' :: (%d)' % cached_album_images_response.status_code print 'Full response:' + cached_album_images_response.text images_array = self.get_json_key(cached_album_images, ['Response', 'AlbumImage']) if images_array is None: print 'Could not get images array for album: ' + self.get_json_key(album, ['Name']) + 'uri:' + album_uri images_array = [] for image in images_array: file = File() file.name = self.get_json_key(image, ['FileName']) is_video = self.get_json_key(image, ['IsVideo']) if is_video == True: #print 'Video: ' + file.name continue file.relativePath = os.path.normpath(self.get_json_key(album, ['UrlPath'])) file.originalPath = os.path.normpath(os.path.join(file.relativePath, file.name)) file.source = self.get_json_key(image, ['ArchivedUri']) file.thumbnail = self.get_json_key(image, ['ThumbnailUrl']) file.weburi = self.get_json_key(image, ['WebUri']) file.uri = self.get_json_key(image, ['Uri']) file.size = self.get_json_key(image, ['ArchivedSize']) file.md5 = self.get_json_key(image, ['ArchivedMD5']) _, file_extension = os.path.splitext(file.name) file.type = File.type_from_extension(file_extension) if file.type == fileConstants.TYPE_OTHER or file.type == fileConstants.TYPE_UNKNOWN: pass metadata = self.get_json_key(image, ['Uris', 'ImageMetadata', 'ImageMetadata']) file.exif_width = self.get_json_key(image, ['OriginalWidth']) file.exif_height = self.get_json_key(image, ['OriginalHeight']) file.file_type = fileConstants.TYPE_SMUGMUG if metadata is not None: file.metadata = metadata file.exif_aperture = self.get_json_key(metadata, ['Aperture']) file.exif_date = self.get_json_key(metadata, ['DateTime']) or self.get_json_key(metadata, ['DateTimeCreated']) or self.get_json_key(metadata, ['DateTimeOriginal']) file.exif_date_parsed = file.convert_time_string(file.exif_date) file.exif_iso = self.get_json_key(metadata, ['ISO']) # fl is a string, strip 'mm', convert to a double try: file.exif_focal_length = float(self.get_json_key(metadata, ['FocalLength']).replace('mm', '')) except: pass file.exif_exposure = self.get_json_key(metadata, ['Exposure']) file.exif_camera = self.get_json_key(metadata, ['Camera']) or self.get_json_key(metadata, ['Model']) with self.output_lock: self.add_file_to_hash(file, self.images) self.increment_threadcount()