播放直播的一种技术配置——ffplayer,python,iis,win7

本文介绍了如何在Windows 7上利用内置的IIS服务器和Python脚本,解决加密直播地址的问题,实现ffplayer播放。通过IIS作为中间层,动态获取并映射加密的直播链接,以绕过wsSecret和wsTime的限制。同时,文章提到了通过修改已有的Python脚本,并使用Chrome浏览器的特殊启动参数来解决跨域问题,以便于在PC上观看Huya等平台的直播电影。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先以前写的文章中有,有配置在浏器中直接打开自定的外部链接调用,系统程序的配置方法。这在win7,ubuntu下我都配置成功了。这样的好处是播放相当流畅,因为没有垃圾代码占用系统资源。但公开的直播链接地址不好找啊。都才用了一些加密的方法,不让用户不经过他们的 方式得到视频流地址,比如 虎牙直播的电影,以前是可以直接得到地址的,现在地址中加了:

【周星星】精彩无间断 ,http://bd.hls.huya.com/src/94525224-2460685313-10568562945082523648-2789274524-10057-A-0-1_2500.m3u8?wsSecret=82d460f856a9703e6188e92d8c2bccf4&wsTime=5e5f2954

由于wsSecret与wsTime是打开直播间时生成的,每次打开直播音这两个值都会变。这样链接地址就不能做成静态网页让手机,或调用FFPLayer播放。因为在实测,播放中wsSecret与wsTime并不会经 经常变动。所以用win7自,带的IIS做中传把python生成的直播地址,直接映射。是这种加密直播直址的一种解决方法。

因为已经做了haya直播地址,提取的python脚本,略改一下,  让IIS通过CGI自动调用。就可以实现了。

实测中发现有的直播间,定时10左右,改变wsSecret与wsTime。这样的话这个方法就不太实用了。但有的直播间这 两个值是不变的。变的就要通过防问地址重定向了。这个要做python代码,还没实现,因没电 脑端通过直播间还是比较方便的看到这些直播电影,做代码的动力不强。有空的话就计划把这完成。

还有一种一种用网页内JS实现的方式。这种通过JS取得直播地址的方式因为要用JS跨域访问,所以要用特别的方式调用游览器。比如用chrome时要用如下的方式调用:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --args --disable-web-security  --user-data-dir=D:\MyChromeDevUserData --user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_2 like Mac OS X) AppleWebKit/605.1.15" "http://localhost/huya-js.html"

这个是真对跨域访问问题的,一个是因为要访问m3u8格式真播要用的移动端的user-agent。实测是有用的。如下内容就是huya-js.html真接打开文件或通过IIS都可以。加"openffplay://"是因我PC上设定了调用openffplay的外部调用。如果没设置就要手工copy地址给VLC之类的用。VLC有user-agent问题 ,openffplay调用时可以设置user-agent。

<!DOCTYPE Video-HLS-m3u8>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.5, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes"/>
</head>
<TITLE>js视频huya</TITLE>
<body>
<DT><H3>js视频直播huya</H3></DT>
<p id="ipready"></p>

<script>

 var browser={
 versions:function(){
 var u = navigator.userAgent, app = navigator.appVersion;
 return {
 trident: u.indexOf('Trident') > -1, //IE内核
 webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
 mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
 mac: u.indexOf('Mac OS X') > -1, //Mac终端
 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
 android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
 iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone 
 iPad: u.indexOf('iPad') > -1, //是否iPad
 };
 }(),
 language:(navigator.browserLanguage || navigator.language).toLowerCase()
 };
 function offplayadd(){
 //if(browser.versions.mobile){
    //}else
    {
/*        if(browser.versions.mac){
             var div = document.getElementById("divMain");
       var linkTmp = document.createElement("a");
       linkTmp.href = "./v-huya.xspf";
       linkTmp.innerText = "vlc的播放列表文件"; 
       //链接要使用innertText,不能使用value
       div.appendChild(linkTmp);
    }
        else{    */    
        var mylinks = document.links;
        for(var i=0;i <mylinks.length;i++){
        mylinks[i].href="openffplay://"+mylinks[i].href;
        }
//}
    }
}


function huya2video(){
var httpRequest = null;
if (window.XMLHttpRequest) {  
  httpRequest = new XMLHttpRequest();  
  //针对某些特定版本的mozillar浏览器的BUG进行修正  
  if (httpRequest.overrideMimeType) {  
                    httpRequest.overrideMimeType("text/xml");  
  }  

if (httpRequest != null) { 
  httpRequest.open("GET", "http://m.huya.com/g/seeTogether", false); 
    httpRequest.send();
    var html1 =  httpRequest.responseText;
/*    var result = [];
    html1.replace(/<a([^<>]*)>/g, function(){
        result.push(arguments[1]);
        return arguments[0];
    });
*/
    var obj = document.createElement("div");
    obj.innerHTML = html1;
    var arr = obj.getElementsByTagName("a");
    var L=0;
    for(var i = 0, len = arr.length; i < len; i++){
        //if(arr[i].getAttribute("class")=="title new-clickstat j_live-card"){
        if(arr[i].getAttribute("class")=="clickstat g-link"){
              L=L+1;
              //if(L>5) break;
                //console.log(arr[i].getAttribute("title"));
                var urlroom=arr[i].getAttribute("href");
                httpRequest.open("GET", urlroom, false); 
          httpRequest.send();
          var htmlroom =  httpRequest.responseText;
          where1 = htmlroom.indexOf('<video');
                where2 = htmlroom.indexOf('</video>');
                textvideo=htmlroom.substring(where1,where2);
                where1 = textvideo.indexOf('src=');
                where2 = textvideo.indexOf('data-setup=');
                urlvideo=textvideo.substring(where1+5,where2-2);
                    
                var Edt = document.createElement("dt");
                document.body.appendChild(Edt);    
                var Ea1 = document.createElement("a");
                Ea1.href =urlvideo;
                //Ea1.innerText =arr[i].getAttribute("title");
                //Ea1.innerText =arr[i].getElementsByTagName("p").innerText;
                //videotitle=arr[i].innerText;
                where1 = htmlroom.indexOf('<div class="video_hd_title">');
                where2 = htmlroom.indexOf('<div class="video_hd_viewer">');
                videotitle=htmlroom.substring(where1+28,where2);
                where2 = videotitle.indexOf('</div>');
                videotitle=videotitle.substring(0,where2);
                Ea1.innerText =videotitle;
                document.body.appendChild(Ea1);    
                //document.body.insertBefore(Edt, document.body.firstElementChild);        
        }

    }

}


huya2video();
offplayadd();


</script>
<!--<script src="test.js"></script>
<script type="text/javascript">test.js</script>
-->
</body>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值