防盜鏈測試01 - Jwplayer+Tengine2.3.1 mp4模塊打造流媒體測試服務器

最近有個想法,想作相似下面的視頻URL防盜驗證;javascript

一、URL Tag Validation

二、Special format of URL for preventing unauthorized usage and access、
sample
  Original: http://www.baidu.com/2016/0704/8025915_HD-60i_7198.mp4
  Using UTV:http://www.baidu.com/2016/0704/8025915_HD-60i_7198.mp4?px-time=1467685158&px-hash=a08a3c149514aae2aea14755a45a29c2

  px-time : current time or expire time
  px-hash : hash(secret + url_path +expire_time) 

  

下面是個人想法,按照想法先搞一下;html

 

1. 一個簡單流媒體測試服務器。java

2. 搞清楚頁面防盜連接所須要的知識,好比打開視頻連接繼而驗證referer,還有添加校驗的args等。python

3. 優化,添加功能。nginx

4. 驗證這些是否符合需求。git

 

搭建流媒體使用tengine 新版自帶的mp4模塊github

下載源碼:http://tenine.taobao.org/download.htmlweb

./configure  --prefix=/web --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_v2_module  --with-http_ssl_module   --with-http_image_filter_module  --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_mp4_module && make && make install

 

Nginx配置文件:服務器

####
    server {
        listen       80;
        server_name  xxxxxx;

        access_log  logs/vhost/xxxxxx_access.log  main;
        #access_log  "pipe:rollback logs/vhost/xxxxxx.access_log interval=1d baknum=7 maxsize=2G"  main;

        location / {
            root   xxxxxx;
            index  index.html index.htm;
            mp4;  #mp4配置,沒有作優化
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

 

播放器選用Jwplayerapp

https://www.jwplayer.com  PS:註冊☑️勾選了開發者就能夠獲取JS連接;jdk等用來測試嗯嗯免費^ ^。

 

 

編輯測試頁面:

index.html

<!DOCTYPE heml>
<html>
    <head>
        <!-- 在這裏替換本身的JW Player id -->
        <script type="text/javascript" src="https://cdn.jwplayer.com/libraries/xxxx.js"></script>
        <script type="text/javascript" src="getParam.js"></script>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    </head>

    <body bgcolor="#000000">
        <div id="myElement">Loading the page...</div>
        <script type="text/javascript">
            var file_name=getParam('id');
            console.log(file_name);
            jwplayer("myElement").setup({
                file: "http://x.x.x.x:8081/" + file_name,
                // image: "data/myposter.jpg",
                title: file_name,
            });
        </script>
    </body>
</html>

 

獲取文件getParam.js 

function getParam(paramName) {
    paramValue = "", isFound = !1;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
        arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
        while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++;
    }
    return paramValue == "" && (paramValue = null), paramValue;
}

 

流媒體測試服務器就基本搭建ok了,測試以下:

PS: 我的的VPS已升級,流媒體測試防盜鏈學習將使用 referer+nginx 驗證token來打造。token: md5(appId+appKey)  敬請期待;

 

參考資料:

https://www.xiaohulu.com/video/user_detail?plat=201&roomid=61936357840

https://www.cnblogs.com/nopnog/p/7452405.html

https://www.cnblogs.com/vinyuan/p/3556218.html

https://leefige.github.io/2019/03/05/%E5%9F%BA%E4%BA%8ENginx%E9%85%8D%E7%BD%AEWeb%E8%A7%86%E9%A2%91%E6%B5%81%E5%AA%92%E4%BD%93%E6%9C%8D%E5%8A%A1%E5%99%A8/

相關文章
相關標籤/搜索