Module:SongsInAnime

-- Module Name: Songs In Anime -- Author: 机智的小鱼君 -- Description: --- All the music that appears in the animation --- can be queried using this module. --- To complete the songs information, please go to Module:SongsInAnime/table local p = {} local getArgs = require('Module:Arguments').getArgs local util = require('Module:Util') local songsTable = require('Module:SongsInAnime/table') -- Find songs used in anime function p.anime(frame) local args = getArgs(frame) local episode = args['episode'] or args[1] -- 参数错误 if episode == nil then return 'Module:SongsInAnime error：No episode given.' end local songs = songsTable[episode] -- 没有该集信息 if songs == nil then return 'Attention: There\'s no episode named ' .. episode .. '！' end -- 没有音乐 if util.tableLength(songs) < 1 then return ' Can\'t find song information about ' .. episode .. '.' end -- 创建列表 local text = 'Episode ' .. episode .. ' used following musics: ' for k, v in pairs(songs) do   local time = k    local endtime = songs[k]['endtime'] or '' if endtime ~= '' then time = time .. '-' .. endtime end local song = songs[k]['song'] local description = songs[k]['description'] or '' text = text .. '' .. time .. ' ' ..                song .. '  ' .. description .. '' end -- 结束，返回列表 text = text .. '' return text end -- Find animes used the song function p.song(frame) local args = getArgs(frame) local song = args['song'] or args[1] -- 参数错误 if song == nil then return 'Module:SongsInAnime error: No song name given.' end -- 初始化表 local episodes = {} -- 遍历剧集 for k1, v1 in pairs(songsTable) do   local thisEp = k1 -- 本次遍历的剧集名称 local thisEpTable = songsTable[k1] -- 本次遍历的剧集的表 -- 遍历时间节点 for k2, v2 in pairs(thisEpTable) do     local thisTime = k2 -- 本次遍历的时间 local thisTimeTable = thisEpTable[k2] -- 本次遍历的时间的表 local thisSong = thisTimeTable['song'] -- 本次遍历的时间的音乐名 -- 如果该时间节点的音乐名就是比对的音乐名 if thisSong == song then -- 本集的表若不存在，先建立表 if type(episodes[thisEp]) == 'nil' then episodes[thisEp] = {} end -- 将本时间节点的表插进表 episodes[thisEp][thisTime] = thisTimeTable end end end -- 没有剧集使用该音乐 if util.tableLength(episodes) < 1 then return 'Attention: No animate episodes using ' .. song .. '. ' end -- 创建列表 local text = 'Music ' .. song .. ' using in the following animate episodes:' -- 遍历表 for k1, v1 in pairs(episodes) do   local episode = k1 -- 本次遍历的剧集 -- 遍历时间 for k2, v2 in pairs(episodes[episode]) do     local time = k2 -- 本次遍历的时间 local description = episodes[episode][k2]['description'] local endtime = episodes[episode][k2]['end'] or '' if endtime ~= '' then time = time .. '-' .. endtime end text = text .. '' ..             episode ..                '' .. ' ' ..                   ' ' ..                      time .. ' <i class="song-description">' .. description .. '</i></li>' end end -- 结束，返回列表 text = text .. '</ul>' return text end function p.main return 'Module:SongsInAnime info: \n*  Display a list of songs that the episode are using.\n*   Display a list of episodes that using the song.' end return p