Created
August 29, 2019 08:33
-
-
Save chenxuuu/672ba390c9968c99e2fbec4f9a89d15e to your computer and use it in GitHub Desktop.
youtube live check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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