Skip to content

Commit

Permalink
feat: 外网访问端口可独立配置
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Jul 4, 2024
1 parent 485a42a commit ce9adce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion xiaomusic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class Config:
music_path: str = os.getenv("XIAOMUSIC_MUSIC_PATH", "music")
conf_path: str = os.getenv("XIAOMUSIC_CONF_PATH", None)
hostname: str = os.getenv("XIAOMUSIC_HOSTNAME", "192.168.2.5")
port: int = int(os.getenv("XIAOMUSIC_PORT", "8090"))
port: int = int(os.getenv("XIAOMUSIC_PORT", "8090")) # 监听端口
public_port: int = int(os.getenv("XIAOMUSIC_PUBLIC_PORT", 0)) # 歌曲访问端口
proxy: str | None = os.getenv("XIAOMUSIC_PROXY", None)
search_prefix: str = os.getenv(
"XIAOMUSIC_SEARCH", "bilisearch:"
Expand Down
3 changes: 3 additions & 0 deletions xiaomusic/static/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ <h2>小爱音箱设置面板
<option value="false">false</option>
</select>

<label for="public_port">外网访问端口(0表示跟监听端口一致):</label>
<input id="public_port" type="number" value="0"></input>

<label for="stop_tts_msg">停止提示音:</label>
<input id="stop_tts_msg" type="text" value="收到,再见"></input>
<label for="keywords_playlocal">播放本地歌曲口令:</label>
Expand Down
6 changes: 5 additions & 1 deletion xiaomusic/xiaomusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def init_config(self):

self.hostname = self.config.hostname
self.port = self.config.port
self.public_port = self.config.public_port
if self.public_port == 0:
self.public_port = self.port

self.proxy = self.config.proxy
self.search_prefix = self.config.search_prefix
self.ffmpeg_location = self.config.ffmpeg_location
Expand Down Expand Up @@ -456,7 +460,7 @@ def get_music_url(self, name):
"get_music_url local music. name:%s, filename:%s", name, filename
)
encoded_name = urllib.parse.quote(filename)
return f"http://{self.hostname}:{self.port}/{encoded_name}"
return f"http://{self.hostname}:{self.public_port}/{encoded_name}"

# 递归获取目录下所有歌曲,生成随机播放列表
def _gen_all_music_list(self):
Expand Down

0 comments on commit ce9adce

Please sign in to comment.