利用 PhantomJS 获取抖音直播的直播源

2021-03-04 08:28

阅读:747

标签:else   抖音   ike   ESS   格式   cti   获取   ora   ons   

用手机把直播分享,把直播链接URL带进参数

PhantomJS.exe DYLive.js [直播URL]

如果获取成功返回m3u8格式的地址以及姓名和ID

var page = require(‘webpage‘).create(),
system = require(‘system‘),
address;
if (system.args.length === 1) {
    console.log(‘Usage: DYLiveURL.js [URL]‘);
    phantom.exit();
}

address = system.args[1];

page.settings.userAgent = ‘Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25‘;

page.viewportSize = {
    width: 540,
    height: 960
};

page.open(address, function (status) {
    if (status === "success") {
        var ret = page.evaluate(function () {
                var userName = document.querySelector(‘.user-name‘).innerHTML;
                var emojiReg = /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/gi;
                userName = userName.replace(emojiReg,‘‘);

                var userID = document.querySelector(‘.info-id‘).innerHTML;
                var regex = /[0-9a-zA-Z_.]{4,}/gi;
                userID =userID.match(regex);
                var video = document.querySelectorAll(‘#theVideo‘);
                if (video.length == 0)
                    return 0;
                else
                    return video[0].outerHTML + ‘ LIVE_UN‘ + userName + ‘LIVE_UN‘ +
                                                ‘ LIVE_ID‘ + userID + ‘LIVE_ID‘;
            });
        if (ret == 0)
            console.log(‘NotFind‘);
        else {
            var regex = /(https|http).*?(?=\"|\"\)|\))/gi;
            var liveURL = ret.match(regex);
                regex = /(LIVE_UN).*?(LIVE_UN)/gi;
            var userName = ret.match(regex);
                regex = /(LIVE_ID).*?(LIVE_ID)/gi;
            var userID = ret.match(regex);

            console.log(liveURL);
            console.log(userName);
            console.log(userID);
        }
    }
    phantom.exit();
});

 

利用 PhantomJS 获取抖音直播的直播源

标签:else   抖音   ike   ESS   格式   cti   获取   ora   ons   

原文地址:https://www.cnblogs.com/nlsoft/p/13264220.html


评论


亲,登录后才可以留言!