Module:AlbumParam

-- Implements the album parameter of Template:Rip -- Written by Ironwestie local p = {} --checks if a string has any link syntax local function hasLinkSyntax(str) if string.match(str, "%[") or string.match(str,"%]") then return true else return false end end -- remove trailing and leading whitespace from string. -- ref: http://lua-users.org/wiki/CommonFunctions -- https://en.wikipedia.org/wiki/Trim_(programming) local function trim(s) -- from PiL2 20.4 return (s:gsub("^%s*(.-)%s*$", "%1")) end --ref from https://stackoverflow.com/questions/1426954/split-string-in-lua local function split(inputstr, sep) if sep == nil then sep = ";" --for the purposes of this wiki, we assume that the delimiter is a ; end local t={}; if string.find(inputstr,sep) ~= nil then for str in string.gmatch(inputstr, "([^"..sep.."]+)") do           table.insert(t,trim(str)) end else table.insert(t,inputstr) end return t end -- recursively ensures that there is only ever at most one "-" between words (i.e. "--" never appears) local function removeDupDash(str) if str:find("%-%-") == nil then return str else return removeDupDash(str:gsub("%-%-","-")) end end local function transform(str) assert (str, 'str must exist') local result = 'https://gilvasunner.bandcamp.com/album/' if str == "" then return str elseif str:find("【") then return "https://gilvasunner.bandcamp.com/album/silva-gunner-best-of-soundtrack-b-w" elseif str:find("KORIBALL")then return "https://giivasunner.bandcamp.com/album/koriball" elseif str:find(".veg") then return "https://gilvasunner.bandcamp.com/album/the-siivagunner-ytpmv-collab-eek-veg" elseif str:find("SiIVa has come to") then return "https://www.youtube.com/playlist?list=PLL0CQjrcN8D2LpKwfEONnKzirIsWLZBQo" elseif str:find("UnregisteredHyperCam2.FullAlbum") then return "https://gilvasunner.bandcamp.com/album/2018-unregisteredhypercam2-fullalbum-xvid-kfad-320kbps-cdrip" elseif str:find("The Space Jam Charity SLAM!: First Quarter")then return "https://giivasunner.bandcamp.com/album/the-space-jam-charity-slam-first-quarter" elseif str:find("B-Ball Side")then return "https://giivasunner.bandcamp.com/album/the-space-jam-charity-slam-b-ball-side" else --makes all characters lowercase str = str:lower --removes all characters not alphanumeric or "-", "/" or "&" str = str:gsub("[^%w%s%-/&]","") --           str = str:gsub("%p","") --replaces "/" and "&"'s with "-"s str = str:gsub("[&/]","-") --replaces all spaces with "-"s str = str:gsub("%s","-") --ensures that there is only ever at most one "-" between words str = removeDupDash(str) return result .. str end end

-- format album links local function link_label(str) assert (str, 'str must exist') str = tostring(str)

if (not str or str == "") then return str end

local label_map = { ["."] = "-|.",       ["-"] = "-|.",        ["The Phantom Rips: SiIVa has come to"] = ":Category:The Phantom Rips: SiIVa has come to|The Phantom Rips: SiIVa has come to", ["2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps(CDRip)"] = "2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps(CDRip)|2018.&shy;Unregistered&shy;HyperCam&shy;2.&shy;Full&shy;Album.&shy;XviD.&shy;KfaD.&shy;320&shy;kbps&shy;&#91;CDRip&#93;", ["2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps[CDRip]"] = "2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps(CDRip)|2018.&shy;Unregistered&shy;HyperCam&shy;2.&shy;Full&shy;Album.&shy;XviD.&shy;KfaD.&shy;320&shy;kbps&shy;&#91;CDRip&#93;", ["2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps&#91;CDRip&#93;"] = "2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps(CDRip)|2018.&shy;Unregistered&shy;HyperCam&shy;2.&shy;Full&shy;Album.&shy;XviD.&shy;KfaD.&shy;320&shy;kbps&shy;&#91;CDRip&#93;", ["SiIvaGunner's Highest Quality Rips: Volume L (Side A)"] = "SiIvaGunner's Highest Quality Rips: Volume L (Side A)|SiIvaGunner's Highest Quality Rips: Volume L &#91;Side A&#93;", ["SiIvaGunner's Highest Quality Rips: Volume L [Side A]"] = "SiIvaGunner's Highest Quality Rips: Volume L (Side A)|SiIvaGunner's Highest Quality Rips: Volume L &#91;Side A&#93;", ["SiIvaGunner's Highest Quality Rips: Volume L &#91;Side A#93;"] = "SiIvaGunner's Highest Quality Rips: Volume L (Side A)|SiIvaGunner's Highest Quality Rips: Volume L &#91;Side A&#93;", ["SiIvaGunner's Highest Quality Rips: Volume L (Side B)"] = "SiIvaGunner's Highest Quality Rips: Volume L (Side B)|SiIvaGunner's Highest Quality Rips: Volume L &#91;Side B&#93;", ["SiIvaGunner's Highest Quality Rips: Volume L [Side B]"] = "SiIvaGunner's Highest Quality Rips: Volume L (Side B)|SiIvaGunner's Highest Quality Rips: Volume L &#91;Side B&#93;", ["SiIvaGunner's Highest Quality Rips: Volume L &#91;Side B#93;"] = "SiIvaGunner's Highest Quality Rips: Volume L (Side B)|SiIvaGunner's Highest Quality Rips: Volume L &#91;Side B&#93;", ["Sensational Celebrations ~ The SiIvaSummer All-Star Festival Collection (Event Side)"] = "Sensational Celebrations ~ The SiIvaSummer All-Star Festival Collection (Event Side)|Sensational Celebrations ~ The SiIvaSummer All-Star Festival Collection &#91;Event Side&#93;", ["Sensational Celebrations ~ The SiIvaSummer All-Star Festival Collection [Event Side]"] = "Sensational Celebrations ~ The SiIvaSummer All-Star Festival Collection (Event Side)|Sensational Celebrations ~ The SiIvaSummer All-Star Festival Collection &#91;Event Side&#93;", ["Sensational Celebrations ~ The SiIvaSummer All-Star Festival Collection &#91;Event Side&#93;"] = "Sensational Celebrations ~ The SiIvaSummer All-Star Festival Collection (Event Side)|Sensational Celebrations ~ The SiIvaSummer All-Star Festival Collection &#91;Event Side&#93;", ["Bloodstained Bounties ~ The SiIvaGunner All-Star Summer Festival 2021 Collection (Event Side)"] = "Bloodstained Bounties ~ The SiIvaGunner All-Star Summer Festival 2021 Collection (Event Side)|Bloodstained Bounties ~ The SiIvaGunner All-Star Summer Festival 2021 Collection &#91;Event Side&#93;", ["Bloodstained Bounties ~ The SiIvaGunner All-Star Summer Festival 2021 Collection [Event Side]"] = "Bloodstained Bounties ~ The SiIvaGunner All-Star Summer Festival 2021 Collection (Event Side)|Bloodstained Bounties ~ The SiIvaGunner All-Star Summer Festival 2021 Collection &#91;Event Side&#93;", ["Bloodstained Bounties ~ The SiIvaGunner All-Star Summer Festival 2021 Collection &#91;Event Side&#93;"] = "Bloodstained Bounties ~ The SiIvaGunner All-Star Summer Festival 2021 Collection (Event Side)|Bloodstained Bounties ~ The SiIvaGunner All-Star Summer Festival 2021 Collection &#91;Event Side&#93;" }

if label_map[str] then str = label_map[str] end return str end

-- formats a string of album names into something like: -- Album_name , local function format_param(str) assert (str, 'str must exist') local result = "" if (str == "") then return str end t = split(str,";") local site for index,value in ipairs(t) do        site = "Bandcamp" if value:find("SiIVa has come to") ~= nil then -- if this is any of the albums not listed on Bandcamp site = "YouTube" end if (index > 1) then -- if this isn't the first album listed result = result .. ", "       end result = result .. string.format("%s ",link_label(value),site,transform(value)) end return result end

local function format_into_list(str) assert(str, 'str must exist') local result = "" if (str == "") then return str end t = split(str,";") for index,value in ipairs(t) do       if (index > 1) then -- if this isn't the first item listed result = result .. ", "       end result = result .. string.format("%s", value) end return result end -- implements automatic categorization local function categorize(str) assert (str, "str must exist") t = split(str,";") local result = "" if (str == "") then return str end for index, value in ipairs(t) do      result = result .. string.format("",value) end return result end -- puts categories on the bottom of the page. assumes delimiter is ";". function p.categorize(frame) local str = frame.args[1] --if there's any link syntax, then we override the transform function if hasLinkSyntax(str) then return "" elseif pcall(function result = categorize(str) end) then return frame:preprocess(result) else return frame:preprocess(str .. "") end end -- calls transform; can be called from an invoke -- function p.transform(frame) local str = frame.args[1] --if there's any link syntax, then we override the transform function if hasLinkSyntax(str) then return str elseif pcall(function result = transform(str) end) then return frame:preprocess(result) else return frame:preprocess(str .. "") end end

-- makes a comma-separated list out of a string with a ";" as its delimiter function p.list(frame) local str = frame.args[1] --if there's any link syntax, then we override the function if hasLinkSyntax(str) then return str elseif pcall(function result = format_into_list(str) end) then return frame:preprocess(result) else return frame:preprocess(str .. "") end end

-- fully transforms album. -- function p.main(frame) local str = frame.args[1] --if there's any link syntax, then we override the main function if hasLinkSyntax(str) then return str elseif pcall(function result = format_param(str) end) then return frame:preprocess(result) else return frame:preprocess(str .. "") end end return p