Skip to content

Commit

Permalink
feat: 🎸 修复流媒体URL无法访问的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
monlor committed May 31, 2024
1 parent dd932df commit 611c8ec
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
3 changes: 2 additions & 1 deletion alist/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ VOLUME /data
COPY ./start.sh /start.sh
COPY ./clear.sh /clear.sh
COPY ./update_media_addr.sh /update_media_addr.sh
COPY ./fix_media.sh /fix_media.sh

RUN chmod +x /start.sh /clear.sh /update_media_addr.sh
RUN chmod +x /start.sh /clear.sh /update_media_addr.sh /fix_media.sh

ENTRYPOINT [ "/start.sh" ]

Expand Down
66 changes: 66 additions & 0 deletions alist/fix_media.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

echo "等待emby.js创建完成..."
while ! test -f /etc/nginx/http.d/emby.js; do
sleep 2
done

sed -i '/async function fetchXYApi/{:a;N;$!ba;d}' /etc/nginx/http.d/emby.js

cat >> /etc/nginx/http.d/emby.js <<-\EOF
async function fetchXYApi(xyurl) {
let urlParts = xyurl.split('/');
let encodedParts = urlParts.map(part => encodeURIComponent(part));
xyurl = urlParts[0] + '//' + urlParts[2] + '/' + encodedParts.slice(3).join('/');
try {
const res = await ngx.fetch(xyurl, { headers: { 'Content-Type': 'application/json;charset=utf-8', "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.160 Safari/537.36" }, max_response_body_size: 365535} );
if (res.status == 302) {
if (res.statusText == "Found") {
return res.headers.Location;
}
return (`error: xy_api return 304 destination is null`);
}
else {
return res.text();
}
}
catch (error) {
return (`error: xy_api fetch aliyun direct link failed, ${error}`);
}
}
export default { redirect2Pan };
EOF



echo "等待jellyfin.js创建完成..."
while ! test -f /etc/nginx/http.d/jellyfin.js; do
sleep 2
done

sed -i '/async function fetchXYApi/{:a;N;$!ba;d}' /etc/nginx/http.d/jellyfin.js
cat >> /etc/nginx/http.d/jellyfin.js <<-\EOF
async function fetchXYApi(xyurl) {
let urlParts = xyurl.split('/');
let encodedParts = urlParts.map(part => encodeURIComponent(part));
xyurl = urlParts[0] + '//' + urlParts[2] + '/' + encodedParts.slice(3).join('/');
try {
const res = await ngx.fetch(xyurl, { headers: { 'Content-Type': 'application/json;charset=utf-8' }, max_response_body_size: 365535} );
if (res.status == 302) {
if (res.statusText == "Found") {
return res.headers.Location;
}
return (`error: xy_api return 304 destination is null`);
}
else {
return res.text();
}
}
catch (error) {
return (`error: xy_api fetch aliyun direct link failed, ${error}`);
}
}
export default { redirect2Pan };
EOF
2 changes: 2 additions & 0 deletions alist/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,6 @@ if [ "${AUTO_UPDATE_MEDIA_ADDR:=true}" = "true" ]; then
/update_media_addr.sh &> /dev/null &
fi

/fix_media.sh &

exec /entrypoint.sh /opt/alist/alist server --no-prefix

0 comments on commit 611c8ec

Please sign in to comment.