Skip to content

一分钟搭建影视站,支持Docker等部署方式

refactor(player): 移除广告过滤规则依赖,简化M3U8广告过滤逻辑

shinya640fa246142a
diff --git a/js/config.js b/js/config.js
index ea80a9f..368b175 100644
--- a/js/config.js
+++ b/js/config.js
@@ -25,13 +25,11 @@ const API_SITES = {
api: 'https://json.heimuer.xyz',
name: '黑木耳',
detail: 'https://heimuer.tv',
- filterAdRule: '#EXT-X-DISCONTINUITY\\n#EXTINF:\\d+\\.\\d+,\\n.*?\\n#EXT-X-DISCONTINUITY'
},
ffzy: {
api: 'http://ffzy5.tv',
name: '非凡影视',
detail: 'http://ffzy5.tv',
- filterAdRule: '#EXT-X-DISCONTINUITY\\r*\\n*#EXTINF:6.666667,[\\s\\S]*?#EXT-X-DISCONTINUITY'
},
tyyszy: {
api: 'https://tyyszy.com',
diff --git a/player.html b/player.html
index ddfbb0f..897e2bd 100644
--- a/player.html
+++ b/player.html
@@ -531,12 +531,10 @@
function initPlayer(videoUrl, sourceCode) {
if (!videoUrl) return;
- window.filterAdPattern = API_SITES[sourceCode]?.filterAdRule || null
-
// 配置HLS.js选项
const hlsConfig = {
debug: false,
- loader: (adFilteringEnabled && API_SITES[sourceCode]?.filterAdRule) ? CustomHlsJsLoader : Hls.DefaultConfig.loader,
+ loader: adFilteringEnabled ? CustomHlsJsLoader : Hls.DefaultConfig.loader,
enableWorker: true,
lowLatencyMode: false,
backBufferLength: 90,
@@ -888,10 +886,20 @@
function filterAdsFromM3U8(m3u8Content, strictMode = false) {
if (!m3u8Content) return '';
- if (window.filterAdPattern) {
- const regex = new RegExp(window.filterAdPattern, 'g');
- return m3u8Content.replace(regex, '');
- };
+ // 按行分割M3U8内容
+ const lines = m3u8Content.split('\n');
+ const filteredLines = [];
+
+ for (let i = 0; i < lines.length; i++) {
+ const line = lines[i];
+
+ // 只过滤#EXT-X-DISCONTINUITY标识
+ if (!line.includes('#EXT-X-DISCONTINUITY')) {
+ filteredLines.push(line);
+ }
+ }
+
+ return filteredLines.join('\n');
}