Loading... # 前言 熟悉Emby的朋友都知道,它是一个较为成熟的流媒体播放器,和传统播放器相比,海报墙、搜索、剧情简介、多人观看是其特点。 目前搭建Emby的成本有高有低,想要较好的连接性就需要好的服务器,或者要挂个飞机。在Tg群 看到某个大佬(@baipiaoking)的骚操作,他将emby的视频源劫持到目录程序的对应文件的直链,从而实现**不走服务器流量,而观看体验与普通emby相同**。 自行鼓捣一阵后将大佬的配置稍作修改,最终成为此文的配置。 说一下这种方法的优缺点: 优点: 1. 播放视频不依靠与服务器的连接性,速度取决于本地与直链的速度 2. 可单独对视频直链进行中转,例如onemanager、sharelist都支持中转。这点有点鸡肋,因为一般情况下可直接对emby服务端进行中转。搭配世纪互联才是最佳选择。 缺点: 1. 无法进行服务器端解码。虽然大部分小鸡的性能也不足以支撑解码 2. 网页端无法实现(这点为博主个人原因,无法复现老哥网页端的效果) # 环境要求 配置前默认的要求: 1. 已经搭建好并正常使用没有问题的Emby服务端 2. 安装好njs模块的nginx程序。windows端无法安装njs,可自行参照本文思路用其它方法实现。njs模块的安装教程自行搜索。 3. 一个已经搭建好的目录程序,本文使用的是Onemanager。理论目录程序都可以 ,不限于gd和od,也不局限于绑定域名或者裸IP。 4. 基本nginx基础,一丢丢就行 5. 一个会百度或谷歌教程外问题的脑子 # 开始配置 运行下面命令查看nginx 的配置位置 ``` nginx -t ``` 博主的配置位于: ``` /usr/local/nginx/conf/nginx.conf ``` 以下操作基于你获得的配置位置,请自行灵活操作 在 **/usr/local/nginx/conf** 文件夹中新建 emby.js 文件 内容如下 ```javascript var api_key = "1fb2477b5cbxxxxxxxx"; //修改为自己的emby api var reg = /\/emby\/Videos\/(.*)\/stream(.*)/i; //i表示case-insensitive function redirect2Pan(r) { var itemInfoUrl = r.variables.uri.replace(reg, "http://127.0.0.1:8097/emby/Items?Fields=Path&Ids=$1&api_key=") + api_key; //r.return(200, itemInfoUrl); ngx.fetch(itemInfoUrl) .then(reply => reply.json()) .then(body => body.Items[0].Path) .then(path => path.replace('/media/video','')) //修改为自己的路径 .then(uri => encodeURI(uri)) // http://one.weinb.top .then(uri => 'http://xxx.weinb.top'+uri) //http://xxx.weinb.top 请修改为自己的目录地址 .then(uri => r.return(301, uri)); // .then(uri => r.internalRedirect(uri)) // .catch(e => r.return(501, e.message)); } var downreg = /\/emby\/Items\/(.*)\/Download(.*)/i; //i表示case-insensitive function redirectdown2Pan(r) { //r.return(200, "test"); var itemInfoUrl = r.variables.uri.replace(downreg, "http://127.0.0.1:8097/emby/Items?Fields=Path&Ids=$1&api_key=") + api_key; ngx.fetch(itemInfoUrl) .then(reply => reply.json()) .then(body => body.Items[0].Path) .then(path => path.replace('/media/video','')) //修改为自己的路径 .then(uri => encodeURI(uri)) // http://one.weinb.top .then(uri => 'http://xxx.weinb.top'+uri) //http://xxx.weinb.top 请修改为自己的目录地址 .then(uri => r.return(301, uri)); } ``` 配置说明已在代码中说明,请根据提示修改 主要说明的路径的配置 这是博主媒体库中的配置  在api中获取媒体库内的文件信息如下  可见路径为:"/media/video/newanime/奇巧计程车/Season 01/[Lilith-Raws] Odd Taxi - S01E01 [Baha][WEB-DL][1080p][AVC AAC][CHT][MP4].mp4" js中需要实现的是将此路径转换为对应的文件直链,所以代码中 **path.replace** 中填 **/media/video** ,最后直链为 http://xxx.weinb.top/newanime/奇巧计程车/Season 01/[Lilith-Raws] Odd Taxi - S01E01 [Baha][WEB-DL][1080p][AVC AAC][CHT][MP4].mp4 Ps:注意目录网址中尾部最好不要加 / 打开nginx 的配置文件,此处为 /usr/local/nginx/conf/nginx.conf 修改配置,博主的最终配置如下 ``` #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { js_include /usr/local/nginx/conf/emby.js; # emby流转到网盘 server{ gzip on; listen 8097; server_name 0.0.0.0; location /test { js_content redirect2Pan; } location ~* \/emby\/videos\/\d*\/stream { #获取视频流时的反代 js_content redirect2Pan; } location ~* \/emby\/Items\/\d*\/Download { #获取视频流时的反代 js_content redirectdown2Pan; } location / { proxy_pass http://localhost:8096; proxy_buffering off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } } ``` 修改完全部配置后,运行命令重载配置 ``` nginx -s reload ``` # 实现效果 8096端口同正常emby一样,8097的端口访问的话实现的是直链效果。 最后修改:2021 年 06 月 14 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 0 如果觉得我的文章对你有用,请随意赞赏
8 条评论
不获取外挂字幕的地址吗?
nginx最新版本抛弃了js_include方式引入js,而是js_import。
那么nginx配置文件的js_include就应该变更为:
js_path /usr/local/nginx/conf/;
js_import emby2Pan from emby.js;
location处的js_content也应该在redirect2Pan前加emby.变成emby.redirect2Pan,以此类推。
最后在js脚本的最后加上
export default {redirect2Pan, redirectdown2Pan};
这样就可以兼容最新的nginx了
jellyfin适用吗
博主你好,我在修改nginx.conf后保存时报错,unknown directive "js_include",请问这是什么问题呢
"The directive was made obsolete in version 0.4.0 and was removed in version 0.7.1. The js_import directive should be used instead."
是否安装好插件以及js文件是否在同目录
大佬,这个网页版直链播放有解决办法吗
测试评论