Skip to content

Instantly share code, notes, and snippets.

@chenxuuu
Created August 29, 2019 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenxuuu/672ba390c9968c99e2fbec4f9a89d15e to your computer and use it in GitHub Desktop.
Save chenxuuu/672ba390c9968c99e2fbec4f9a89d15e to your computer and use it in GitHub Desktop.
youtube live check
package.path = package.path..";/www/wwwroot/tcy2b.papapoi.com/?.lua"
json = require("JSON")
channel = ngx.req.get_uri_args()["c"]
if not channel then ngx.say(json:encode({error = "no c found"})) return end
hc = require('httpclient').new()
res = hc:get("https://www.youtube.com/channel/"..channel.."/live")
if not res.body then ngx.say(json:encode({error = res.err})) return end
if ngx.req.get_uri_args()["debug"] == "on" then
ngx.say(res.body)
return
end
local ytplayer_config = res.body:match("ytplayer.config *= *(.-});")
if not ytplayer_config then ngx.say(json:encode({error = "no this channel"})) return end
local info = json:decode(json:decode(ytplayer_config)['args']['player_response'])
local result = {}
result.live = info.videoDetails.isLive
result.title = info.videoDetails.title
result.url = "https://youtu.be/"..info.videoDetails.videoId
result.thumbnail = info.videoDetails.thumbnail.thumbnails[#info.videoDetails.thumbnail.thumbnails].url
result.channel = info.videoDetails.channelId
ngx.say(json:encode(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment