1
0
mirror of https://github.com/hanxi/xiaomusic.git synced 2026-04-15 21:03:55 +08:00

feat: 增加均衡歌曲响度(可选) (#338)

可选下载和转换mp3时,是否均衡的歌曲响度,避免歌声忽大忽小。#336
This commit is contained in:
AisukaYuki
2024-12-29 19:40:10 +08:00
committed by GitHub
parent 52bce6af9d
commit 2c3a95b98d
5 changed files with 22 additions and 0 deletions

View File

@@ -97,6 +97,7 @@ class Config:
port: int = int(os.getenv("XIAOMUSIC_PORT", "8090")) # 监听端口
public_port: int = int(os.getenv("XIAOMUSIC_PUBLIC_PORT", 0)) # 歌曲访问端口
proxy: str = os.getenv("XIAOMUSIC_PROXY", None)
loudnorm: str = os.getenv("XIAOMUSIC_LOUDNORM", None) # 均衡音量参数
search_prefix: str = os.getenv(
"XIAOMUSIC_SEARCH", "bilisearch:"
) # "bilisearch:" or "ytsearch:"

View File

@@ -110,6 +110,9 @@ var vConsole = new window.VConsole();
<label for="proxy">XIAOMUSIC_PROXY(ytsearch需要):</label>
<input id="proxy" type="text" placeholder="http://192.168.2.5:8080" />
<label for="loudnorm">均衡歌曲音量大小(loudnorm滤镜):</label>
<input id="loudnorm" type="text" placeholder="loudnorm=I=-14:TP=-1.5:LRA=6" />
<label for="remove_id3tag">去除MP3 ID3v2和填充:</label>
<select id="remove_id3tag">
<option value="true">true</option>

View File

@@ -111,6 +111,9 @@ var vConsole = new window.VConsole();
<label for="proxy">XIAOMUSIC_PROXY(ytsearch需要):</label>
<input id="proxy" type="text" placeholder="http://192.168.2.5:8080" />
<label for="loudnorm">均衡歌曲音量大小(loudnorm滤镜):</label>
<input id="loudnorm" type="text" placeholder="loudnorm=I=-14:TP=-1.5:LRA=6" />
<label for="remove_id3tag">去除MP3 ID3v2和填充:</label>
<select id="remove_id3tag">
<option value="true">true</option>

View File

@@ -487,6 +487,11 @@ def convert_file_to_mp3(input_file: str, config) -> str:
log.info(f"File {out_file_path} already exists. Skipping convert_file_to_mp3.")
return relative_path
# 检查是否存在 loudnorm 参数
loudnorm_args = []
if config.loudnorm:
loudnorm_args = ["-af", config.loudnorm]
command = [
os.path.join(config.ffmpeg_location, "ffmpeg"),
"-i",
@@ -495,6 +500,7 @@ def convert_file_to_mp3(input_file: str, config) -> str:
"mp3",
"-vn",
"-y",
*loudnorm_args,
out_file_path,
]
@@ -895,6 +901,9 @@ async def download_playlist(config, url, dirname):
if config.enable_yt_dlp_cookies:
sbp_args += ("--cookies", f"{config.yt_dlp_cookies_path}")
if config.loudnorm:
sbp_args += ("--postprocessor-args", f"-af {config.loudnorm}")
sbp_args += (url,)
@@ -930,6 +939,9 @@ async def download_one_music(config, url, name=""):
if config.enable_yt_dlp_cookies:
sbp_args += ("--cookies", f"{config.yt_dlp_cookies_path}")
if config.loudnorm:
sbp_args += ("--postprocessor-args", f"-af {config.loudnorm}")
sbp_args += (url,)

View File

@@ -1724,6 +1724,9 @@ class XiaoMusicDevice:
if self.config.enable_yt_dlp_cookies:
sbp_args += ("--cookies", f"{self.config.yt_dlp_cookies_path}")
if self.config.loudnorm:
sbp_args += ("--postprocessor-args", f"-af {self.config.loudnorm}")
cmd = " ".join(sbp_args)
self.log.info(f"download cmd: {cmd}")