From 436df47104052989ab508969f00549930e9b9d87 Mon Sep 17 00:00:00 2001 From: xiaoQQya Date: Sat, 15 Mar 2025 11:28:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Docker=20=E9=95=9C=E5=83=8F=E5=86=85?= =?UTF-8?q?=E7=BD=AE=20UnblockNeteaseMusic,=20=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E9=83=A8=E5=88=86=E6=97=A0=E7=89=88=E6=9D=83?= =?UTF-8?q?=E6=AD=8C=E6=9B=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 14 +++++++++++--- docker-compose.yml | 18 ++++++++++++++++++ docker-entrypoint.sh | 29 +++++++++++++++++++++++++++++ nginx.conf | 22 ++++++++++++++++++++++ 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 1afef4a..fa1a2c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,8 +23,16 @@ COPY --from=builder /app/out/renderer /usr/share/nginx/html COPY --from=builder /app/nginx.conf /etc/nginx/conf.d/default.conf -RUN apk add --no-cache npm +COPY --from=builder /app/docker-entrypoint.sh /docker-entrypoint.sh -RUN npm install -g NeteaseCloudMusicApi +RUN apk add --no-cache npm python3 youtube-dl \ + && npm install -g @unblockneteasemusic/server NeteaseCloudMusicApi \ + && wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp \ + && chmod +x /usr/local/bin/yt-dlp \ + && chmod +x /docker-entrypoint.sh -CMD nginx && npx NeteaseCloudMusicApi +ENV NODE_TLS_REJECT_UNAUTHORIZED=0 + +ENTRYPOINT ["/docker-entrypoint.sh"] + +CMD ["npx", "NeteaseCloudMusicApi"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7c7d19b..0885bb8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,3 +10,21 @@ services: ports: - 25884:25884 restart: always + environment: + # 所有变量都不是必填项 + # 网易云服务端 IP, 可在宿主机通过 ping music.163.com 获得 + - NETEASE_SERVER_IP=220.197.30.65 + # UnblockNeteaseMusic 使用的音源, 支持列表见 https://github.com/UnblockNeteaseMusic/server?tab=readme-ov-file#%E9%9F%B3%E6%BA%90%E6%B8%85%E5%8D%95 + - UNBLOCK_SOURCES=kugou kuwo bilibili + # 可添加 UnblockNeteaseMusic 支持的任何环境变量, 支持列表见 https://github.com/UnblockNeteaseMusic/server?tab=readme-ov-file#%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F + - ENABLE_FLAC=false + - ENABLE_HTTPDNS=false + - BLOCK_ADS=true + - DISABLE_UPGRADE_CHECK=false + - DEVELOPMENT=false + - FOLLOW_SOURCE_ORDER=true + - JSON_LOG=false + - NO_CACHE=false + - SELECT_MAX_BR=true + - LOG_LEVEL=info + - SEARCH_ALBUM=true diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..346dce6 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -e + +# start unblock service in the background +npx unblockneteasemusic -p 80:443 -s -f ${NETEASE_SERVER_IP:-220.197.30.65} -o ${UNBLOCK_SOURCES:-kugou kuwo bilibili} 2>&1 & + +# point the neteasemusic address to the unblock service +if ! grep -q "music.163.com" /etc/hosts; then + echo "127.0.0.1 music.163.com" >> /etc/hosts +fi +if ! grep -q "interface.music.163.com" /etc/hosts; then + echo "127.0.0.1 interface.music.163.com" >> /etc/hosts +fi +if ! grep -q "interface3.music.163.com" /etc/hosts; then + echo "127.0.0.1 interface3.music.163.com" >> /etc/hosts +fi +if ! grep -q "interface.music.163.com.163jiasu.com" /etc/hosts; then + echo "127.0.0.1 interface.music.163.com.163jiasu.com" >> /etc/hosts +fi +if ! grep -q "interface3.music.163.com.163jiasu.com" /etc/hosts; then + echo "127.0.0.1 interface3.music.163.com.163jiasu.com" >> /etc/hosts +fi + +# start the nginx daemon +nginx + +# start the main process +exec "$@" diff --git a/nginx.conf b/nginx.conf index 33811a3..2d6327f 100644 --- a/nginx.conf +++ b/nginx.conf @@ -15,6 +15,22 @@ server { rewrite ^(.*)$ /index.html last; } + location /api/netease/song/url/v1 { + proxy_buffers 16 64k; + proxy_buffer_size 128k; + proxy_busy_buffers_size 256k; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Host $remote_addr; + proxy_set_header X-NginX-Proxy true; + proxy_pass http://localhost:3000/song/url/v1; + + sub_filter '"url":"https://music.163.com' '"url":"/music/unblock'; + sub_filter_types application/json; + sub_filter_once off; + } + location /api/netease/ { proxy_buffers 16 64k; proxy_buffer_size 128k; @@ -26,4 +42,10 @@ server { proxy_set_header X-NginX-Proxy true; proxy_pass http://localhost:3000/; } + + location /music/unblock/ { + proxy_pass https://music.163.com/; + proxy_buffering off; + proxy_request_buffering off; + } }