def entry_from_file_path(file_path: Path, source: BaseSource) -> Entry: """ Creates an Entry template from a file path, filling the fields with file metadata. """ mimetype = get_mimetype(file_path) entry = Entry( title=file_path.name, source=source.entry_source, schema=get_schema_from_mimetype(mimetype), extra_attributes={ 'file': { 'checksum': get_checksum(file_path), 'path': str(file_path.resolve()), 'mimetype': mimetype, }, }, ) entry.date_on_timeline = get_file_entry_date(entry) if mimetype: if mimetype.startswith('image/'): entry.schema = 'file.image' entry.extra_attributes.update( get_image_extra_attributes(file_path)) if mimetype.startswith('video/'): entry.schema = 'file.video' try: entry.extra_attributes.update( get_video_extra_attributes(file_path)) except FileFormatError: logger.exception( f"Could not read metadata for video {str(file_path)}") if mimetype.startswith('audio/'): entry.schema = 'file.audio' entry.extra_attributes.update( get_audio_extra_attributes(file_path)) if mimetype.startswith('text/'): entry.schema = 'file.text' with file_path.open('r') as text_file: entry.description = text_file.read( settings.MAX_PLAINTEXT_PREVIEW_SIZE) return entry
entry.schema = 'message.telegram.audio' elif mimetype and mimetype.startswith('video'): entry.schema = 'message.telegram.video' elif mimetype and mimetype.startswith('image'): entry.schema = 'message.telegram.image' else: entry = Entry() if message.get('media_type') == 'sticker': entry.schema = 'message.telegram.sticker' elif message.get('media_type') == 'animation': entry.schema = 'message.telegram.gif' else: entry.schema = 'message.telegram' entry.source = self.entry_source entry.description = self.get_message_text(message) entry.date_on_timeline = self.get_message_date(message) # Set message metadata if chat['type'] == 'personal_chat': # For personal chats, messages are from one user to another user. # In the telegram data, the chat ID is the same as the other user's ID. if message['from_id'] == self.account_id( account): # Outgoing private msg entry.extra_attributes.update({ 'sender_name': self.account_name(account), 'sender_id': message['from_id'], 'recipient_name': chat['name'],