惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

Rat's Blog - typecho

零基础的萌新搭建属于自己的Typecho/WordPress等博客教程 - Rat's Blog 修复官方Dplayer-Typecho插件不能连接弹幕API后端的方法 - Rat's Blog 小内存VPS一键安装Typecho/WordPress/Zblog/Kodexplorer及整站备份等 - Rat's Blog Caddy环境下一些Web应用程序的配置参考 - Rat's Blog 小内存VPS安装Caddy+PHP 7+Sqlite 3环境,并快速搭建Typecho博客 - Rat's Blog VPS服务器如何优化/加快网站的访问速度 - Rat's Blog Typecho升级助手:一个可以将Typecho升级到最新版本的插件 - Rat's Blog SC private letter: 一个基于serverchan微信推送服务的私信发送站 - Rat's Blog 给WordPress、Emlog等博客网站添加下雪特效,附带Typecho下雪插件 - Rat's Blog
使用Docker搭建DPlayer视频弹幕接口API后端 - Rat's Blog
博主: Rat's · 2019-01-03 · via Rat's Blog - typecho

说明:之前有同学要求博主出个DPlayer弹幕后端搭建教程,刚好本博客的Handsome主题更新并完美适配了Dplayer,然后就研究了下,发现了点小问题,如作者提供的弹幕API加载不出弹幕,而且Typecho当中的Dplayer插件有点旧无法对接V3后端,不知道其它程序插件是不是这样,这里博主只能使用HTML代码直接输出调用,经测试已完全正常加载弹幕和观看。这里就说下搭建及使用方法。

【2020.10.3】
弹幕api接口已修复,长期可用,https://dplayer.moerats.com,如出现问题留言即可。

【2020.10.27】
由于有些人不太喜欢Docker搭建,所以下面补齐CentOS、Debian、Ubuntu手动搭建教程。

简介

DPlayer是一个支持弹幕的HTML5视频播放器。支持Bilibili视频和danmaku,支持HLSFLVMPEG DASHWebTorrent以及其他视频格式,支持截屏、热键、切换清晰度以及字幕等。

安装

作者提供的弹幕后端搭建方法挺多的,这里选择一个搭建最快,版本最新的一种。

Github地址:https://github.com/MoePlayer/DPlayer-node

Docker安装

1、安装Docker

#CentOS 6
rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum update -y
yum -y install docker-io
service docker start
chkconfig docker on

#CentOS 7、Debian、Ubuntu
curl -sSL https://get.docker.com/ | sh
systemctl start docker
systemctl enable docker

2、安装Docker Compose

curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

3、运行镜像
安装git

#Debian、Ubuntu系统
apt install git -y

#CentOS系统
yum install -y git

再使用命令:

#拉取源码
git clone https://github.com/MoePlayer/DPlayer-node.git
cd DPlayer-node
#新建镜像
docker-compose build
#拉取其它镜像并后台运行
docker-compose up -d

此时api地址为http://ip:1207,数据和日志存放在/root/dplayer文件夹。

当然如果你想其它端口,或者修改存放文件夹路径,那你在上面的新建镜像之前,作出如下操作:

#编辑DPlayer-node文件夹的docker-compose.yml文件,部分修改如下
mongo:
  volumes:
      - ~/dplayer/db:/data/db  #数据库存放文件夹,~/dplayer/db为映射在外部的路径,自行修改,
web:
  ports:
    - 1207:1207  #api映射到外部的端口,将前面的1207修改成你想要的即可
  volumes:
    - ~/dplayer/logs:/usr/src/app/logs  #同数据库操作
    - ~/dplayer/pm2logs:/root/.pm2/logs  #同上

改完后再新建镜像即可,如果你已经新建镜像了,但想改,那就清空之前的镜像再修改,方法参考→传送门

CentOS安装

提示:教程适用于CentOS 7、8系统。

1、安装NodeJS

curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum install nodejs git -y

2、安装Mongodb

#将下面命令一起复制进SSH客户端运行
cat <<EOF > /etc/yum.repos.d/mongodb.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
EOF
#安装mongodb
yum -y install mongodb-org
systemctl start mongod
systemctl enable mongod

3、安装Redis

#CentOS 7系统
yum install epel-release -y
yum install redis -y
systemctl start redis
systemctl enable redis

#CentOS 8系统
yum install redis -y
systemctl start redis
systemctl enable redis

4、安装弹幕服务器

#拉取源码
git clone https://github.com/MoePlayer/DPlayer-node.git
cd DPlayer-node
npm i
npm i -g pm2
pm2 start index.js --name danmuapi

此时api地址为http://ip:1207

Debian安装

提示:教程适用于Debian 8、9、10系统。

1、安装NodeJS

curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt install -y git nodejs 

2、安装Mongodb

#Debian 8系统
wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | apt-key add -
echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/4.0 main" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list
apt update -y
apt -y install mongodb-org
systemctl start mongod
systemctl enable mongod

#Debian 9系统
wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | apt-key add -
echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list
apt update -y
apt -y install mongodb-org
systemctl start mongod
systemctl enable mongod

#Debian 10系统
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add -
echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list
apt update -y
apt -y install mongodb-org
systemctl start mongod
systemctl enable mongod

3、安装Redis

apt install redis-server -y

4、安装弹幕服务器

#拉取源码
git clone https://github.com/MoePlayer/DPlayer-node.git
cd DPlayer-node
npm i
npm i -g pm2
pm2 start index.js --name danmuapi

此时api地址为http://ip:1207

Ubuntu安装

提示:教程适用于Ubuntu 16.04、18.04、20.04系统。

1、安装NodeJS

curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt install -y git nodejs 

2、安装Mongodb

#Ubuntu 16.04系统
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
apt update -y
apt install -y mongodb-org
systemctl start mongod
systemctl enable mongod

#Ubuntu 18.04系统
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
apt update -y
apt install -y mongodb-org
systemctl start mongod
systemctl enable mongod

#Ubuntu 20.04系统
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
apt update -y
apt install -y mongodb-org
systemctl start mongod
systemctl enable mongod

3、安装Redis

apt install redis-server -y

4、安装弹幕服务器

#拉取源码
git clone https://github.com/MoePlayer/DPlayer-node.git
cd DPlayer-node
npm i
npm i -g pm2
pm2 start index.js --name danmuapi

此时api地址为http://ip:1207

域名反代

如果你的博客已经开启了https访问,那api也需要https地址,所以只使用ip:端口是不行的,这里就需要使用域名反代了。博主喜欢Caddy,所以这里说下宝塔和Caddy反代,其它一键环境的建议看官方文档或自行搜索。

如果你服务器没有安装Nginx/Apache的,可以用下Caddy,很方便很快,记得提前将域名解析到服务器。

1、宝塔反代
先进入宝塔面板,然后点击左侧网站,添加站点,然后再点击添加好了的域名名称,这时候就进入了站点配置,点击反向代理,目标URL填入http://127.0.0.1:1207,再启用反向代理即可。至于启用SSL就不说了,直接在站点配置就可以看到。

2、Caddy反代
安装Caddy

wget -N --no-check-certificate https://raw.githubusercontent.com/iiiiiii1/doubi/master/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh
#备用地址
wget -N --no-check-certificate https://www.moerats.com/usr/shell/Caddy/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh

配置Caddy

#以下全部内容是一个整体,请修改域名后一起复制到SSH运行!
echo "xx.com {
 tls admin@moerats.com
 proxy / http://127.0.0.1:1207
}" > /usr/local/caddy/Caddyfile

tls参数会自动帮你签发ssl证书,如果你要使用自己的ssl,改为tls /root/xx.crt /root/xx.key即可。后面为ssl证书路径。

启动Caddy

/etc/init.d/caddy start

反代好了后,你的API地址就为https://xx.com

使用

作者提供了很多插件,这里列举一点:

Typecho:https://github.com/volio/DPlayer-for-typecho
Hexo:https://github.com/NextMoe/hexo-tag-dplayer
Z-Blog:https://github.com/fghrsh/DPlayer_for_Z-BlogPHP
Discuz!:https://coding.net/u/Click_04/p/video/git
WordPress:https://github.com/BlueCocoa/DPlayer-WordPress

不过Typecho插件暂时用不了,其它程序暂时不清楚,所以这里提供一个播放器的HTML代码,代码如下:

<link href="https://www.moerats.com/usr/dplayer/DPlayer.min.css" rel="stylesheet">
<div id="dplayer"></div>
<script src="https://www.moerats.com/usr/dplayer/DPlayer.min.js"></script>
<script src="https://cdnjs.loli.net/ajax/libs/blueimp-md5/2.10.0/js/md5.min.js"></script>
<script>
var url="https://www.moerats.com/xx.mp4";    //这里填写视频地址
var id=md5(url);
const dp = new DPlayer({
    container: document.getElementById('dplayer'),
    video: {
        url: url
  },
  danmaku: {
        id: id,
        api: 'https://dplayer.moerats.com/'    //这里填写弹幕地址
    }
});
</script>

直接将代码贴进文章里即可,如果在Typecho开发版中使用不正常的话,可能还需要用两排!!!将代码上下围住使其强制输出,比如:

#特殊原因,不得已才加上o,使用的时候记得去掉
o!!!
代码
o!!!

还有更多功能及使用方法可以查看→传送门

演示

博主知道有人懒搭建的,所以这里提供个弹幕API地址:https://dplayer.moerats.com/。

好了,可以在视频里发彩色弹幕了,如果该视频播放器不显示的话,刷新一下就行了。


版权声明:本文为原创文章,版权归 Rat's Blog 所有,转载请注明出处!

本文链接:https://www.moerats.com/archives/838/

如教程需要更新,或者相关链接出现404,可以在文章下面评论留言。