|
| 1 | +import sys |
| 2 | +import exifread |
| 3 | + |
| 4 | +def get_exif_data(file_path): |
| 5 | + try: |
| 6 | + with open(file_path, 'rb') as f: |
| 7 | + tags = exifread.process_file(f) |
| 8 | + return tags |
| 9 | + except IOError: |
| 10 | + return None |
| 11 | + |
| 12 | +def extract_info(file_path, tags): |
| 13 | + if tags is None: |
| 14 | + print("Error! - File Not Found!") |
| 15 | + return |
| 16 | + |
| 17 | + make = tags.get('Image Make', 'N/A') |
| 18 | + model = tags.get('Image Model', 'N/A') |
| 19 | + datetime_original = tags.get('EXIF DateTimeOriginal', 'N/A') |
| 20 | + latitude_tag = tags.get('GPS GPSLatitude') |
| 21 | + longitude_tag = tags.get('GPS GPSLongitude') |
| 22 | + |
| 23 | + if latitude_tag is not None and longitude_tag is not None: |
| 24 | + latitude = str(latitude_tag) + ' ' + str(tags.get('GPS GPSLatitudeRef', 'N/A')) |
| 25 | + longitude = str(longitude_tag) + ' ' + str(tags.get('GPS GPSLongitudeRef', 'N/A')) |
| 26 | + else: |
| 27 | + latitude = longitude = 'N/A' |
| 28 | + |
| 29 | + print(f"Source File: {file_path}") |
| 30 | + print(f"Make: {make}") |
| 31 | + print(f"Model: {model}") |
| 32 | + print(f"Original Date/Time: {datetime_original}") |
| 33 | + print(f"Latitude: {latitude}") |
| 34 | + print(f"Longitude: {longitude}") |
| 35 | + |
| 36 | +def main(): |
| 37 | + if len(sys.argv) != 2: |
| 38 | + print("Error! - No Image File Specified!") |
| 39 | + return |
| 40 | + |
| 41 | + file_path = sys.argv[1] |
| 42 | + exif_data = get_exif_data(file_path) |
| 43 | + extract_info(file_path, exif_data) |
| 44 | + |
| 45 | +if __name__ == "__main__": |
| 46 | + main() |
0 commit comments