Module:Sandbox/The JoTS/ProfileMusic

-- User Profile Random Music (v1.1.1) -- Because screw autoplaying music of the same song. Every. Single. Time. -- By "The JoTS"

-- v1.1, link to song for wikis w/o w:c:YouTubeAudio (or not using a mobile device)

-- local type = { CHIPTUNE = 0, GAME_OST = 1, MASHUP = 2  } local mood = {} -- To be implemented. Maybe.

local source = { ["plvpwaa"] = { name     = "Professor Layton vs. Phoenix Wright: Ace Attorney", link     = "w:c:aceattorney:Professor Layton VS Gyakuten Saiban Magical Mystery Music", release  = "2013", mediatype = type.GAME_OST },

["sonicmania"] = { name = "Sonic Mania", link = "w:c:sonic:Sonic Mania", release = "2017", mediatype = type.GAME_OST },

["pmd_eot"] = { name = "Pokémon Mystery Dungeon: Explorers of Time", link = "w:c:pokemon:Pokémon Mystery Dungeon: Explorers of Time & Explorers of Darkness", release = nil, mediatype = type.CHIPTUNE },

["pkmn_rse"] = { name = "Pokémon Ruby / Sapphire / Emerald", link = "w:c:pokemon:Pokémon Ruby and Sapphire Version", release = nil, mediatype = type.CHIPTUNE },

["advancewars2"] = { name = "Advance Wars 2: Black Hole Rising", link = "w:c:advancewars:Advance Wars 2: Black Hole Rising", release = nil, mediatype = type.CHIPTUNE },

["ghosttrick"] = { name = "Ghost Trick: Phantom Detective", link = "w:c:ghosttrick:Ghost Trick Original Sound Track", release = "2010", mediatype = type.CHIPTUNE },

["dronpa"] = { name = "Danganronpa: Trigger Happy Havoc", link = "w:c:danganronpa:Danganronpa: Trigger Happy Havoc (Original Soundtrack)", release = nil, mediatype = type.GAME_OST },

["chronocross"] = { name = "Chrono Cross", link = nil, release = nil, mediatype = type.CHIPTUNE },   ["daigyakuten"] = { name = "Dai Gyakuten Saiban: Naruhodō Ryūnosuke no Bōken", link = "w:c:aceattorney:Dai Gyakuten Saiban", release = "2015", mediatype = type.GAME_OST },

["daigyakuten2"] = { name = "Dai Gyakuten Saiban 2: Naruhodō Ryūnosuke no Kakugo", link = "w:c:aceattorney:Dai Gyakuten Saiban 2: Naruhodō Ryūnosuke no Kakugo", release = "2017", mediatype = type.GAME_OST },

["traumacenterwii"] = { name = "Trauma Center: Second Opinion", link = nil, release = nil, mediatype = type.GAME_OST },   ["traumacenter"] = { name = "Trauma Center: Under the Knife", link = nil, release = nil, mediatype = type.CHIPTUNE },

["traumacenter2"] = { name = "Trauma Center: Under the Knife 2", link = nil, release = nil, mediatype = type.CHIPTUNE },

["traumateam"] = { name = "Trauma Team", link = nil, release = nil, mediatype = type.GAME_OST },

["traumacenternb"] = { name = "Trauma Center: New Blood", link = nil, release = nil, mediatype = type.GAME_OST } }

local songs = { [source.plvpwaa] = { {"h3Ysg4Tlu-4", "Puzzle Deductions"}, {"R7czv7Ij3iM",  "Trial of the Great Witch"} },   [source.sonicmania] = { {"WxIElxztRk", "Flying Battery Zone, Act 1"}, {"YJG5FZDun9I", "Hydrocity Zone, Act 2"} },   [source.pmd_eot] = { {"ZEL3__eZIuA", "Temporal Tower"} },   [source.pkmn_rse] = { {"7vif4oZGnH0", "Mt. Pyre Outer Wall"} },

[source.advancewars2] = { {"EPjkLIcyEcc", "Black Hole Super CO Power"}, {"JsEnlbZunzE", "Sturm's Theme"} },   [source.ghosttrick] = { {"wwC2PVgufLk", "A Dashing Enigma"}, {"ywz-aGga0qU", "AWAKENING"}, {"8W8xu_pxgP0", "CHASE"}, {"8lO1GurMClg", "Dead Afterimage"}, {"ZcG5OeQg9S0", "Jowd ~ A Captive of Fate"}, {"p63H1Gy4-DM", "The Imprisoned"}, {"VHLKzQB7irk", "TRAUMA"}, {"mT9vFqZHGD4", "Unused Track #5"}, },   [source.dronpa] = { {"xOpHT6gZ0Rs", "BOX 15"}, {"rKVty1HGvx8", "Weekly Despair Magazine"}, {"xKSRb0y6Lb8", "Class Trial Solar Edition"}, {"m3EHCTP3jic", "New World Order"}, },   [source.chronocross] = { {"H-IJV93FQZc", "Dragon God"}, },   [source.daigyakuten] = { {"JUVlITp3qj0", "Pursuit ~ Time for a Great Turnabout"}, {"VSg-arCwnGQ", "Naruhodou Ryuunosuke ~ Objection!"} },

[source.daigyakuten2] = { {"OWiejCtmgmM", "Pursuit ~ The Great Turnabout 2017"} },   [source.traumacenterwii] = { {"okxgCNFav30", "Second Opinion"}, {"qr2R387hyHI", "St. Francis Hospital"}, {"fimZIwYgKzQ", "A Savior's Forthcoming"}, {"11cvXLY7vOE", "Vulnerability"} },

[source.traumacenter] = { {"ULKvwNBvD4w", "System: Opening"}, {"tS1vYQrPl9s", "Large Map 2 - Last Half"}, {"0N2bmR_YGyo", "Ending"} },

[source.traumacenter2] = { {"qCAu8Zm-ZV8", "Gentle Breeze"}, {"sVHSntwaDIM", "Doctors on Duty"}, {"fC0jbgNdea4", "Darkness Sets In"}, {"pcYEEhqgdVs", "Unfaltering Hands"}, {"JtbFa0Gb3gs", "Confronting the Menace"}, {"0M0IRuLiqYA", "Severing the Chains of Fate"}, },

[source.traumateam] = { {"FsrcD74oz5M", "Bloody Rose"} },

[source.traumacenternb] = { {"OLJucAGWT-A", "Pleasant Day"}, {"ZynYKnrOqh8", "Warning"}, {"bC0acSL_U88", "Bad News"}, {"8RMT2IUXt6A", "Life at Stakes"}, {"PcGjQQg5ZhM", "Miracle Surgery!"}, --     {"3xCyEE-Nvg0", "Awakening"} } }

local make = { table = function(str, frame) return frame:preprocess("{| class=articletable \n" .. str .. "\n|}") end, row = function(str, title) return (title and "!" or "|") .. str .. "\n|-\n" end, link = function(str, link, out) return link and (               out and ("[" .. link .. " " .. str .. "]")               or ("" .. str .. "")            ) or str end }

return { main = function(frame) local ostOrder = {} local nSongs = 0 -- Gather collection info for ost,soundtracks in pairs(songs) do           local n = #soundtracks nSongs = nSongs + n           table.insert(ostOrder, ost) end mw.log("Number of songs: " .. tostring(nSongs)) -- Choose song & find math.randomseed(os.time) local rIndex, sum, currOst = math.random(1, nSongs), 0 for i = 1, #ostOrder do           currOst = ostOrder[i] local newSum = sum + #songs[currOst] if newSum >= rIndex then break end sum = newSum end -- Generate song widget local selectedSong = songs[currOst][rIndex -sum] local songWidget, footer = " " .. selectedSong[1] .. " ",           " • [ (new song)]" return frame and make.table(           make.row('"' .. selectedSong[2] .. '"', true) ..            make.row("''" .. make.link(               currOst.name .. (currOst.release and (' (' .. currOst.release .. ')') or ""),               currOst.link) .. "''") ..           make.row(songWidget .. make.link("(song src)",                   "https://youtu.be/" .. selectedSong[1],                    true                ) .. footer )      , frame) end,

list = function end }