cosk commited on
Commit
136bbe9
1 Parent(s): c796575

Upload captions_code.py

Browse files
Files changed (1) hide show
  1. captions_code.py +107 -0
captions_code.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Be careful with scripts that use 'os' library!
2
+ # Don't touch anything unless it's clearly stated what to do, or you know what you are doing
3
+ import os
4
+
5
+ # 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)
6
+ # will not be possible to fix.
7
+ # Running multiple times the program will also be bad.
8
+
9
+ keyword = "" # If you want to put a specific keyword on the tags, for example: keyword = "asuna"
10
+ path = r"" # Path where the captions are, for example: path = r"C:\my model\captions"
11
+ change_parenthesis = True # Replaces ( ... ) with \( ... \)
12
+
13
+ # The program will not replace underscores in these tags. It's not necessary to add your keyword
14
+ not_touch = [
15
+ ">_<", "O_o", "0_0", "3_3", "6_9", "@_@", "^_^", "|_|", "||_||", "=_=", "+_+", "._.", "<o>_<o>", "O_O", "o_o"
16
+ ]
17
+
18
+ # Removes these tags, good for meta tags like commentary, translation request, etc, but of course you can add anything.
19
+ # Didn't include "highres, lowres, absurdres, artifacts, anime screencap, ..." as they might be used.
20
+ # Check meta tags at "https://danbooru.donmai.us/wiki_pages/tag_group%3Ametatags"
21
+ # This doesn't remove artist or character tags, so in that case you might want to use another program.
22
+ remove = [
23
+
24
+ "commentary", "tagme", "translation request", "commentary request", "source request", "artist request", "copyright request", "character request",
25
+ "weapon request", "alternate language", "translated", "hard translated", "partially translated", "poorly translated", "translation note",
26
+ "commentary", "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", "cropped", "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",
36
+ "has downscaled revision", "has lossy revision", "has watermarked revision", "bad aspect ratio", "reversed", "rotated", "exif rotation", "stitched",
37
+ "poorly stitched", "webp-to-png conversion", "webp-to-jpg conversion", "ugoira conversion", "flash conversion", "vector trace", "extraction",
38
+ "animated", "animated png", "animated gif", "fast animated gif", "flash", "flash 9", "interactive", "flash game", "ruffle compatible", "video",
39
+ "high efficiency video coding", "low bitrate", "ugoira", "sound", "audible music", "audible speech", "volume warning", "check medium", "easytoon",
40
+ "live2d", "mikumikudance (medium)", "blender (medium)", "maya (medium)", "modo (medium)", "keyshot (medium)", "cinema 4d (medium)", "unreal (medium)",
41
+ "source filmmaker (medium)", "poser (medium)", "daz studio (medium)", "autodesk 3ds max", "xnalara", "xps", "looping animation", "non-repeating animation",
42
+ "roulette animation", "alpha transparency", "archived file", "hidden file", "open in winamp", "alt text", "open in internet explorer", "thumbnail surprise",
43
+ "exif thumbnail surprise", "tall image", "wide image", "wallpaper forced", "wallpaper forced", "lossy-lossless", "lossless-lossy", "low frame rate",
44
+ "missing file", "corrupted file", "corrupted flash", "corrupted metadata", "missing thumbnail", "solid color thumbnail", "epilepsy warning", "md5 mismatch",
45
+ "ai-generated", "ai-assisted", "duplicate", "pixel-perfect duplicate", "derivative work", "reference photo", "photo-referenced", "redrawn", "album cover redraw",
46
+ "manga panel redraw", "screencap redraw", "eyecatch", "end card", "official art", "game model", "key visual", "promotional art", "production art", "animatic",
47
+ "disc menu", "cd (source)", "spoilers", "check spoilers", "paid reward", "patreon reward", "enty reward", "fantia reward", "fanbox reward", "gumroad reward",
48
+ "paid reward available", "line sticker available", "scan dust", "self scan", "bleed through", "binding discoloration", "fixed", "avatar generator",
49
+ "off-topic", "jav", "self-upload", "revision", "color halftone", "magazine scan", "commentary request", "translation request", "artist request",
50
+ "copyright request", "character request", "source request", "gender request", "clothing request", "flower request", "headwear request", "weapon request",
51
+ "annotation request", "food request", "costume request", "vehicle request", "cosplay request", "gesture request", "medium request", "object request",
52
+ "parody request", "neckwear request", "hair ornament request", "hairstyle request", "collaboration request", "bird request", "mecha request",
53
+ "style request", "magazine request", "plant request", "song request", "fish request", "animal request", "reference request", "reference work request",
54
+ "dog request", "animal ear request", "aircraft request", "character counter request", "instrument request", "location request", "pose request",
55
+ "creature request", "creature request", "expression request", "color request", "footwear request", "sound effect request", "language request",
56
+ "pattern request", "emblem request", "symbol request", "logo request", "model request", "meme request", "earring request", "flag request", "phone request",
57
+ "skin request", "voice actor connection request", "check translation", "check commentary", "check copyright", "check character", "check artist",
58
+ "check source", "check gender", "check weapon", "check annotation", "annotation request", "check flower", "check medium", "check instrument", "check vehicle",
59
+ "skeb commission", "pixiv commission", "fantia commission", "bad pixiv id", "bad twitter id", "bad tumblr id", "bad deviantart id", "bad nicoseiga id",
60
+ "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",
61
+ "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",
62
+ "bad patreon id", "bad dropbox id", "bad artstreet id", "bad cgsociety id", "bad behance id", "bad miiverse id", "bad bilibili id", "bad vkontakte id",
63
+ "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",
64
+ "bad stash id", "bad booth id", "bad drawtwit id", "bad furaffinity id", "image sample", "pixiv sample", "twitter sample", "tumblr sample",
65
+ "artstation sample", "deviantart sample", "yandere sample", "e-hentai sample", "nicoseiga sample", "drawcrowd sample", "konachan sample", "fantia sample",
66
+ "hentai-foundry sample", "weibo sample", "tinami sample", "lofter sample", "zerochan sample", "newgrounds sample", "sankaku sample", "bcy sample",
67
+ "mihuashi sample", "picarto sample", "ko-fi sample", "twitpic sample", "furaffinity sample", "gracg sample", "plurk sample", "reddit sample", "uchor sample",
68
+ "english commentary", "chinese commentary", "symbol-only commentary", "partial commentary", "korean commentary", "mixed-language commentary",
69
+ "check commentary", "dated commentary", "romaji commentary", "spanish commentary", "engrish commentary", "russian commentary", "thai commentary",
70
+ "german commentary", "indonesian commentary", "french commentary", "portuguese commentary", "italian commentary", "vietnamese commentary",
71
+ "mojibake commentary", "latin commentary", "arabic commentary", "finnish commentary", "swedish commentary", "cyrillic commentary", "polish commentary",
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"
76
+ ]
77
+
78
+ filename = os.listdir(path)
79
+ total = len(filename)
80
+ i = 0
81
+ for file in os.listdir(path):
82
+ file_path = f"{path}\{file}"
83
+ if file_path.endswith(".txt"):
84
+ with open(file_path, 'r') as f:
85
+ text = f.read()
86
+ text = text.replace("\n", ", ")
87
+ for tag in not_touch:
88
+ if tag in text:
89
+ newtag = tag.replace("_", "/$")
90
+ text = text.replace(f"{tag}", f"{newtag}")
91
+ text = text.replace("_", " ")
92
+ text = text.replace("/$", "_")
93
+ for bad_tag in remove:
94
+ if bad_tag in text:
95
+ text = text.replace(f", {bad_tag}", "")
96
+ if change_parenthesis:
97
+ text = text.replace("(", "\(")
98
+ text = text.replace(")", "\)")
99
+ with open(file_path, 'w') as f:
100
+ if keyword == "":
101
+ f.write(text[:-2])
102
+ else:
103
+ f.write(text + f"{keyword}")
104
+ else:
105
+ print("\n-> " + file_path + " is not a text file!")
106
+ i += 1
107
+ print(f"\rProcessed: {i}/{total}", end="")