m3u8播放器,刪除廣告

钢锅發表於2024-03-11

先提供一個H5的影片播放器,支援m3u8

m3u8播放器,刪除廣告
<!DOCTYPE html>
<html>
<head>
    <title>影片線上解析</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
    <script src="https://cdn.bootcdn.net/ajax/libs/hls.js/0.14.14-0.alpha.5887/hls.min.js"></script>
    <script src="https://config.net.cn/tools/static/Main/jquery.min.js"></script>
</head>
<body>
    <div style="width: 100%;text-align: center;">
        <p id = "Title"style="font-size: 22px;">線上播放</p>
        <video id="my_video_1" width="70%" height="100%" controls poster="https://img0.baidu.com/it/u=2208922133,990968789&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500">
        </video>
        <div style="width: 64%;margin: 0 auto;">
            <table id = "table">
                <tr><td></td><td></td></tr>
            </table>
        </div>
    </div>
<script>
var liebiao = {
    獵冰:{
        第01集:'http://xxxxx.com:9999/m3u8/no1.m3u8',
...
        第17集:'http://xxxxx:9999/m3u8/no17.m3u8',
        第18集:'http://xxxxx:9999/m3u8/no18.m3u8'
    },
    線上電視:{
        浙江衛視:'http://ali-vl.cztv.com/channels/lantian/channel001/360p.m3u8?a=1000&d=46ff2b9c8e77cb79264e864b99592b89&k=16f158ac9e0c5ef3e70b88819fda9ea7&t=1709798048',
        浙江4頻道:'http://ali-vl.cztv.com/channels/lantian/channel004/360p.m3u8?a=1000&d=46ff2b9c8e77cb79264e864b99592b89&k=35e8457f7f508c29e3105c2e501f57ac&t=1709798351',
        浙江6頻道:'http://ali-vl.cztv.com/channels/lantian/channel006/360p.m3u8?a=1000&d=46ff2b9c8e77cb79264e864b99592b89&k=b8ca552e16fe818092a0bf7dba14e14b&t=1709798166'
    },
    線上廣播:{
        FM93:'http://ali-m-l.cztv.com/channels/lantian/fm93/128k.m3u8',
        FM107:'http://ali-m-l.cztv.com/channels/lantian/fm107/128k.m3u8'
    }
};
var urlliHtml = '';
for(leixing in liebiao){
    urlliHtml += '<tr><td id ="'+ leixing +'" style="width: 64px;">' + leixing + '</td><td style="text-align: left;">';
    for(name in liebiao[leixing]){
        urlliHtml += '<button style="height: 30px; margin: 4px 2px; background: green;color: #FFF;border-radius: 4px;border: 0;" id ="'+leixing +'.'+ name +'">'+ name +'</button>';
    }
    urlliHtml += '</td></tr>';
}
//console.log(urlliHtml);
$("#table").append(urlliHtml);
$(document).ready(function(){
    $("button").click(function(){
        var button_object = $(this);
        //console.log(button_object.context.id);
        id = button_object.context.id;
        url = liebiao[id.split(".")[0]][id.split(".")[1]];
        $("#my_video_1").val();
        if(Hls.isSupported()) {
            var video = document.getElementById('my_video_1'); // 獲取 video 標籤
            var hls = new Hls(); // 例項化 Hls 物件
            hls.loadSource(url); // 傳入路徑
            hls.attachMedia(video);
            hls.on(Hls.Events.MANIFEST_PARSED,function() {
              video.play(); // 呼叫播放 API
          });
        }
        $("#Title").html("正在播放..."+ id.split(".")[0] + id.split(".")[1]);
        
    });    
});    
</script>
</body>
</html>
View Code

一個完整的M3U8檔案, 可以嘗試用記事本開啟,建議用Notepad++開啟,

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:1.84,
https://xxxx.com/hls/K9AKr1ZN.ts
...
# 下面為廣告
#EXT-X-DISCONTINUITY
#EXT-X-KEY:METHOD=NONE
#EXTINF:2,
/20240222/QO9zTTM3/2000kb/hls/FulpxjRz.ts
#EXTINF:2,
/20240222/QO9zTTM3/2000kb/hls/mcEEPpUn.ts
#EXTINF:2,
/20240222/QO9zTTM3/2000kb/hls/RJmK4ViG.ts
#EXTINF:2,
 /20240222/QO9zTTM3/2000kb/hls/LHIw32HE.ts
#EXTINF:2,
/20240222/QO9zTTM3/2000kb/hls/ocGUhxkn.ts
#EXTINF:2,
/20240222/QO9zTTM3/2000kb/hls/ZS2KomqW.ts
#EXTINF:2,
/20240222/QO9zTTM3/2000kb/hls/VjpTIkRB.ts
#EXTINF:1.08,
/20240222/QO9zTTM3/2000kb/hls/wM3P6axN.ts
#EXT-X-DISCONTINUITY
#EXTINF:1.84,
https://xxxx.com/hls/K9AKr1ZN.ts

...
#EXT-X-ENDLIST

刪除片頭影片方法

# 以#EXTINF開始,下一行URL 註釋或刪除即可
# 見下面程式碼
# #EXTINF:2.343,
# https://xxxx.com/FQpqVb5O/1500kb/hls/BDx4TXPx.ts
# #EXTINF:2.52,
# https://xxxx.com/FQpqVb5O/1500kb/hls/fjV5clYJ.ts
# 下一行未被註釋
#EXTINF:1.32,
https://xxxx.com/FQpqVb5O/1500kb/hls/TA730dqt.ts
# ...

刪除廣告方法

# 將得到的m3u8檔案,以Notepad++開啟, 選擇語言-python-  搜尋關鍵詞 #EXT-X-DISCONTINUITY.
# 以下面的方式批次註釋,即可無廣告,  以#EXT-X-DISCONTINUITY開始,以#EXT-X-DISCONTINUITY結尾,中間字元全給註釋或刪除
# #EXT-X-DISCONTINUITY
# #EXT-X-KEY:METHOD=NONE
# #EXTINF:2,
# /20240222/QO9zTTM3/2000kb/hls/FulpxjRz.ts
# #EXTINF:2,
# /20240222/QO9zTTM3/2000kb/hls/mcEEPpUn.ts
# #EXTINF:2,
# /20240222/QO9zTTM3/2000kb/hls/RJmK4ViG.ts
# #EXTINF:2,
# /20240222/QO9zTTM3/2000kb/hls/LHIw32HE.ts
# #EXTINF:2,
# /20240222/QO9zTTM3/2000kb/hls/ocGUhxkn.ts
# #EXTINF:2,
# /20240222/QO9zTTM3/2000kb/hls/ZS2KomqW.ts
# #EXTINF:2,
# /20240222/QO9zTTM3/2000kb/hls/VjpTIkRB.ts
# #EXTINF:1.08,
# /20240222/QO9zTTM3/2000kb/hls/wM3P6axN.ts
# #EXT-X-DISCONTINUITY

相關文章