| """ | |
| Funkce pro extrakci technických a EXIF metadat. | |
| """ | |
| from datetime import datetime | |
| import os | |
| def extract_video_metadata(video_path): | |
| """ | |
| Extract technical metadata from video file | |
| Returns dictionary of metadata | |
| """ | |
| import cv2 | |
| cap = cv2.VideoCapture(video_path) | |
| if not cap.isOpened(): | |
| return None | |
| width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) | |
| height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |
| fps = cap.get(cv2.CAP_PROP_FPS) | |
| frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) | |
| duration = frame_count / fps | |
| cap.release() | |
| file_stats = os.stat(video_path) | |
| return { | |
| 'filename': os.path.basename(video_path), | |
| 'path': video_path, | |
| 'resolution': f"{width}x{height}", | |
| 'fps': fps, | |
| 'duration': duration, | |
| 'frame_count': frame_count, | |
| 'size': file_stats.st_size, | |
| 'created': datetime.fromtimestamp(file_stats.st_ctime), | |
| 'modified': datetime.fromtimestamp(file_stats.st_mtime) | |
| } | |
| def extract_audio_metadata(audio_path): | |
| """ | |
| Extract technical metadata from audio file | |
| Returns dictionary of metadata | |
| """ | |
| import wave | |
| try: | |
| with wave.open(audio_path, 'rb') as audio_file: | |
| channels = audio_file.getnchannels() | |
| sample_width = audio_file.getsampwidth() | |
| framerate = audio_file.getframerate() | |
| frames = audio_file.getnframes() | |
| duration = frames / float(framerate) | |
| file_stats = os.stat(audio_path) | |
| return { | |
| 'filename': os.path.basename(audio_path), | |
| 'path': audio_path, | |
| 'channels': channels, | |
| 'sample_width': sample_width, | |
| 'sample_rate': framerate, | |
| 'duration': duration, | |
| 'size': file_stats.st_size, | |
| 'created': datetime.fromtimestamp(file_stats.st_ctime), | |
| 'modified': datetime.fromtimestamp(file_stats.st_mtime) | |
| } | |
| except: | |
| return None | |
| def extract_exif_data(image_path): | |
| """ | |
| Extract EXIF metadata from image file | |
| Returns dictionary of EXIF data | |
| """ | |
| from PIL import Image, ExifTags | |
| try: | |
| img = Image.open(image_path) | |
| exif_data = img._getexif() | |
| if not exif_data: | |
| return None | |
| exif = {} | |
| for tag, value in exif_data.items(): | |
| decoded = ExifTags.TAGS.get(tag, tag) | |
| exif[decoded] = value | |
| file_stats = os.stat(image_path) | |
| exif.update({ | |
| 'filename': os.path.basename(image_path), | |
| 'path': image_path, | |
| 'size': file_stats.st_size, | |
| 'created': datetime.fromtimestamp(file_stats.st_ctime), | |
| 'modified': datetime.fromtimestamp(file_stats.st_mtime) | |
| }) | |
| return exif | |
| except: | |
| return None |