This commit is contained in:
flywithu 2019-03-16 00:31:03 +09:00
parent 33f43d2e3b
commit 3a3d32fcff

76
exif.py
View File

@ -8,8 +8,7 @@ import sys
from piwigo import * from piwigo import *
from calendar import monthrange from calendar import monthrange
import tinytag import tinytag
import subprocess
sys.stdout.reconfigure(encoding='utf-8') sys.stdout.reconfigure(encoding='utf-8')
sys.stdin.reconfigure(encoding='utf-8') sys.stdin.reconfigure(encoding='utf-8')
exif_choice = "EXIF DateTimeOriginal" exif_choice = "EXIF DateTimeOriginal"
@ -128,7 +127,11 @@ def files(path):
targetfolder = "./data/" 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): def photoupload(targetfolder):
filenames = os.listdir(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 ] testdirs = [ x for x in filenames if os.path.isdir(os.path.join(targetfolder,x)) == True ]
for testdir in testdirs: for testdir in testdirs:
photoupload(testdir) photoupload(os.path.join(targetfolder,testdir))
for filename in testfiles: for filename in testfiles:
# newfilename = filename.encode('utf-8') # newfilename = filename.encode('utf-8')
targetname,targetext = os.path.splitext(filename) targetname,targetext = os.path.splitext(filename)
pathfile = folder+filename pathfile = os.path.join(targetfolder,filename)
f2 = "./done/"+filename f2 = "./done/"+filename
f = open(pathfile,'rb') f = open(pathfile,'rb')
if targetext == ".mp4": if targetext == ".mp4":
print (".mp4") print (".mp4")
# print_all_metadata_atoms(Mp4File(pathfile)) T=datetime.datetime.strptime(str(get_video_date(pathfile))[1:10],'%Y-%m-%d')
# exit()
else: else:
tags = exifread.process_file(f, stop_tag=exif_choice) tags = exifread.process_file(f, stop_tag=exif_choice)
# print (pathfile) for tag in tags.keys():
for tag in tags.keys(): if tag in (exif_choice):
if tag in (exif_choice): photodatetime=tags[tag]
photodatetime=tags[tag] T=datetime.datetime.strptime(str(photodatetime)[0:10],'%Y:%m:%d')
T=datetime.datetime.strptime(str(photodatetime)[0:10],'%Y:%m:%d') day=T.strftime('%d')
day=T.strftime('%d') if(int(day)<=7):
if(int(day)<=7): fromto=T.strftime('%Y%m01_%Y%m07')
fromto=T.strftime('%Y%m01_%Y%m07') elif (int(day)<=14):
elif (int(day)<=14): fromto=T.strftime('%Y%m08_%Y%m14')
fromto=T.strftime('%Y%m08_%Y%m14') elif (int(day)<=21):
elif (int(day)<=21): fromto=T.strftime('%Y%m15_%Y%m21')
fromto=T.strftime('%Y%m15_%Y%m21') else:
else: year=int(T.strftime('%Y'))
year=int(T.strftime('%Y')) month=int(T.strftime('%m'))
month=int(T.strftime('%m')) lastday=monthrange(year,month)[1]
lastday=monthrange(year,month)[1] fromto=T.strftime('%Y%m22_%Y%m'+str(lastday))
#print(lastday) print(T.strftime('%Y'),T.strftime('%m'),fromto)
fromto=T.strftime('%Y%m22_%Y%m'+str(lastday)) parentid=getidbyname3(T.strftime('%Y'),T.strftime('%m'),fromto)
print(T.strftime('%Y'),T.strftime('%m'),fromto) try:
parentid=getidbyname3(T.strftime('%Y'),T.strftime('%m'),fromto) print("Try:",pathfile)
try: mySite.pwg.images.addSimple(image=pathfile, category=parentid)
print("Try:",pathfile) print("Success:",pathfile)
mySite.pwg.images.addSimple(image=pathfile, category=parentid) os.rename(pathfile,f2)
print("Success:",pathfile) #delete
os.rename(pathfile,f2) except Exception as e:
#delete print(e)
except Exception as e: pass
print(e) #print (T)
pass #print ("Key: %s, value %s" % (tag, tags[tag]))
#print (T)
#print ("Key: %s, value %s" % (tag, tags[tag]))
photoupload(targetfolder) photoupload(targetfolder)