new
This commit is contained in:
parent
33f43d2e3b
commit
3a3d32fcff
76
exif.py
76
exif.py
@ -8,8 +8,7 @@ import sys
|
||||
from piwigo import *
|
||||
from calendar import monthrange
|
||||
import tinytag
|
||||
|
||||
|
||||
import subprocess
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
sys.stdin.reconfigure(encoding='utf-8')
|
||||
exif_choice = "EXIF DateTimeOriginal"
|
||||
@ -128,7 +127,11 @@ def files(path):
|
||||
|
||||
targetfolder = "./data/"
|
||||
|
||||
|
||||
def get_video_date(fileloc):
|
||||
print(fileloc)
|
||||
command="/usr/local/bin/ffprobe -v quiet -print_format flat -show_format "+fileloc+" | grep creation_time | cut -d= -f2-"
|
||||
output=subprocess.run(command, shell=True, stdout = subprocess.PIPE,universal_newlines=True)
|
||||
return (output.stdout)
|
||||
|
||||
def photoupload(targetfolder):
|
||||
filenames = os.listdir(targetfolder)
|
||||
@ -136,51 +139,48 @@ def photoupload(targetfolder):
|
||||
|
||||
testdirs = [ x for x in filenames if os.path.isdir(os.path.join(targetfolder,x)) == True ]
|
||||
for testdir in testdirs:
|
||||
photoupload(testdir)
|
||||
photoupload(os.path.join(targetfolder,testdir))
|
||||
|
||||
for filename in testfiles:
|
||||
# newfilename = filename.encode('utf-8')
|
||||
targetname,targetext = os.path.splitext(filename)
|
||||
pathfile = folder+filename
|
||||
pathfile = os.path.join(targetfolder,filename)
|
||||
f2 = "./done/"+filename
|
||||
f = open(pathfile,'rb')
|
||||
if targetext == ".mp4":
|
||||
print (".mp4")
|
||||
# print_all_metadata_atoms(Mp4File(pathfile))
|
||||
# exit()
|
||||
T=datetime.datetime.strptime(str(get_video_date(pathfile))[1:10],'%Y-%m-%d')
|
||||
else:
|
||||
tags = exifread.process_file(f, stop_tag=exif_choice)
|
||||
# print (pathfile)
|
||||
for tag in tags.keys():
|
||||
if tag in (exif_choice):
|
||||
photodatetime=tags[tag]
|
||||
T=datetime.datetime.strptime(str(photodatetime)[0:10],'%Y:%m:%d')
|
||||
day=T.strftime('%d')
|
||||
if(int(day)<=7):
|
||||
fromto=T.strftime('%Y%m01_%Y%m07')
|
||||
elif (int(day)<=14):
|
||||
fromto=T.strftime('%Y%m08_%Y%m14')
|
||||
elif (int(day)<=21):
|
||||
fromto=T.strftime('%Y%m15_%Y%m21')
|
||||
else:
|
||||
year=int(T.strftime('%Y'))
|
||||
month=int(T.strftime('%m'))
|
||||
lastday=monthrange(year,month)[1]
|
||||
#print(lastday)
|
||||
fromto=T.strftime('%Y%m22_%Y%m'+str(lastday))
|
||||
print(T.strftime('%Y'),T.strftime('%m'),fromto)
|
||||
parentid=getidbyname3(T.strftime('%Y'),T.strftime('%m'),fromto)
|
||||
try:
|
||||
print("Try:",pathfile)
|
||||
mySite.pwg.images.addSimple(image=pathfile, category=parentid)
|
||||
print("Success:",pathfile)
|
||||
os.rename(pathfile,f2)
|
||||
#delete
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
#print (T)
|
||||
#print ("Key: %s, value %s" % (tag, tags[tag]))
|
||||
for tag in tags.keys():
|
||||
if tag in (exif_choice):
|
||||
photodatetime=tags[tag]
|
||||
T=datetime.datetime.strptime(str(photodatetime)[0:10],'%Y:%m:%d')
|
||||
day=T.strftime('%d')
|
||||
if(int(day)<=7):
|
||||
fromto=T.strftime('%Y%m01_%Y%m07')
|
||||
elif (int(day)<=14):
|
||||
fromto=T.strftime('%Y%m08_%Y%m14')
|
||||
elif (int(day)<=21):
|
||||
fromto=T.strftime('%Y%m15_%Y%m21')
|
||||
else:
|
||||
year=int(T.strftime('%Y'))
|
||||
month=int(T.strftime('%m'))
|
||||
lastday=monthrange(year,month)[1]
|
||||
fromto=T.strftime('%Y%m22_%Y%m'+str(lastday))
|
||||
print(T.strftime('%Y'),T.strftime('%m'),fromto)
|
||||
parentid=getidbyname3(T.strftime('%Y'),T.strftime('%m'),fromto)
|
||||
try:
|
||||
print("Try:",pathfile)
|
||||
mySite.pwg.images.addSimple(image=pathfile, category=parentid)
|
||||
print("Success:",pathfile)
|
||||
os.rename(pathfile,f2)
|
||||
#delete
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
#print (T)
|
||||
#print ("Key: %s, value %s" % (tag, tags[tag]))
|
||||
|
||||
photoupload(targetfolder)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user