Update captions_code.py
Browse filesFixed a little bit the code
- captions_code.py +21 -17
captions_code.py
CHANGED
@@ -6,10 +6,11 @@ import os
|
|
6 |
# will not be possible to fix.
|
7 |
# Running multiple times the program will also be bad.
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
# The program will not replace underscores in these tags. It's not necessary to add your keyword
|
15 |
not_touch = [
|
@@ -21,16 +22,14 @@ not_touch = [
|
|
21 |
# Check meta tags at "https://danbooru.donmai.us/wiki_pages/tag_group%3Ametatags"
|
22 |
# This doesn't remove artist or character tags, so in that case you might want to use another program.
|
23 |
remove = [
|
24 |
-
|
25 |
-
"
|
26 |
-
"weapon request", "alternate language", "translated", "hard translated", "partially translated", "poorly translated", "translation note",
|
27 |
-
"commentary", "commentary typo", "collaboration", "commission", "commissioner upload", "annotated", "partially annotated",
|
28 |
"reverse translation", "gift art", "making-of", "making-of available", "video available", "completion time", "textless version", "download link",
|
29 |
"psd available", "pdf available", "zip available", "artweaver (medium)", "azpainter (medium)", "clip studio paint (medium)", "gimp (medium)",
|
30 |
"ibispaint (medium)", "krita (medium)", "medibang paint (medium)", "mspaint (medium)", "mypaint (medium)", "nekopaint (medium)", "paint.net (medium)",
|
31 |
"painttool sai (medium)", "photoshop (medium)", "procreate (medium)", "bad id", "bad link", "bad source", "source mismatch", "multiple sources",
|
32 |
"non-web source", "archived source", "imageboard desourced", "inactive account", "protected link", "second-party source", "third-party source",
|
33 |
-
"resolution mismatch", "source smaller", "source larger", "video crop", "image sample", "cleaned", "
|
34 |
"recolored", "adjusted color balance", "noise reduction", "resized", "upscaled", "aliasing", "downscaled", "waifu2x", "third-party edit",
|
35 |
"detexted", "nude filter", "decensored", "headshop", "third-party watermark", "hard translated", "fake translation", "hard translated (non-english)",
|
36 |
"machine translated", "poorly translated", "has bad revision", "has artifacted revision", "has censored revision", "has cropped revision",
|
@@ -73,19 +72,21 @@ remove = [
|
|
73 |
"greek commentary", "malay commentary", "morse code commentary", "serbo-croatian commentary", "ukrainian commentary", "zalgo commentary", "hungarian commentary",
|
74 |
"tagalog commentary", "minnan commentary", "r'lyehian commentary", "czech commentary", "turkish commentary", "albanian commentary", "armenian commentary",
|
75 |
"base64 commentary", "catalan commentary", "danish commentary", "esperanto commentary", "gibberish commentary", "hindi commentary", "hymmnos commentary",
|
76 |
-
"kurdish commentary", "romanian commentary", "slovak commentary"
|
77 |
]
|
78 |
|
79 |
filename = os.listdir(path)
|
80 |
total = len(filename)
|
81 |
i = 0
|
|
|
|
|
82 |
for file in os.listdir(path):
|
83 |
file_path = f"{path}\{file}"
|
84 |
if file_path.endswith(".txt"):
|
85 |
with open(file_path, 'r') as f:
|
86 |
text = f.read()
|
87 |
text = text.replace("\n", ", ")
|
88 |
-
if
|
89 |
for tag in not_touch:
|
90 |
if tag in text:
|
91 |
newtag = tag.replace("_", "/$")
|
@@ -94,16 +95,19 @@ for file in os.listdir(path):
|
|
94 |
text = text.replace("/$", "_")
|
95 |
for bad_tag in remove:
|
96 |
if bad_tag in text:
|
97 |
-
text = text.replace(f"
|
98 |
-
|
|
|
|
|
99 |
text = text.replace("(", "\(")
|
100 |
text = text.replace(")", "\)")
|
101 |
with open(file_path, 'w') as f:
|
102 |
-
if keyword == "":
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
else:
|
107 |
print("\n-> " + file_path + " is not a text file!")
|
108 |
i += 1
|
109 |
print(f"\rProcessed: {i}/{total}", end="")
|
|
|
|
6 |
# will not be possible to fix.
|
7 |
# Running multiple times the program will also be bad.
|
8 |
|
9 |
+
get_path = str(input("Path (folder containing the captions): ")) # Path where the captions are, for example: path = r"C:\my model\captions"
|
10 |
+
keyword = str(input("Keyword (adds word to all files, leave empty for none): ")) # If you want to put a specific keyword on the tags, for example: keyword = "asuna"
|
11 |
+
underscore = int(input("Replace underscores with spaces? (0 -> No, 1 -> Yes): ")) # Replaces underscores with spaces
|
12 |
+
parenthesis = int(input("Replace parenthesis? (0 -> No, 1 -> Yes): ")) # Replaces ( ... ) with \( ... \)
|
13 |
+
path = rf"{get_path}"
|
14 |
|
15 |
# The program will not replace underscores in these tags. It's not necessary to add your keyword
|
16 |
not_touch = [
|
|
|
22 |
# Check meta tags at "https://danbooru.donmai.us/wiki_pages/tag_group%3Ametatags"
|
23 |
# This doesn't remove artist or character tags, so in that case you might want to use another program.
|
24 |
remove = [
|
25 |
+
"translation request", "commentary request", "source request", "artist request", "copyright request", "character request",
|
26 |
+
"weapon request", "alternate language", "translated", "hard translated", "partially translated", "poorly translated", "translation note", "commentary typo", "collaboration", "commission", "commissioner upload", "annotated", "partially annotated",
|
|
|
|
|
27 |
"reverse translation", "gift art", "making-of", "making-of available", "video available", "completion time", "textless version", "download link",
|
28 |
"psd available", "pdf available", "zip available", "artweaver (medium)", "azpainter (medium)", "clip studio paint (medium)", "gimp (medium)",
|
29 |
"ibispaint (medium)", "krita (medium)", "medibang paint (medium)", "mspaint (medium)", "mypaint (medium)", "nekopaint (medium)", "paint.net (medium)",
|
30 |
"painttool sai (medium)", "photoshop (medium)", "procreate (medium)", "bad id", "bad link", "bad source", "source mismatch", "multiple sources",
|
31 |
"non-web source", "archived source", "imageboard desourced", "inactive account", "protected link", "second-party source", "third-party source",
|
32 |
+
"resolution mismatch", "source smaller", "source larger", "video crop", "image sample", "cleaned", "colorized", "paintschainer",
|
33 |
"recolored", "adjusted color balance", "noise reduction", "resized", "upscaled", "aliasing", "downscaled", "waifu2x", "third-party edit",
|
34 |
"detexted", "nude filter", "decensored", "headshop", "third-party watermark", "hard translated", "fake translation", "hard translated (non-english)",
|
35 |
"machine translated", "poorly translated", "has bad revision", "has artifacted revision", "has censored revision", "has cropped revision",
|
|
|
72 |
"greek commentary", "malay commentary", "morse code commentary", "serbo-croatian commentary", "ukrainian commentary", "zalgo commentary", "hungarian commentary",
|
73 |
"tagalog commentary", "minnan commentary", "r'lyehian commentary", "czech commentary", "turkish commentary", "albanian commentary", "armenian commentary",
|
74 |
"base64 commentary", "catalan commentary", "danish commentary", "esperanto commentary", "gibberish commentary", "hindi commentary", "hymmnos commentary",
|
75 |
+
"kurdish commentary", "romanian commentary", "slovak commentary", "tagme", "commentary", "cropped legs", "cropped"
|
76 |
]
|
77 |
|
78 |
filename = os.listdir(path)
|
79 |
total = len(filename)
|
80 |
i = 0
|
81 |
+
count = 0
|
82 |
+
print("Removing tags...")
|
83 |
for file in os.listdir(path):
|
84 |
file_path = f"{path}\{file}"
|
85 |
if file_path.endswith(".txt"):
|
86 |
with open(file_path, 'r') as f:
|
87 |
text = f.read()
|
88 |
text = text.replace("\n", ", ")
|
89 |
+
if underscore == 1:
|
90 |
for tag in not_touch:
|
91 |
if tag in text:
|
92 |
newtag = tag.replace("_", "/$")
|
|
|
95 |
text = text.replace("/$", "_")
|
96 |
for bad_tag in remove:
|
97 |
if bad_tag in text:
|
98 |
+
text = text.replace(f"{bad_tag}", "")
|
99 |
+
text = text.replace(f", ,", ",")
|
100 |
+
count += 1
|
101 |
+
if parenthesis == 1:
|
102 |
text = text.replace("(", "\(")
|
103 |
text = text.replace(")", "\)")
|
104 |
with open(file_path, 'w') as f:
|
105 |
+
if keyword == "": text = text[:-2]
|
106 |
+
if text[0] == "," and text[1] == " ":
|
107 |
+
text = text[2:]
|
108 |
+
f.write(text + f"{keyword}")
|
109 |
else:
|
110 |
print("\n-> " + file_path + " is not a text file!")
|
111 |
i += 1
|
112 |
print(f"\rProcessed: {i}/{total}", end="")
|
113 |
+
print(f"\nRemoved {count} tags in total.")
|