Tuesday, 16 March 2021

function findLiveStreamVideoId(channelId, cb){ $.ajax({ url: 'https://www.youtube.com/channel/'+channelId, type: "GET", headers: { 'Access-Control-Allow-Origin': '*', 'Accept-Language': 'en-US, en;q=0.5' }}).done(function(resp) { //one method to find live video let n = resp.search(/\{"videoId[\sA-Za-z0-9:"\{\}\]\[,\-_]+BADGE_STYLE_TYPE_LIVE_NOW/i); //If found if(n>=0){ let videoId = resp.slice(n+1, resp.indexOf("}",n)-1).split("\":\"")[1] return cb(videoId); } //If not found, then try another method to find live video n = resp.search(/https:\/\/i.ytimg.com\/vi\/[A-Za-z0-9\-_]+\/hqdefault_live.jpg/i); if (n >= 0){ let videoId = resp.slice(n,resp.indexOf(".jpg",n)-1).split("/")[4] return cb(videoId); } //No streams found return cb(null, "No live streams found"); }).fail(function() { return cb(null, "CORS Request blocked"); }); }

0 comments:

Post a Comment