SiIvaGunner Wiki
Advertisement
SiIvaGunner Wiki

Documentation for this module may be created at Module:AlbumParam/doc

-- 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"
        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 = {
        ["."] = "-|.",
        ["-"] = "-|.",
        ["2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps(CDRip)"] = "2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps(CDRip)|2018.­Unregistered­HyperCam­2.­Full­Album.­XviD.­KfaD.­320­kbps­[CDRip]",
        ["2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps[CDRip]"] = "2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps(CDRip)|2018.­Unregistered­HyperCam­2.­Full­Album.­XviD.­KfaD.­320­kbps­[CDRip]",
        ["2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps[CDRip]"] = "2018.UnregisteredHyperCam2.FullAlbum.XviD.KfaD.320kbps(CDRip)|2018.­Unregistered­HyperCam­2.­Full­Album.­XviD.­KfaD.­320­kbps­[CDRip]",
        ["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 [Side A]",
        ["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 [Side A]",
        ["SiIvaGunner's Highest Quality Rips: Volume L [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 (Side B)"] = "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 [Side B]"] = "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 [Side B#93;"] = "SiIvaGunner's Highest Quality Rips: Volume L (Side B)|SiIvaGunner's Highest Quality Rips: Volume L [Side B]",
        ["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 [Event Side]",
        ["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 [Event Side]",
        ["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 [Event Side]"
    }

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

-- formats a string of album names into something like:
-- ''[[Album_name]]'' ({{Icon|<site>|2={{{album}}}}}),
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]]'' ({{Icon|%s|2=%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("[[Category:%s]]",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 .. "[[Category:Pages with script errors]]")
    end
end
 
-- calls transform; can be called from an invoke
-- {{#invoke:AlbumParam|transform}}
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 .. "[[Category:Pages with script errors]]")
    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 .. "[[Category:Pages with script errors]]")
    end
end

-- fully transforms album.
-- {{#invoke:AlbumParam|main|{{{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 .. "[[Category:Pages with script errors]]")
    end
end
return p
Advertisement