misc-datasets / captions_code.py
cosk's picture
Update captions_code.py
cf8cd8c
# Be careful with scripts that use 'os' library!
# Don't touch anything unless it's clearly stated what to do, or you know what you are doing
import os
# Make a backup of your text files, something wrong in these settings (let's say you didn't want to change the parenthesis, for example)
# will not be possible to fix.
# Running multiple times the program will also be bad.
get_path = str(input("Path (folder containing the captions): ")) # Path where the captions are, for example: path = r"C:\my model\captions"
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"
fix_spacing = int(input("Remove line breaks? (0 -> No, 1 -> Yes): ")) # To remove line breaks, useful when downloading with gallery-dl
underscore = int(input("Replace underscores with spaces? (0 -> No, 1 -> Yes): ")) # Replaces underscores with spaces
parenthesis = int(input("Replace parenthesis? (0 -> No, 1 -> Yes): ")) # Replaces ( ... ) with \( ... \)
path = rf"{get_path}"
# The program will not replace underscores in these tags. It's not necessary to add your keyword
not_touch = [
">_<", "O_o", "0_0", "3_3", "6_9", "@_@", "^_^", "|_|", "||_||", "=_=", "+_+", "._.", "<o>_<o>", "O_O", "o_o"
]
# Removes these tags, good for meta tags like commentary, translation request, etc, but of course you can add anything.
# Didn't include "highres, lowres, absurdres, artifacts, anime screencap, ..." as they might be used.
# Check meta tags at "https://danbooru.donmai.us/wiki_pages/tag_group%3Ametatags"
# This doesn't remove artist or character tags, so in that case you might want to use another program.
remove = [
"translation request", "commentary request", "source request", "artist request", "copyright request", "character request",
"weapon request", "alternate language", "translated", "hard translated", "partially translated", "poorly translated", "translation note", "commentary typo", "collaboration", "commission", "commissioner upload", "annotated", "partially annotated",
"reverse translation", "gift art", "making-of", "making-of available", "video available", "completion time", "textless version", "download link",
"psd available", "pdf available", "zip available", "artweaver (medium)", "azpainter (medium)", "clip studio paint (medium)", "gimp (medium)",
"ibispaint (medium)", "krita (medium)", "medibang paint (medium)", "mspaint (medium)", "mypaint (medium)", "nekopaint (medium)", "paint.net (medium)",
"painttool sai (medium)", "photoshop (medium)", "procreate (medium)", "bad id", "bad link", "bad source", "source mismatch", "multiple sources",
"non-web source", "archived source", "imageboard desourced", "inactive account", "protected link", "second-party source", "third-party source",
"resolution mismatch", "source smaller", "source larger", "video crop", "image sample", "cleaned", "colorized", "paintschainer",
"recolored", "adjusted color balance", "noise reduction", "resized", "upscaled", "aliasing", "downscaled", "waifu2x", "third-party edit",
"detexted", "nude filter", "decensored", "headshop", "third-party watermark", "hard translated", "fake translation", "hard translated (non-english)",
"machine translated", "poorly translated", "has bad revision", "has artifacted revision", "has censored revision", "has cropped revision",
"has downscaled revision", "has lossy revision", "has watermarked revision", "bad aspect ratio", "reversed", "rotated", "exif rotation", "stitched",
"poorly stitched", "webp-to-png conversion", "webp-to-jpg conversion", "ugoira conversion", "flash conversion", "vector trace", "extraction",
"animated", "animated png", "animated gif", "fast animated gif", "flash", "flash 9", "interactive", "flash game", "ruffle compatible", "video",
"high efficiency video coding", "low bitrate", "ugoira", "sound", "audible music", "audible speech", "volume warning", "check medium", "easytoon",
"live2d", "mikumikudance (medium)", "blender (medium)", "maya (medium)", "modo (medium)", "keyshot (medium)", "cinema 4d (medium)", "unreal (medium)",
"source filmmaker (medium)", "poser (medium)", "daz studio (medium)", "autodesk 3ds max", "xnalara", "xps", "looping animation", "non-repeating animation",
"roulette animation", "alpha transparency", "archived file", "hidden file", "open in winamp", "alt text", "open in internet explorer", "thumbnail surprise",
"exif thumbnail surprise", "tall image", "wide image", "wallpaper forced", "wallpaper forced", "lossy-lossless", "lossless-lossy", "low frame rate",
"missing file", "corrupted file", "corrupted flash", "corrupted metadata", "missing thumbnail", "solid color thumbnail", "epilepsy warning", "md5 mismatch",
"ai-generated", "ai-assisted", "duplicate", "pixel-perfect duplicate", "derivative work", "reference photo", "photo-referenced", "redrawn", "album cover redraw",
"manga panel redraw", "screencap redraw", "eyecatch", "end card", "official art", "game model", "key visual", "promotional art", "production art", "animatic",
"disc menu", "cd (source)", "spoilers", "check spoilers", "paid reward", "patreon reward", "enty reward", "fantia reward", "fanbox reward", "gumroad reward",
"paid reward available", "line sticker available", "scan dust", "self scan", "bleed through", "binding discoloration", "fixed", "avatar generator",
"off-topic", "jav", "self-upload", "revision", "color halftone", "magazine scan", "commentary request", "translation request", "artist request",
"copyright request", "character request", "source request", "gender request", "clothing request", "flower request", "headwear request", "weapon request",
"annotation request", "food request", "costume request", "vehicle request", "cosplay request", "gesture request", "medium request", "object request",
"parody request", "neckwear request", "hair ornament request", "hairstyle request", "collaboration request", "bird request", "mecha request",
"style request", "magazine request", "plant request", "song request", "fish request", "animal request", "reference request", "reference work request",
"dog request", "animal ear request", "aircraft request", "character counter request", "instrument request", "location request", "pose request",
"creature request", "creature request", "expression request", "color request", "footwear request", "sound effect request", "language request",
"pattern request", "emblem request", "symbol request", "logo request", "model request", "meme request", "earring request", "flag request", "phone request",
"skin request", "voice actor connection request", "check translation", "check commentary", "check copyright", "check character", "check artist",
"check source", "check gender", "check weapon", "check annotation", "annotation request", "check flower", "check medium", "check instrument", "check vehicle",
"skeb commission", "pixiv commission", "fantia commission", "bad pixiv id", "bad twitter id", "bad tumblr id", "bad deviantart id", "bad nicoseiga id",
"bad drawr id", "bad nijie id", "bad yandere id", "bad artstation id", "bad instagram id", "bad bcy id", "bad hentai-foundry id", "bad drawcrowd id",
"bad tinami id", "bad weibo id", "bad fanbox id", "bad cghub id", "bad google+ id", "bad poipiku id", "bad e-hentai id", "bad newgrounds id", "bad pawoo id",
"bad patreon id", "bad dropbox id", "bad artstreet id", "bad cgsociety id", "bad behance id", "bad miiverse id", "bad bilibili id", "bad vkontakte id",
"bad fantia id", "bad youtube id", "bad picasa id", "bad facebook id", "bad lofter id", "bad baraag id", "bad skeb id", "bad inkbunny id", "bad pillowfort id",
"bad stash id", "bad booth id", "bad drawtwit id", "bad furaffinity id", "image sample", "pixiv sample", "twitter sample", "tumblr sample",
"artstation sample", "deviantart sample", "yandere sample", "e-hentai sample", "nicoseiga sample", "drawcrowd sample", "konachan sample", "fantia sample",
"hentai-foundry sample", "weibo sample", "tinami sample", "lofter sample", "zerochan sample", "newgrounds sample", "sankaku sample", "bcy sample",
"mihuashi sample", "picarto sample", "ko-fi sample", "twitpic sample", "furaffinity sample", "gracg sample", "plurk sample", "reddit sample", "uchor sample",
"english commentary", "chinese commentary", "symbol-only commentary", "partial commentary", "korean commentary", "mixed-language commentary",
"check commentary", "dated commentary", "romaji commentary", "spanish commentary", "engrish commentary", "russian commentary", "thai commentary",
"german commentary", "indonesian commentary", "french commentary", "portuguese commentary", "italian commentary", "vietnamese commentary",
"mojibake commentary", "latin commentary", "arabic commentary", "finnish commentary", "swedish commentary", "cyrillic commentary", "polish commentary",
"greek commentary", "malay commentary", "morse code commentary", "serbo-croatian commentary", "ukrainian commentary", "zalgo commentary", "hungarian commentary",
"tagalog commentary", "minnan commentary", "r'lyehian commentary", "czech commentary", "turkish commentary", "albanian commentary", "armenian commentary",
"base64 commentary", "catalan commentary", "danish commentary", "esperanto commentary", "gibberish commentary", "hindi commentary", "hymmnos commentary",
"kurdish commentary", "romanian commentary", "slovak commentary", "tagme", "commentary", "cropped legs", "cropped"
]
filename = os.listdir(path)
total = len(filename)
i = 0
count = 0
print("Removing tags...")
for file in os.listdir(path):
file_path = f"{path}\{file}"
if file_path.endswith(".txt"):
with open(file_path, 'r') as f:
text = f.read()
if fix_spacing == 1:
text = text.replace("\n", ", ")
if underscore == 1:
for tag in not_touch:
if tag in text:
newtag = tag.replace("_", "/$")
text = text.replace(f"{tag}", f"{newtag}")
text = text.replace("_", " ")
text = text.replace("/$", "_")
for bad_tag in remove:
if bad_tag in text:
text = text.replace(f"{bad_tag}", "")
text = text.replace(f", ,", ",")
count += 1
if parenthesis == 1:
text = text.replace("(", "\(")
text = text.replace(")", "\)")
if fix_spacing != 1:
text = text.replace("\n\n", "\n")
with open(file_path, 'w') as f:
if keyword == "": text = text[:-2]
if text[0] == "," and text[1] == " ":
text = text[2:]
f.write(text + f"{keyword}")
else:
print("\n-> " + file_path + " is not a text file!")
i += 1
print(f"\rProcessed: {i}/{total}", end="")
print(f"\nRemoved {count} tags in total.")