From 2f205d2a4ea4b3e24a9fdde064ef9a3ef96a67bd Mon Sep 17 00:00:00 2001 From: Felipe Martin Date: Wed, 26 Sep 2018 23:54:29 +0200 Subject: [PATCH] Fixed not returning correct type --- porg.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/porg.py b/porg.py index 1d4e8b1..32f6dcb 100644 --- a/porg.py +++ b/porg.py @@ -3,6 +3,7 @@ from datetime import datetime import hashlib import mimetypes import os.path +from typing import Text import exifread import mutagen @@ -21,7 +22,7 @@ class File: path: str @property - def type(self): + def type(self) -> Text: """Retrieves the file mimetype by extension""" if not getattr(self, '_type', False): self._type, _ = mimetypes.guess_type(self.path) @@ -30,15 +31,15 @@ class File: return self._type @property - def is_image(self): + def is_image(self) -> bool: return 'image' in self.type @property - def is_video(self): + def is_video(self) -> bool: return 'video' in self.type @property - def exif(self): + def exif(self) -> dict: """ Retrieve EXIF data from the file and merge it with wathever mutagen finds in there for video files. """ @@ -49,7 +50,7 @@ class File: return self._exif @property - def datetime(self): + def datetime(self) -> datetime: """ Retrieves original creation date for the picture trying exif data first, filename guessing and finally modification date. Make sure your pictures are exported unmodified so the file attributes maintain their @@ -78,14 +79,14 @@ class File: # Last resort, use file creation/modification date stat = os.stat(self.path) try: - return stat.st_birthtime + return datetime.fromtimestamp(stat.st_birthtime) except AttributeError: # Linux: No easy way to get creation dates here, # so we'll settle for when its content was last modified. - return stat.st_mtime + return datetime.fromtimestamp(stat.st_mtime) @property - def checksum(self): + def checksum(self) -> Text: if not getattr(self, '_checksum', False): digest = hashlib.sha1() with open(self.path, 'rb') as handler: