mirror of https://github.com/fmartingr/porg.git
Fixed not returning correct type
This commit is contained in:
parent
4e2a373dc3
commit
2f205d2a4e
17
porg.py
17
porg.py
|
@ -3,6 +3,7 @@ from datetime import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os.path
|
import os.path
|
||||||
|
from typing import Text
|
||||||
|
|
||||||
import exifread
|
import exifread
|
||||||
import mutagen
|
import mutagen
|
||||||
|
@ -21,7 +22,7 @@ class File:
|
||||||
path: str
|
path: str
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self) -> Text:
|
||||||
"""Retrieves the file mimetype by extension"""
|
"""Retrieves the file mimetype by extension"""
|
||||||
if not getattr(self, '_type', False):
|
if not getattr(self, '_type', False):
|
||||||
self._type, _ = mimetypes.guess_type(self.path)
|
self._type, _ = mimetypes.guess_type(self.path)
|
||||||
|
@ -30,15 +31,15 @@ class File:
|
||||||
return self._type
|
return self._type
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_image(self):
|
def is_image(self) -> bool:
|
||||||
return 'image' in self.type
|
return 'image' in self.type
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_video(self):
|
def is_video(self) -> bool:
|
||||||
return 'video' in self.type
|
return 'video' in self.type
|
||||||
|
|
||||||
@property
|
@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.
|
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
|
return self._exif
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def datetime(self):
|
def datetime(self) -> datetime:
|
||||||
"""
|
"""
|
||||||
Retrieves original creation date for the picture trying exif data first, filename guessing and finally
|
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
|
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
|
# Last resort, use file creation/modification date
|
||||||
stat = os.stat(self.path)
|
stat = os.stat(self.path)
|
||||||
try:
|
try:
|
||||||
return stat.st_birthtime
|
return datetime.fromtimestamp(stat.st_birthtime)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# Linux: No easy way to get creation dates here,
|
# Linux: No easy way to get creation dates here,
|
||||||
# so we'll settle for when its content was last modified.
|
# so we'll settle for when its content was last modified.
|
||||||
return stat.st_mtime
|
return datetime.fromtimestamp(stat.st_mtime)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def checksum(self):
|
def checksum(self) -> Text:
|
||||||
if not getattr(self, '_checksum', False):
|
if not getattr(self, '_checksum', False):
|
||||||
digest = hashlib.sha1()
|
digest = hashlib.sha1()
|
||||||
with open(self.path, 'rb') as handler:
|
with open(self.path, 'rb') as handler:
|
||||||
|
|
Loading…
Reference in New Issue