Module:TagParser

--WIP

--script that'll allow you to just paste .json metadata from a doujin into it and it will assemble a neat tag table

require('Module:StrManip') local p = {}

function p.main local str = mw.getCurrentFrame.args[1] local str = Everyday Life with Lady Yupiel (Towako 2) [English] {CapableScoutMan & S.T.A.L.K.E.R.}",    "title_original": "[774] ユピエル様との日常 (永遠娘 2) [英訳]",    "category": "manga",    "tags": {      "language": [        "english",        "translated"      ],      "artist": [        "nanashi | 774, test1, test2"      ],      "male": [        "collar",        "petplay",        "sole male",        "vampire"      ],      "female": [        "cunnilingus",        "femdom",        "kissing",        "leg lock",        "lolicon",        "sole female",        "sweating",        "vampire"      ],      "misc": [        "mosaic censorship",        "multi-work series"      ]    },    "language": "English",    "translated": true,    "favorite_category": null,    "upload_date": [      2017,      4,      11,      12,      37,      0    ],

str = str:gsub("\"","\'"):gsub("|","&#124;")   --mw.logObject("STR: "..str)    mw.logObject(str:match("'title': '(.-)',"))    local title = str:match("'title': '(.-)',")    local titleRep = title:gsub(" ","&#32;"):gsub("%[","&#91;"):gsub("%]","&#93;"):gsub("%{","&#123;"):gsub("%}","&#125;"):gsub("|","&#124;")    local title_original = str:match("'title_original': '(.-)',")    local tags = str:match("'tags': %{(.-)%}")    --mw.logObject("TAGS: "..tags)    local tagsTab = {}    --local tags = tags:match("'(.-)': %[(.-)%],")

for k, v in string.gmatch(tags,"'.-': %[.-%]") do       local key = k:match("'(.-)': %[.-%]") local val = k:match("'.-': %[(.-)%]") val = val:gsub(\,"") valTab = {} --strSplit(val,",") local cnt = 0 local valStr = "" for k, v in string.gmatch(val,"'(.-)'") do           if (cnt == 0) then valStr = k               cnt = 1 else valStr = valStr .. ", " .. k           end --table.insert(valTab,k) end --mw.logObject("KEY: "..key.."\nVAL: "..val) --mw.logObject(valTab) tagsTab[key] = valStr end mw.logObject("TAGS TAB:") mw.logObject(tagsTab)

--NOW ASSEMBLE PARSED DATA INTO TABLE --MAKE TITLE CLICKABLE TO DIRECT SEARCH FOR TITLE https://exhentai.org/search= URLENCODE --MAKE ARTIST CLICKABLE https://exhentai.org/tag/artist:done

local table = "{| class='wikitable' style='margin: 15px; width: 600px;'\n" table = table .. "! colspan='2'| [https://exhentai.org/?f_search=&#34;".. titleRep .."&#34; ".. titleRep .." ] ".. title_original .." \n|-\n" if (tagsTab["group"]) then local groupRep = tagsTab["group"]:gsub("|","&#124;"):gsub(" ","&#32;"):gsub("%[","&#91;"):gsub("%]","&#93;"):gsub("%{","&#123;"):gsub("%}","&#125;"):gsub("|","&#124;") table = table .. "! scope='row' style='width: 66px;'| group\n" table = table .. "| [https://exhentai.org/?f_search=&#34;group:".. groupRep .."$&#34; ".. groupRep .." ]\n|-\n" end if (tagsTab["artist"]) then local artistRep = tagsTab["artist"] local artistTab = strSplit(artistRep,",|") local artistStr = "" local artistCnt = 0 for k, v in ipairs(artistTab) do           artistCnt = artistCnt + 1 if artistCnt > 1 then artistStr = artistStr .. ", "           end artistTab[k] = trim(v):gsub("|","&#124;"):gsub(" ","&#32;"):gsub("%[","&#91;"):gsub("%]","&#93;"):gsub("%{","&#123;"):gsub("%}","&#125;"):gsub("|","&#124;") artistStr = artistStr .. " [https://exhentai.org/tag/artist:".. artistTab[k] .." ".. artistTab[k] .." ]" end mw.logObject(artistStr) table = table .. "!scope='row'| artist\n" table = table .. "|" .. artistStr .. " \n|-\n"

end if (tagsTab["female"]) then table = table .. "! scope='row' style='width: 66px';| female\n" table = table .. "|"..tagsTab["female"].."\n|-\n" end if (tagsTab["male"]) then table = table .. "! scope='row' style='width: 66px';| male\n" table = table .. "|"..tagsTab["male"].."\n|-\n" end if (tagsTab["misc"]) then table = table .. "! scope='row' style='width: 66px';| misc\n" table = table .. "|"..tagsTab["misc"].."\n|-\n" end table = table .. "|}"   --mw.logObject(table)

--{| class="wikitable" style="margin-right: 15px; width: 600px;" --! colspan="2"|

--Kanji -- --|- --! scope="row" style="width: 66px;| Kana --|

return table end return p