Skip to content

Commit

Permalink
Merge pull request #417 from chen3861229/main
Browse files Browse the repository at this point in the history
feat(plex2Alist): 强制 Infuse 支持 strm 播放
  • Loading branch information
chen3861229 authored Nov 17, 2024
2 parents e3d672c + 38a8f36 commit d270300
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion emby2Alist/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
=> navicat 中双击打开 data.db 的 main 数据库 => 表 => 右侧 x_storages 双击
=> 通过 drive 字段将鼠标点击到 115 Cloud 上 => 点击右下角倒数第二行的表单视图
=> addition 字段 => json 字段的 "limit_rate" 属性并修改 : 后的数值
=> ctrl + s 保存/点击坐下角的对勾应用更改 => 关闭 data.db 连接
=> ctrl + s 保存/点击左下角的对勾应用更改 => 关闭 data.db 连接
=> 更名原始的 data.db 为 data.db.bak 进行备份
=> 将修改后的 data.db 传输到服务端 => 重新启动 alist 即可

Expand Down
11 changes: 6 additions & 5 deletions emby2Alist/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ services:
service.nginx-emby:
image: nginx:1.27.1
container_name: nginx-emby
deploy:
resources:
limits:
cpus: '0.50'
memory: 128M
# 需要 Docker Swarm 模式
# deploy:
# resources:
# limits:
# cpus: '0.50'
# memory: 128M
# 更改为默认host网络,纠正流量标识,直接占用宿主机端口,docker层会禁用端口映射
network_mode: host
# 如果需要使用bridge(桥接)网络,请取消ports(端口映射)注释,并注释network_mode
Expand Down
24 changes: 23 additions & 1 deletion plex2Alist/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@

### 文章更新记录

#### 2024-11-17

1.强制 Infuse 支持 strm 播放,当然这是实验性质的,因为修改了文件名后缀,绕过了白名单检测,
理论上任何程序都应该是实时取二进制文件头/魔术头判断文件类型,实测播放器应该都是这样工作的,
假如是使用 FFmpeg 的话,都是可以播放成功的

1.1 加上很久之前修改了 strm 的在 plex 的 Media/Part 对象的 container 字段填充了一个默认值 mp4 进行欺骗支持,
以上不区分客户端都进行了修改,此次仅针对 Infuse 客户端,强制修改了 Part 对象的 file 字段/文件地址,添加了 .mp4 后缀进行欺骗支持,
所以在媒体详情或日志或报文中发现 strm 的这两个字段信息有误的话,是预期修改结果,请无视

1.2 对比没有修改这两个字段进行欺骗的情况下,原本 plex 对于 strm 播放的支持不够完善,具体为
Web 端和官方 plex 客户端响应了 307 重定向(和 302 差不多意思),但是重定向地址为了安全考虑强制加了服务器的域名前缀,导致无法正常播放,
而响应给第三方播放器的重定向地址是正确的,理论上除 Infuse 外,其他第三方播放原生支持 strm 播放,不需要此反代修改

1.3 没欺骗 Infuse 前,这边简单测试 HamHub: 1.3.9(267) 是正常播放 strm 的,欺骗后 Infuse-Direct/8.0.3 也是支持了,
具体测试媒体为 mkv 1080p HEVC,文件名为 xxx.strm,只针对 Infuse 返回的 Part 对象的 file 字段/文件地址为,
xxx.strm.mp4, Infuse 中媒体的内封字幕也是兼容的可以切换

1.4 唯一缺点是开始播放会比较慢,大概 5-8 秒,这个没办法,plex 相对 emby 没有客户端首次播放 strm 后上报补充媒体信息的功能

1.5 另外测试发现 Infuse 对于 emby 是没有屏蔽 strm 文件的详情页的,只对 plex 禁用了,原因未知

#### 2024-11-11

1.115 最近风控比较严格, alist 驱动上前端能填写的最小值 1 已经无法匹配远端限流熔断策略,
Expand All @@ -14,7 +36,7 @@
=> navicat 中双击打开 data.db 的 main 数据库 => 表 => 右侧 x_storages 双击
=> 通过 drive 字段将鼠标点击到 115 Cloud 上 => 点击右下角倒数第二行的表单视图
=> addition 字段 => json 字段的 "limit_rate" 属性并修改 : 后的数值
=> ctrl + s 保存/点击坐下角的对勾应用更改 => 关闭 data.db 连接
=> ctrl + s 保存/点击左下角的对勾应用更改 => 关闭 data.db 连接
=> 更名原始的 data.db 为 data.db.bak 进行备份
=> 将修改后的 data.db 传输到服务端 => 重新启动 alist 即可

Expand Down
11 changes: 6 additions & 5 deletions plex2Alist/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ services:
service.nginx-plex:
image: nginx:1.27.1
container_name: nginx-plex
deploy:
resources:
limits:
cpus: '0.50'
memory: 128M
# 需要 Docker Swarm 模式
# deploy:
# resources:
# limits:
# cpus: '0.50'
# memory: 128M
# 更改为默认host网络,纠正流量标识,直接占用宿主机端口,docker层会禁用端口映射
network_mode: host
# 如果需要使用bridge(桥接)网络,请取消ports(端口映射)注释,并注释network_mode
Expand Down
4 changes: 2 additions & 2 deletions plex2Alist/nginx/conf.d/plex.conf
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ server {
proxy_pass_request_headers on;
add_header X-Proxy-Success true; # for debug
}
# PlexApiHandler, this REG see: https://regex101.com/r/spMXKP/2
location ~* ^/(hubs|library|status)/(sections/\d+($|/all)|metadata/\d+$|continueWatching|promoted$|sessions$) {
# PlexApiHandler, this REG see: https://regex101.com/r/spMXKP/3
location ~* ^\/(hubs|library|status)\/(sections\/\d+($|\/all)|metadata\/\d+($|\/children)|continueWatching|promoted$|sessions$) {
proxy_set_header Accept-Encoding "";
add_header X-Modify-Success true;
js_content plex2Pan.plexApiHandler;
Expand Down
12 changes: 9 additions & 3 deletions plex2Alist/nginx/conf.d/plex.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ async function fetchPlexFileFullName(downloadApiPath) {

async function fetchStrmInnerText(r) {
const plexHost = config.plexHost;
const api_key = r.args[util.ARGS.plexTokenKey];
const api_key = r.args[util.ARGS.plexTokenKey] || r.headersIn[util.ARGS.plexTokenKey];
const downloadApiPath = `${plexHost}${r.uri}?download=1&${util.ARGS.plexTokenKey}=${api_key}`;
try {
// fetch Api ignore nginx locations
Expand Down Expand Up @@ -445,7 +445,7 @@ async function plexApiHandler(r) {
method: r.method,
});
const contentType = subR.headersOut["Content-Type"];
//r.log(`plexApiHandler Content-Type Header: ${contentType}`);
r.log(`plexApiHandler Content-Type Header: ${contentType}`);
let bodyObj;
let sBody;
if (subR.status === 200) {
Expand Down Expand Up @@ -613,26 +613,32 @@ function fillMediaInfo(r, media, isXmlNode) {
}

function fillPartInfo(r, part, isXmlNode) {
// !!!important is MediaInfo, PartInfo is not important
if (!part) return;
// only strm file not have mediaContainer
// no real container required can playback, but subtitles maybe error
const defaultContainer = "mp4";
const defaultStream = [];
const isInfuse = r.headersIn["User-Agent"].includes("Infuse");
if (isXmlNode) {
if (!part.$attr$container) {
part.$attr$container = defaultContainer;
}
if (!part.$attr$Stream) {
part.$attr$Stream = defaultStream;
}
if (isInfuse && part.$attr$file.toLowerCase().endsWith(".strm")) {
part.$attr$file = part.$attr$file + `.${defaultContainer}`;
}
} else {
if (!part.container) {
part.container = defaultContainer;
}
if (!part.Stream) {
part.Stream = defaultStream;
}
if (isInfuse && part.file.toLowerCase().endsWith(".strm")) {
part.file = part.file + `.${defaultContainer}`;
}
}
}

Expand Down

0 comments on commit d270300

Please sign in to comment.