Skip to content

Commit

Permalink
reload danmu && remove data cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiram committed May 12, 2024
1 parent eff0831 commit 02b7ca7
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 50 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"artplayer-plugin-danmuku": "^5.0.1",
"axios": "^1.6.8",
"axios-retry": "^4.1.0",
"bad-words": "^3.0.4",
"cheerio": "^1.0.0-rc.12",
"crypto-js": "^4.2.0",
"dayjs": "^1.11.11",
Expand Down
7 changes: 1 addition & 6 deletions src/main/core/server/routes/barrge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import badWords from 'bad-words';
import { FastifyReply, FastifyPluginAsync, FastifyRequest } from 'fastify';
import _ from 'lodash';
import axios from 'axios';
Expand Down Expand Up @@ -53,11 +52,7 @@ const api: FastifyPluginAsync = async (fastify): Promise<void> => {
}
const response = await axios(`${url}${id}`);
const text: any = response.data;
const filter = new badWords();
const cleanedData = text[key].map((item: any) => {
const cleanedContent = filter.isProfane(item[content]) ? filter.clean(item[content]) : item[content];
return { ...item, [content]: cleanedContent };
});
const cleanedData = text;

// { time: 230.523, type: "right", color: "#fff", author: "618c713c", text: "键盘妹子挺好看?" }
data.data = cleanedData.map((item: any) => [
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/assets/md/en_US/privacy-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
6. This software has resource sniffing characteristics, which may lead to the privacy and security risks of third-party data. When using this feature, users shall bear the risk of possible information leakage or abuse and be fully responsible for its consequences.
7. You are responsible for all operations and results when using this software. This software is not responsible for any content you obtain through the use of this software, including but not limited to the accuracy, copyright compliance, integrity, security and availability of media resources. We shall not be liable for any loss, damage or legal disputes caused by the use of this software.
8. When using this software, you must abide by the relevant laws and regulations of your country/region, and prohibit the use of this software for any activities that violate laws and regulations, including but not limited to the production, uploading, dissemination and storage of any illegal, infringing, obscene, defamation, malware and other content. If you violate relevant laws and regulations, you need to bear your own legal responsibility.
9. In order to comply with the content review requirements of the Network Security Law, this software does not provide barrage sending services. Regarding the barrage display, the bad-world local library is used for preliminary data cleaning. Although we have tried our best to deal with it, due to technical restrictions such as word segmentation, it may not be possible to completely remove all bad comments. If the user makes bad remarks through any channel, the behavior has nothing to do with this software. We call on users to jointly maintain network health and civilized language.
9. In order to comply with the content review requirements of the Network Security Law, this software does not provide barrage sending services. Regarding the barrage display, due to the limitation of local performance without data cleaning, there may be bad comments. Please do not believe that this causes unnecessary trouble. At the same time, if the user makes bad remarks through any channel, the behavior has nothing to do with this software. We call on users to use civilized language and jointly maintain a healthy network environment.
10. We know that your privacy is invaluable. Therefore, this software never collects any user data. Except for the necessary WebDev backup (this process is strictly managed by a professional third party), all information is strictly stored locally to ensure that your data is only under your control. This software does not share any information about you with any third party.
11. This disclaimer applies to all users of this software. The software reserves the right to modify and update this statement at any time, and notify users in the form of Github Readme, software updates, etc. Please check and abide by the latest disclaimer regularly.

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/assets/md/zh_CN/privacy-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
6. 本软件具备资源嗅探特性,可能会引发第三方数据的隐私和安全风险。用户在使用该特性时,需自行承担可能产生的信息泄露或滥用风险,并对其后果负全部责任。
7. 您在使用本软件时需自行负责所有操作和使用结果。本软件不对您通过使用本软件获取的任何内容负责,包括但不限于媒体资源的准确性、版权合规性、完整性、安全性和可用性。对于任何因使用本软件导致的损失、损害或法律纠纷,不承担任何责任。
8. 您在使用本软件时必须遵守您所在国家/地区的相关法律法规,禁止使用本软件进行任何违反法律法规的活动,包括但不限于制作、上传、传播、存储任何违法、侵权、淫秽、诽谤、恶意软件等内容。如您违反相关法律法规,需自行承担法律责任。
9. 为遵守网络安全法的内容审核要求,本软件不提供弹幕发送服务。关于弹幕展示,使用bad-world本地库进行初步数据清洗,尽管我们已经尽力处理,但由于分词等技术限制,可能无法完全清除所有不良言论。如果用户通过任何渠道发表不良言论行为,该行为与本软件无关。我们呼吁用户共同维护网络健康,文明用语
9. 为遵守网络安全法的内容审核要求,本软件不提供弹幕发送服务。关于弹幕展示,受限于本地性能未做数据清理,可能存在不良言论,请勿相信因此引起非必的要麻烦。同时如果用户通过任何渠道发表不良言论行为,该行为与本软件无关。我们呼吁用户文明用语,共同维护网络健康环境
10. 我们深知您的隐私无价。因此,本软件绝不收集任何用户数据,除了必要的WebDev备份(此过程由专业第三方严格管理)外,所有信息均严格本地存储,确保您的数据仅在您掌控之中。此软件不与任何第三方共享您的任何信息。
11. 本免责声明适用于本软件的所有用户。本软件保留随时修改、更新本声明的权利,并以Github Readme、软件更新等形式通知用户。请您定期查阅并遵守最新的免责声明。

Expand Down
52 changes: 38 additions & 14 deletions src/renderer/src/pages/Play.vue
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ import { setDefault } from '@/api/setting';
import { fetchChannelList } from '@/api/iptv';
import { checkUrlIpv6, getLocalStorage } from '@/utils/tool';
import { playerBarrage, playerCreate, playerDestroy, playerNext, playerSeek, playerPause, playerTimeUpdate, offPlayerTimeUpdate } from '@/utils/common/player';
import { playerBarrage, playerCreate, playerDestroy, playerNext, playerSeek, playerPause, playerTimeUpdate, offPlayerTimeUpdate, offPlayerBarrage } from '@/utils/common/player';
import {
fetchBingeData,
putBingeData,
Expand Down Expand Up @@ -427,6 +427,8 @@ const tmp = reactive({
sourceUrl: "",
preloadNext: "",
preloadLoading: false,
preloadBarrage: [],
preloadSourceUrl: '',
playerHeaders: {}
}) as any;
Expand Down Expand Up @@ -536,21 +538,24 @@ const createPlayer = async (url: string, videoType: string = '') => {
// 弹幕
const options = set.value.barrage;
const danmuList = await fetchBarrage();
const { flimSource, filmIndex } = active;
const danmuList = await fetchBarrage(tmp.sourceUrl, options, { flimSource, filmIndex });
if (danmuList.length > 0) {
if (playerMode.type === 'dplayer') {
playerBarrage(player, playerMode.type, tmp.sourceUrl, options);
playerBarrage(player, playerMode.type, tmp.sourceUrl, options, tmp.sourceUrl);
} else {
playerBarrage(player, playerMode.type, danmuList, options);
playerBarrage(player, playerMode.type, danmuList, options, tmp.sourceUrl);
};
}
};
setSystemMediaInfo(); // 设置系统媒体信息
// setTimeout(()=>{
// setTimeout(() => {
// console.log('setTimeout')
// offPlayerTimeUpdate(player, playerMode.type);
// }, 6000)
// offPlayerBarrage(player, playerMode.type);
// }, 6000);
};
// 摧毁播放器
Expand Down Expand Up @@ -758,9 +763,21 @@ const changeEvent = async (item) => {
await offPlayerTimeUpdate(player, playerMode.type);
await playerNext(player, playerMode.type, tmp.preloadNext);
if (tmp.preloadBarrage.length > 0) {
await offPlayerBarrage(player, playerMode.type);
const options = set.value.barrage;
if (playerMode.type === 'dplayer') {
playerBarrage(player, playerMode.type, tmp.preloadSourceUrl, options, tmp.preloadSourceUrl);
} else {
playerBarrage(player, playerMode.type, tmp.preloadBarrage, options, tmp.preloadSourceUrl);
};
tmp.preloadBarrage = [];
};
// if (skipConfig.value.skipTimeInStart) await playerSeek(player, playerMode.type, skipConfig.value.skipTimeInStart); 无法解决进度条问题
tmp.preloadLoading = false;
tmp.preloadNext = {};
tmp.sourceUrl = tmp.preloadSourceUrl;
tmp.preloadSourceUrl = '';
setSystemMediaInfo(); // 更新系统媒体信息
setTimeout(async () => {
await timerUpdatePlayProcess();
Expand All @@ -772,12 +789,22 @@ const changeEvent = async (item) => {
};
// 提前获取下一集链接
const preloadNext = async (url: string) => {
const preloadNext = async (item: string) => {
const url = formatIndex(item).url;
tmp.preloadSourceUrl = url;
const { snifferMode } = set.value;
const { site } = ext.value;
const { flimSource } = active;
const analyze = snifferAnalyze.value;
const response = await playHelper(snifferMode, url, site, analyze, active.flimSource);
const response = await playHelper(snifferMode, url, site, analyze, flimSource);
tmp.preloadNext = { ...response };
if (response?.url) { // 预加载弹幕
const options = set.value.barrage;
tmp.preloadBarrage = await fetchBarrage(tmp.sourceUrl, options, { flimSource, filmIndex:item });
};
};
// 获取豆瓣影片推荐
Expand Down Expand Up @@ -820,8 +847,7 @@ const timerUpdatePlayProcess = () => {
if (season.value[siteSource].length !== index + 1 && !tmp.preloadLoading) {
try {
tmp.preloadLoading = true;
const preloadUrl = formatIndex(season.value[siteSource][index + 1]).url;
await preloadNext(preloadUrl);
await preloadNext(season.value[siteSource][index + 1]);
} catch (err) { };
};
};
Expand All @@ -835,10 +861,8 @@ const timerUpdatePlayProcess = () => {
};
// 获取弹幕
const fetchBarrage = async () => {
const options = set.value.barrage;
const { flimSource, filmIndex } = active;
const response = await fetchBarrageData(tmp.sourceUrl, options, { flimSource, filmIndex });
const fetchBarrage = async (url: string, options: any, active: any) => {
const response = await fetchBarrageData(url, options, active);
return response || [];
};
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/style/player/artplayer.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@

.art-danmuku-emitter {
opacity: 0 !important;
}
}
102 changes: 88 additions & 14 deletions src/renderer/src/utils/common/player.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { nanoid } from 'nanoid';

import Artplayer from 'artplayer';
import artplayerPluginDanmuku from 'artplayer-plugin-danmuku';
import DPlayer from 'dplayer';
import NPlayer, { EVENT as NPlayerEvent, Icon as NPlayerIcon } from 'nplayer';
import nplayerDanmaku from '@nplayer/danmaku';
import badWords from 'bad-words';
import flvjs from 'flv.js';
import Hls from 'hls.js';
import WebTorrent from './components/webtorrent';
Expand Down Expand Up @@ -128,6 +129,18 @@ const publicElementDeal = {
},
};

const publicBarrageSend = (url: string, options: any) => {
const okd = new FormData();
okd.append('player', options.id);
okd.append('text', options.text);
okd.append('time', options.time);
okd.append('color', options.color);
okd.append('type', options.type);
const xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.send(okd);
};

const publicListener = {
xgplayer: {
timeupdate: (currentTime, duration, callback) => {
Expand Down Expand Up @@ -385,9 +398,20 @@ let playerConfig: any = {
// 播放器公共部分
const playerMethod = {
xgplayer: {
barrge: (player: XgPlayer, comments: any) => {
barrge: (player: XgPlayer, comments: any, url: string, id: string) => {
player.plugins.danmu.updateComments(comments, true);
// player.getPlugin('danmu').updateComments(comments, true);
// player.getPlugin('danmu').updateComments(comments, true); // 效果一样
// player.plugins.danmu.sendComment({
// duration: 5000, //弹幕持续显示时间,毫秒(最低为5000毫秒)
// id: nanoid(), //弹幕id,需唯一
// start: player.currentTime * 1000, //弹幕出现时间,毫秒
// color: true, //该条弹幕为彩色弹幕,默认false
// txt: '', //弹幕文字内容
// style: {
// //弹幕自定义样式
// color: '#FFFFFF',
// },
// }); // 应插件内实现
},
create: (options: any): XgPlayer => {
const plugins = options.plugins;
Expand Down Expand Up @@ -457,6 +481,10 @@ const playerMethod = {
duration: player.duration || 0,
};
},
offBarrage: (player: XgPlayer) => {
// player.offAll();
// 无该事件
},
onTimeupdate: (player: XgPlayer) => {
player.on(Events.TIME_UPDATE, ({ currentTime, duration }) => {
return { currentTime, duration };
Expand All @@ -477,7 +505,7 @@ const playerMethod = {
},
},
dplayer: {
barrge: (player: DPlayer, comments: any) => {
barrge: (player: DPlayer, comments: any, url: string, id: string) => {
const video = player.options.video;
let danmaku: any = player.options.danmaku;
danmaku.id = comments;
Expand Down Expand Up @@ -537,6 +565,9 @@ const playerMethod = {
}
});
},
offBarrage: (player: DPlayer) => {
// 弹幕组件会直接提交后端
},
offTimeupdate: (player: CustomDPlayer) => {
player.off('timeupdate');
},
Expand All @@ -548,11 +579,27 @@ const playerMethod = {
},
},
artplayer: {
barrge: (player: Artplayer, comments: any) => {
barrge: (player: Artplayer, comments: any, url: string, id: string) => {
player.plugins.artplayerPluginDanmuku.config({
danmuku: comments,
});
player.plugins.artplayerPluginDanmuku.load();
// @ts-ignore
player.on('artplayerPluginDanmuku:emit', (danmu: any) => {
const options = {
player: id,
text: danmu.text,
time: danmu.time,
color: danmu.color,
type: danmu.mode == 1 ? '5' : '0',
};
publicBarrageSend(url, options);
// player.plugins.artplayerPluginDanmuku.emit({
// text: danmu.text,
// color: danmu.color,
// border: true,
// }); // 会重复显示
});
},
create: (options: any): Artplayer => {
Artplayer.PLAYBACK_RATE = [0.5, 0.75, 1, 1.25, 1.5, 2];
Expand Down Expand Up @@ -600,6 +647,10 @@ const playerMethod = {
};
});
},
offBarrage: (player: Artplayer) => {
// @ts-ignore
player.off('artplayerPluginDanmuku:emit');
},
offTimeupdate: (player: Artplayer) => {
player.off('video:timeupdate');
},
Expand All @@ -611,8 +662,18 @@ const playerMethod = {
},
},
nplayer: {
barrge: (player: NPlayer, comments: any) => {
barrge: (player: NPlayer, comments: any, url: string, id: string) => {
player.danmaku.resetItems(comments);
player.on('DanmakuSend', (danmu) => {
const options = {
player: id,
text: danmu.text,
time: danmu.time,
color: danmu.color,
type: danmu.type,
};
publicBarrageSend(url, options);
});
},
create: (options: any): NPlayer => {
NPlayerIcon.register('play', publicElementDeal.nplayer.createIcon(publicIcons.play));
Expand Down Expand Up @@ -759,6 +820,9 @@ const playerMethod = {
};
});
},
offBarrage: (player: NPlayer) => {
player.off('DanmakuSend');
},
offTimeupdate: (player: NPlayer) => {
player.off(NPlayerEvent.TIME_UPDATE);
},
Expand Down Expand Up @@ -940,7 +1004,7 @@ const offPlayerTimeUpdate = (player, playerMode) => {
};

// 弹幕加载
const playerBarrage = (player: any, playerMode: string, data: any, options: any) => {
const playerBarrage = (player: any, playerMode: string, data: any, options: any, id: string) => {
const barrges = {
xgplayer: playerMethod.xgplayer.barrge,
artplayer: playerMethod.artplayer.barrge,
Expand All @@ -949,16 +1013,12 @@ const playerBarrage = (player: any, playerMode: string, data: any, options: any)
};
const barrge = barrges[playerMode];

const { start, mode, color, content } = options;
const { start, mode, color, content, url } = options;
let comments: any = [];
let cleanedData: any = [];

if (playerMode !== 'dplayer') {
const filter = new badWords();
cleanedData = data.map((item: any) => {
const cleanedContent = filter.isProfane(item[content]) ? filter.clean(item[content]) : item[content];
return { ...item, [content]: cleanedContent };
});
cleanedData = data;
}

switch (playerMode) {
Expand Down Expand Up @@ -999,7 +1059,20 @@ const playerBarrage = (player: any, playerMode: string, data: any, options: any)
break;
}

barrge(player, comments);
barrge(player, comments, url, id);
};

// 取消弹幕监听
const offPlayerBarrage = (player, playerMode) => {
const offBarrages = {
xgplayer: playerMethod.xgplayer.offBarrage,
artplayer: playerMethod.artplayer.offBarrage,
dplayer: playerMethod.dplayer.offBarrage,
nplayer: playerMethod.nplayer.offBarrage,
};
const offBarrage = offBarrages[playerMode];
console.log(111)
offBarrage(player);
};

export {
Expand All @@ -1010,5 +1083,6 @@ export {
playerSeek,
playerPause,
playerTimeUpdate,
offPlayerBarrage,
offPlayerTimeUpdate,
};
12 changes: 0 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2465,18 +2465,6 @@ b4a@^1.6.0, b4a@^1.6.4:
resolved "https://registry.npmmirror.com/b4a/-/b4a-1.6.6.tgz#a4cc349a3851987c3c4ac2d7785c18744f6da9ba"
integrity sha512-5Tk1HLk6b6ctmjIkAcU/Ujv/1WqiDl0F0JdRCR80VsOcUlHcu7pWeWRlOqQLHfDEsVx9YH/aif5AG4ehoCtTmg==

bad-words@^3.0.4:
version "3.0.4"
resolved "https://registry.npmmirror.com/bad-words/-/bad-words-3.0.4.tgz#044c83935c4c363a905d47b5e0179f7241fecaec"
integrity sha512-v/Q9uRPH4+yzDVLL4vR1+S9KoFgOEUl5s4axd6NIAq8SV2mradgi4E8lma/Y0cw1ltVdvyegCQQKffCPRCp8fg==
dependencies:
badwords-list "^1.0.0"

badwords-list@^1.0.0:
version "1.0.0"
resolved "https://registry.npmmirror.com/badwords-list/-/badwords-list-1.0.0.tgz#5e9856dbf13482a295c3b0b304afb9d4cfc5c579"
integrity sha512-oWhaSG67e+HQj3OGHQt2ucP+vAPm1wTbdp2aDHeuh4xlGXBdWwzZ//pfu6swf5gZ8iX0b7JgmSo8BhgybbqszA==

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.npmmirror.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
Expand Down

0 comments on commit 02b7ca7

Please sign in to comment.