Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function split(str, pat)
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- api="http://lyrics.wikia.com/api.php?artist=ARTISTHERE&song=SONGHERE"
- tArgs={ ... }
- function printUsage()
- rp=shell.getRunningProgram()
- print("Usage: "..rp.." <artist> <song>")
- end
- if #tArgs < 2 then
- printUsage()
- error()
- end
- api="http://lyrics.wikia.com/api.php?artist="..tArgs[1]:gsub("_","+").."&song="..tArgs[2]:gsub("_","+")
- site=http.get(api)
- if site then
- src=site.readAll()
- site.close()
- split1=split(src,"<pre>")
- split2=split(split1[2],"</pre>")
- lyrics=split2[1]
- lyrics=lyrics:gsub("'","'")
- term.clear()
- term.setCursorPos(1,1)
- print(tArgs[1].." - "..tArgs[2])
- textutils.slowPrint(lyrics)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement