技术文摘

搭建DPlayer视频弹幕接口API后端

作者:雨祺   发表于:
浏览:192次    字数:4025  电脑原创
级别: 站长   总稿: 68 篇,  月稿: 0

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

  1. 【2021.07.27】 
  2. 弹幕api接口已修复,长期可用,https://danmu.meiweny.cn,如出现问题留言即可。 
  3.  
  4. 【2021.07.27】 
  5. 由于有些人不太喜欢Docker搭建,所以下面补齐CentOS、Debian、Ubuntu手动搭建教程。 

简介

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

安装

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

Docker安装

1、安装Docker
  1. #CentOS 6 
  2. rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 
  3. yum update -y 
  4. yum -y install docker-io 
  5. service docker start 
  6. chkconfig docker on 
  7.  
  8. #CentOS 7、Debian、Ubuntu 
  9. curl -sSL https://get.docker.com/ | sh 
  10. systemctl start docker 
  11. systemctl enable docker 

2、安装Docker Compose

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

3、运行镜像,安装git

  1. #Debian、Ubuntu系统 
  2. apt install git -y 
  3.  
  4. #CentOS系统 
  5. yum install -y git 

再使用命令:

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

此时api地址为http://ip:1207,数据和日志存放在/root/dplayer文件夹。当然如果你想其它端口,或者修改存放文件夹路径,那你在上面的新建镜像之前,作出如下操作:

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

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

1、此命令会清空所有的Docker文件

  1. docker kill $(docker ps -aq) 
  2. docker rm $(docker ps -aq) 
  3. docker rmi $(docker images -q) 
  4. docker volume rm $(docker volume ls -q) 

2、此命令会保留正在运行的Docker镜像,其它会全部清除

  1. docker rm $(docker ps -aq) 
  2. docker rmi $(docker images -q) 
  3. docker volume rm $(docker volume ls -q) 

CentOS安装

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

1、安装NodeJS

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

2、安装Mongodb

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

3、安装Redis

  1. #CentOS 7系统 
  2. yum install epel-release -y 
  3. yum install redis -y 
  4. systemctl start redis 
  5. systemctl enable redis 
  6.  
  7. #CentOS 8系统 
  8. yum install redis -y 
  9. systemctl start redis 
  10. systemctl enable redis 

4、安装弹幕服务器

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

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


Debian安装

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

1、安装NodeJS

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

2、安装Mongodb

  1. #Debian 8系统 
  2. wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | apt-key add - 
  3. 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 
  4. apt update -y 
  5. apt -y install mongodb-org 
  6. systemctl start mongod 
  7. systemctl enable mongod 
  8.  
  9. #Debian 9系统 
  10. wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | apt-key add - 
  11. 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 
  12. apt update -y 
  13. apt -y install mongodb-org 
  14. systemctl start mongod 
  15. systemctl enable mongod 
  16.  
  17. #Debian 10系统 
  18. wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add - 
  19. 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 
  20. apt update -y 
  21. apt -y install mongodb-org 
  22. systemctl start mongod 
  23. systemctl enable mongod 

3、安装Redis

  1. apt install redis-server -y 

4、安装弹幕服务器

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

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


Ubuntu安装

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

1、安装NodeJS

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

2、安装Mongodb

  1. #Ubuntu 16.04系统 
  2. wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - 
  3. 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 
  4. apt update -y 
  5. apt install -y mongodb-org 
  6. systemctl start mongod 
  7. systemctl enable mongod 
  8.  
  9. #Ubuntu 18.04系统 
  10. wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - 
  11. 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 
  12. apt update -y 
  13. apt install -y mongodb-org 
  14. systemctl start mongod 
  15. systemctl enable mongod 
  16.  
  17. #Ubuntu 20.04系统 
  18. wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - 
  19. 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 
  20. apt update -y 
  21. apt install -y mongodb-org 
  22. systemctl start mongod 
  23. systemctl enable mongod 

3、安装Redis

  1. apt install redis-server -y 

4、安装弹幕服务器

  1. #拉取源码 
  2. git clone https://github.com/MoePlayer/DPlayer-node.git 
  3. cd DPlayer-node 
  4. npm i 
  5. npm i -g pm2 
  6. 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

  1. wget -N --no-check-certificate https://raw.githubusercontent.com/iiiiiii1/doubi/master/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh 
  2. #备用地址 
  3. 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

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

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

  1. /etc/init.d/caddy start 

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

说实话,dplayer真的是一个很漂亮的播放器插件,但是这个插件需要后端支持才能正常实现弹幕功能,不幸的是这个插件的官网上面的那个后端接口已经GG了,所以无奈可能得自己搭建后台了!但是网上总是有热心网友吧,作者写了dplayer弹幕后端搭建教程之外还分享了一个线上的搭建好了的后端接口。感谢您的阅读!

【审核人:站长】

收藏   加好友   生成海报   分享
点赞(0)
打赏
Tags: 弹幕 视频 Dplayer
评论(0人参与,0条评论) 雨祺
0/0
  • 请先说点什么
    最新评论

    发布者资料

    热门文章

    技术文摘

    查看更多技术文摘
    首页
    栏目
    搜索
    会员
    投稿