Tag:[歌詞取得スクリプト]
<SiteTitle>Genius</SiteTitle> <SiteSearchURL>[TITLE] site:genius.com/</SiteSearchURL> <LuaScript> function LyricsInfoGet(html) --歌詞を取り出す is1, ie1 = html:find("<div data-lyrics-container=\"true\" class=\"Lyrics__Container", 1, true) --無いときは抜ける if is1 == nil then return "LYRICS=", "TITLE=", "ARTIST=" end --歌詞の終わりを見つける is2, ie2 = html:find("<div class=\"LyricsFooter__Container", ie1+1, true) lyrics = html:sub(is1, is2-1) --HTMLテキストのdiv,改行,ルビ等を消す --lyrics = lyrics:gsub("</p><p>", "<br><br>") --</p><p>は改行x2とする (歌詞ナビ) lyrics = lyrics:gsub("<div data%-lyrics%-container=\"true\" class=\"Lyrics__Container", "<br><div class=\"") -- class="Lyrics__Container区切り毎に改行を追加する(Genius) lyrics = lyrics:gsub("<div>", "") lyrics = lyrics:gsub("<div.->", "") lyrics = lyrics:gsub("</div>", "") lyrics = lyrics:gsub("\r\n", "") lyrics = lyrics:gsub("\n", "") lyrics = lyrics:gsub("<rt>.-</rt>", "") lyrics = lyrics:gsub("<span class=\"rt\">.-</span>", "") lyrics = lyrics:gsub("<rp>.-</rp>", "") lyrics = lyrics:gsub("<rb>", "") lyrics = lyrics:gsub("</rb>", "") lyrics = lyrics:gsub("<ruby>", "") lyrics = lyrics:gsub("</ruby>", "") lyrics = lyrics:gsub("<span.->", "") lyrics = lyrics:gsub("</span>", "") lyrics = lyrics:gsub("<!\-\-.-\-\->", "") lyrics = lyrics:gsub("<a .->", "") lyrics = lyrics:gsub("</a>", "") lyrics = lyrics:gsub("<p>", "") lyrics = lyrics:gsub("</p>", "") lyrics = lyrics:gsub("<font .->", "") lyrics = lyrics:gsub("</font>", "") lyrics = lyrics:gsub("<big>", "") lyrics = lyrics:gsub("</big>", "") lyrics = lyrics:gsub("<small>", "") lyrics = lyrics:gsub("</small>", "") lyrics = lyrics:gsub("<b>", "") lyrics = lyrics:gsub("</b>", "") lyrics = lyrics:gsub("<i>", "") lyrics = lyrics:gsub("</i>", "") lyrics = lyrics:gsub("<s>", "") lyrics = lyrics:gsub("</s>", "") lyrics = lyrics:gsub("<strike>", "") lyrics = lyrics:gsub("</strike>", "") lyrics = lyrics:gsub("<u>", "") lyrics = lyrics:gsub("</u>", "") lyrics = lyrics:gsub("<tt>", "") lyrics = lyrics:gsub("</tt>", "") lyrics = lyrics:gsub("<em>", "") lyrics = lyrics:gsub("</em>", "") lyrics = lyrics:gsub("<strong>", "") lyrics = lyrics:gsub("</strong>", "") lyrics = lyrics:gsub("<sup>", "") lyrics = lyrics:gsub("</sup>", "") lyrics = lyrics:gsub("<sub>", "") lyrics = lyrics:gsub("</sub>", "") lyrics = lyrics:gsub("<blockquote>", "") lyrics = lyrics:gsub("</blockquote>", "") lyrics = lyrics:gsub("<q>", "") lyrics = lyrics:gsub("</q>", "") lyrics = lyrics:gsub("<pre>", "") lyrics = lyrics:gsub("</pre>", "") lyrics = lyrics:gsub("<code>", "") lyrics = lyrics:gsub("</code>", "") lyrics = lyrics:gsub("<aside.->.-</aside>", "") lyrics = lyrics:gsub("^%[.-%]<br%s?/?>", "") --コーラス等の補足情報を削除(Genius) lyrics = lyrics:gsub("<br%s?/?>%[.-%]<br%s?/?>", "<br>") --コーラス等の補足情報を削除(Genius) --<br />を改行にする lyrics = lyrics:gsub("<br%s?/?>", "\r\n") --行末の空白文字を削除 lyrics = lyrics:gsub("[ ]+\r\n", "\r\n") --行頭と行末の空白改行を削除 lyrics = lyrics:gsub("^%s+", "") lyrics = lyrics:gsub("%s+$", "") --特殊文字 lyrics = lyrics:gsub("<", "<") lyrics = lyrics:gsub(">", ">") lyrics = lyrics:gsub(" ", " ") lyrics = lyrics:gsub(""", "\"") lyrics = lyrics:gsub("&", "&") while true do is1, ie1, base16, code = lyrics:find("&#(x?)(%d+);") if is1 == nil then break end base = 10 if base16 == "x" then base = 16 end lyrics = lyrics:sub(1, is1-1) .. string.char(tonumber(code,base)) .. lyrics:sub(ie1+1) end --タイトルを取り出す title = html:match("{\"name\":\"song_title\",\"values\":%[\"(.-)\"%]}") --特殊文字 title = title:gsub("<", "<") title = title:gsub(">", ">") title = title:gsub(" ", " ") title = title:gsub(""", "\"") title = title:gsub("&", "&") while true do is1, ie1, base16, code = title:find("&#(x?)(%d+);") if is1 == nil then break end base = 10 if base16 == "x" then base = 16 end title = title:sub(1, is1-1) .. string.char(tonumber(code,base)) .. title:sub(ie1+1) end --アーティスト名を取り出す artist = html:match("{\"name\":\"artist_name\",\"values\":%[\"(.-)\"%]}") --特殊文字 artist = artist:gsub("<", "<") artist = artist:gsub(">", ">") artist = artist:gsub(" ", " ") artist = artist:gsub(""", "\"") artist = artist:gsub("&", "&") while true do is1, ie1, base16, code = artist:find("&#(x?)(%d+);") if is1 == nil then break end base = 10 if base16 == "x" then base = 16 end artist = artist:sub(1, is1-1) .. string.char(tonumber(code,base)) .. artist:sub(ie1+1) end return "LYRICS="..lyrics, "TITLE="..title, "ARTIST="..artist end </LuaScript> |