1
0
mirror of https://github.com/sashacmc/photo-importer.git synced 2024-11-24 08:02:14 +02:00

Add video time metadata reading (by mean of exiftool)

This commit is contained in:
sashacmc 2020-05-29 00:05:13 +02:00
parent a0a19f388a
commit 240aafbf84
3 changed files with 27 additions and 11 deletions

View File

@ -21,7 +21,7 @@ Standalone web server for fast media import for headless computer
* Debian based Linux (Other Linux versions not officially supported, but might work)
### Dependencies:
* python3-exif
* PyExifTool (pip3 install PyExifTool)
* python3-progressbar
* python3-psutil
* exiftran

View File

@ -14,10 +14,10 @@ class Config(object):
'out_subdir_video': 'Video',
'out_subdir_audio': 'Audio',
'time_src_image': 'exif,name',
'time_src_video': 'name,attr',
'time_src_video': 'exif,name,attr',
'time_src_audio': 'name,attr',
'file_ext_image': 'jpeg,jpg',
'file_ext_video': 'mp4,mpg,mpeg,mov,avi,mts',
'file_ext_video': 'mp4,mpg,mpeg,mov,avi,mts,m2ts',
'file_ext_audio': 'mp3,3gp,3gpp,m4a,wav',
'file_ext_garbage': 'thm,ctg',
'file_ext_ignore': 'ini,zip,db',

View File

@ -5,11 +5,9 @@ import re
import stat
import time
import logging
import exifread
import exiftool
import datetime
from photo_importer import config
IGNORE = 0
IMAGE = 1
@ -49,10 +47,18 @@ class FileProp(object):
EXT_TO_TYPE = {}
DATE_TAGS = [
'EXIF:DateTimeOriginal',
'H264:DateTimeOriginal',
'QuickTime:MediaCreateDate'
]
def __init__(self, config):
self.__config = config
self.__prepare_ext_to_type()
self.__out_list = set()
self.__exiftool = exiftool.ExifTool()
self.__exiftool.start()
def __prepare_ext_to_type(self):
self.EXT_TO_TYPE = {}
@ -106,11 +112,21 @@ class FileProp(object):
def __time_by_exif(self, fullname):
try:
with open(fullname, 'rb') as f:
tags = exifread.process_file(f)
strtime = tags['EXIF DateTimeOriginal'].values
return datetime.datetime.strptime(strtime, '%Y:%m:%d %H:%M:%S')
except (FileNotFoundError, KeyError) as ex:
metadata = self.__exiftool.get_metadata(fullname)
for tag in self.DATE_TAGS:
if tag in metadata:
md = metadata[tag]
pos = md.find('+')
if pos > 0:
md = md[0:pos]
return datetime.datetime.strptime(md, '%Y:%m:%d %H:%M:%S')
logging.warning('time by exif (%s) not found tags count: %s' %
(fullname, len(metadata)))
for tag, val in metadata.items():
logging.debug('%s: %s' % (tag, val))
return None
except Exception as ex:
logging.warning('time by exif (%s) exception: %s' % (fullname, ex))
def __time_by_attr(self, fullname):