-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathexiftool.py
80 lines (73 loc) · 2.54 KB
/
exiftool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
import pyexifinfo as exif
import os, sys
import subprocess
import json
from os.path import basename
from definitions import ROOT_DIR
import shutil
from progress.bar import Bar
#This is the exiftool processor, it runs exiftool and puts the outputs in either
#html, json or XML depending on which function is called. Exiftool needs to be installed for this
#to work.
#exiftool in JSON
def exifJSON():
print("Running exiftool to JSON")
os.chdir(ROOT_DIR + "/media/")
mediadir = os.listdir()
mediafiles = len(mediadir)
jsonbar = Bar('Processing', max=mediafiles)
for i in range(mediafiles):
for filename in os.listdir("."):
exifoutputjson = exif.get_json(filename)
#basejson = os.path.basename(filename)
os.chdir(ROOT_DIR + "/exifdata/json")
#Prints output to json file
print(json.dumps(exifoutputjson, sort_keys=True, indent=0, separators=(',', ': ')),
file= open(filename + ".json","w"))
#print(json.dumps(exifoutputjson, sort_keys=True, indent=0, separators=(',', ': ')),
# file= open(os.path.splitext(basejson)[0]+".json","w"))
jsonbar.next()
os.chdir(ROOT_DIR + "/media")
break
jsonbar.finish()
#exiftool in HTML
def exifHTML():
print("Running exiftool to HTML")
os.chdir(ROOT_DIR + "/media/")
mediadir = os.listdir()
mediafiles = len(mediadir)
htmlbar = Bar('Processing', max=mediafiles)
for i in range(mediafiles):
for filename in os.listdir("."):
#Prints output to HTML
#basehtml = os.path.basename(filename)
exifoutputhtml = exif.command_line(['exiftool', '-h', filename])
os.chdir(ROOT_DIR + "/exifdata/html")
#print(exifoutputhtml,file = open(os.path.splitext(basehtml)[0]+ ".html", "w"))
print(exifoutputhtml,file = open(filename + ".html","w"))
htmlbar.next()
os.chdir(ROOT_DIR + "/media")
break
htmlbar.finish()
#exiftool hex dump to html
def exifHTMLDump():
print("Running exiftool to HTML Dump")
os.chdir(ROOT_DIR + "/media/")
mediadir = os.listdir()
mediafiles = len(mediadir)
os.chdir(ROOT_DIR + "/media/")
htmldumpbar = Bar('Processing', max=mediafiles)
for i in range(mediafiles):
for filename in os.listdir("."):
#basehtmldump = os.path.basename(filename)
exifoutputhtmldump = exif.command_line(['exiftool', '-htmlDump', filename])
os.chdir(ROOT_DIR + "/exifdata/hex_html")
#htmldumpfile = open(os.path.splitext(basehtmldump)[0] + ".html", 'wb')
htmldumpfile = open(filename + ".html", 'wb')
htmldumpfile.write(exifoutputhtmldump)
htmldumpfile.close()
htmldumpbar.next()
os.chdir(ROOT_DIR + "/media")
break
htmldumpbar.finish()