-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlookforbadtextures.py
89 lines (70 loc) · 2.33 KB
/
lookforbadtextures.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
81
82
83
84
85
86
87
88
89
# Chris Sprance
# Look For textures with /ser=1 Supress Engine Reduce Checked on (This is
# BAD!!!!)
from __future__ import print_function
from PIL import TiffImagePlugin
import os
import re
import sys
def strip_control_characters(input):
if input:
# unicode invalid characters
RE_XML_ILLEGAL = (
u"([\u0000-\u0008\u000b-\u000c\u000e-\u001f\ufffe-\uffff])"
+ u"|"
+ u"([%s-%s][^%s-%s])|([^%s-%s][%s-%s])|([%s-%s]$)|(^[%s-%s])"
% (
unichr(0xd800),
unichr(0xdbff),
unichr(0xdc00),
unichr(0xdfff),
unichr(0xd800),
unichr(0xdbff),
unichr(0xdc00),
unichr(0xdfff),
unichr(0xd800),
unichr(0xdbff),
unichr(0xdc00),
unichr(0xdfff),
)
)
input = re.sub(RE_XML_ILLEGAL, "", input)
# ascii control characters
input = re.sub(r"[\x01-\x1F\x7F]", "", input)
input = re.sub(r"(8BIM...)", "", input)
return input
# return raw values from a tag
def retraw(img):
# Load the image into the metadata
# grab the iptc data
# some stuff doesn't have metadata for whatever reason ()
try:
im = TiffImagePlugin.TiffImageFile(img)
# set up our regex
iptc = im.tag.tagdata[TiffImagePlugin.PHOTOSHOP_CHUNK]
regex = re.findall(r"\/ser=1", iptc)
# if regex is true it will return back a value so check that and then
# return
if regex:
print(img, strip_control_characters(iptc))
# extract the data from the tag and return it and the i mage path
# in a tuple
except Exception as e:
print(e)
# just fugettahboutit
return
# main
def main():
# recurse through all directors only finding files with .tif
if len(sys.argv) > 1:
directory = sys.argv[1]
else:
directory = "d:/perforce/gamesdk/objects/weapons"
pass
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".tif"):
retraw(os.path.join(root, file))
# run the shizzle
if __name__ == "__main__":
main()