summaryrefslogtreecommitdiffstats
path: root/tests/exiftool_parser/parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/exiftool_parser/parser.py')
-rwxr-xr-xtests/exiftool_parser/parser.py41
1 files changed, 30 insertions, 11 deletions
diff --git a/tests/exiftool_parser/parser.py b/tests/exiftool_parser/parser.py
index 3298488..351c1b6 100755
--- a/tests/exiftool_parser/parser.py
+++ b/tests/exiftool_parser/parser.py
@@ -25,31 +25,50 @@ print "<exif>"
#
# 1. tag:
#
-# x) name = value
-# - Tag 0x1234
+# | | | x) name = value
+# | | | - Tag 0x1234
#
# 2. IFD indicator:
#
-# + [xxx directory with xx entries]
+# | | | + [xxx directory with xx entries]
#
p = re.compile(
- "(^.*?[0-9]\).*? = .*?\n.*?- Tag 0x[0-9a-f]{4})|(\+ \[.*? directory with [0-9]+ entries]$)"
+ "(((?:\| )+)[0-9]*\).*? = .*?\n.*?- Tag 0x[0-9a-f]{4})" + "|"
+ + "(((?:\| )*)\+ \[.*? directory with [0-9]+ entries]$)"
, re.M)
tags = p.findall(text)
+layer = 0
+ifds = []
+
for s in tags:
- if s[1]:
- ifd = s[1][3:].split()[0]
+ # IFD indicator
+ if s[2]:
+ l = len(s[3])
+ ifd = s[2][l + 3:].split()[0]
+ new_layer = l / 2 + 1
+ if new_layer > layer:
+ ifds.append(ifd)
+ else:
+ for i in range(layer - new_layer):
+ ifds.pop()
+ ifds[-1] = ifd
+ layer = new_layer
else:
+ l = len(s[1])
s = s[0]
+ new_layer = l / 2
+ if new_layer < layer:
+ for i in range(layer - new_layer):
+ ifds.pop()
+ layer = new_layer
+
# find the raw value in the parenthesis
- p = re.compile("\(.*\)\n")
- value = p.search(s)
+ value = re.search("\(.*\)\n", s)
if value:
value = value.group(0)[1:-2]
else:
- p = re.compile("=.*\n")
- value = p.search(s)
+ value = re.search("=.*\n", s)
value = value.group(0)[2:-1]
# find the ID
@@ -61,6 +80,6 @@ for s in tags:
p = re.compile("[0-9]*?\).*? = ")
name = p.search(s)
name = name.group(0)[4:-3]
- print (' <tag ifd="' + ifd + '" id="'
+ print (' <tag ifd="' + ifds[-1] + '" id="'
+ _id + '" name="' + name +'">' + value + "</tag>")
print "</exif>"