1
0
Эх сурвалжийг харах

check the movies also, skip unused

rachels 3 жил өмнө
parent
commit
f7784cb31f
1 өөрчлөгдсөн 23 нэмэгдсэн , 17 устгасан
  1. 23 17
      tools/check_images.py

+ 23 - 17
tools/check_images.py

@@ -8,7 +8,7 @@ import re
 #print path
 
 startpattern = """images/"""
-imgFormats = ['jpg','gif']
+imgFormats = ['jpg','gif','png','mp4']
 
 infile = io.open('glife.txt',mode='r',encoding='utf-16')
 lines = infile.readlines()
@@ -16,22 +16,28 @@ lines = infile.readlines()
 images = []
 
 for name in os.listdir("locations"):
-    ifile = io.open(
-        os.path.join("locations", name),
-        mode='rt',
-        encoding='utf-8'
-    )
-    text = ifile.read()
-    for match in re.finditer(r"images.+?[.](gif|jpg|png)", text, flags=re.U):
-        imgfile = match.group().encode("utf-8")
-        randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
-        if randmatch != None:
-            for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
-                images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
-        else:
-            images.append(imgfile)
-    
-    ifile.close()
+	path = os.path.join("locations", name)
+	if os.path.isdir(path):
+		continue
+		# skip directories
+	else:
+		print "file", name
+		ifile = io.open(
+			os.path.join("locations", name),
+			mode='rt',
+			encoding='utf-8'
+		)
+		text = ifile.read()
+		for match in re.finditer(r"images.+?[.](gif|jpg|png|mp4)", text, flags=re.U):
+			imgfile = match.group().encode("utf-8")
+			randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
+			if randmatch != None:
+				for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
+					images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
+			else:
+				images.append(imgfile)
+		
+		ifile.close()
 
 
 for image in images: