hanxi / xiaomusic

使用小爱音箱播放音乐,音乐使用 yt-dlp 下载。
https://github.com/hanxi/xiaomusic
MIT License
904 stars 89 forks source link
music xiaoai xiaoai-speaker xiaomi

xiaomusic

GitHub License Docker Image Version Docker Pulls PyPI - Version PyPI - Downloads Python Version from PEP 621 TOML GitHub Release

使用小爱音箱播放音乐,音乐使用 yt-dlp 下载。

https://github.com/hanxi/xiaomusic

初次安装遇到问题请查阅 https://github.com/hanxi/xiaomusic/issues/99 上是否已经有解决办法。

最简配置运行

已经支持在 web 页面配置其他参数,docker compose 配置如下:

services:
  xiaomusic:
    image: hanxi/xiaomusic
    container_name: xiaomusic
    restart: unless-stopped
    ports:
      - 8090:8090
    volumes:
      - ./music:/app/music

对应的 docker 启动命令如下:

docker run -p 8090:8090 \
    -v ./music:/app/music \
    hanxi/xiaomusic

启动成功后,在 web 页面可以配置其他参数,带有 * 号的配置是必须要配置的,其他的用不上时不用修改。初次配置时需要在页面上输入小米账号和密码保存后才能获取到设备列表。

✨✨✨ 修改默认8090端口映射 ✨✨✨

如果需要修改 8090 端口为其他端口,比如 5678,需要这样配,3个数字都需要是 5678 。见 https://github.com/hanxi/xiaomusic/issues/19

services:
  xiaomusic:
    image: hanxi/xiaomusic
    container_name: xiaomusic
    restart: unless-stopped
    ports:
      - 5678:5678
    volumes:
      - ./music:/app/music
    environment:
      XIAOMUSIC_PORT: 5678

遇到问题可以去 web 设置页面底部点击【下载日志文件】按钮,然后搜索一下日志文件内容确保里面没有账号密码信息后(有就删除这些敏感信息),然后在提 issues 反馈问题时把下载的日志文件带上。

目前除了 XIAOMUSIC_PORT 只能在启动前配置,其他参数都可以在 web 网页里配置。

pip 方式安装运行

> pip install -U xiaomusic
> xiaomusic --help
 __  __  _                   __  __                 _
 \ \/ / (_)   __ _    ___   |  \/  |  _   _   ___  (_)   ___
  \  /  | |  / _` |  / _ \  | |\/| | | | | | / __| | |  / __|
  /  \  | | | (_| | | (_) | | |  | | | |_| | \__ \ | | | (__
 /_/\_\ |_|  \__,_|  \___/  |_|  |_|  \__,_| |___/ |_|  \___|
          XiaoMusic v0.1.92 by: github.com/hanxi

usage: xiaomusic [-h] [--port PORT] [--hardware HARDWARE] [--account ACCOUNT]
                 [--password PASSWORD] [--cookie COOKIE] [--verbose]
                 [--config CONFIG] [--ffmpeg_location FFMPEG_LOCATION]

options:
  -h, --help            show this help message and exit
  --port PORT           监听端口
  --hardware HARDWARE   小爱音箱型号
  --account ACCOUNT     xiaomi account
  --password PASSWORD   xiaomi password
  --cookie COOKIE       xiaomi cookie
  --verbose             show info
  --config CONFIG       config file path
  --ffmpeg_location FFMPEG_LOCATION
                        ffmpeg bin path
> xiaomusic --config config.json

其中 config.json 文件可以参考 config-example.json 文件配置。见 https://github.com/hanxi/xiaomusic/issues/94

不修改默认端口 8090 的情况下,只需要执行 xiaomusic 即可启动。

开发环境运行

export MI_USER="xxxxx"
export MI_PASS="xxxx"
export MI_DID=00000
export XIAOMUSIC_SEARCH='bilisearch:'

然后启动即可。默认监听了端口 8090 , 使用其他端口自行修改。

pdm run xiaomusic.py

支持口令

隐藏玩法: 对小爱同学说播放歌曲小猪佩奇的故事,会播放小猪佩奇的故事。

已测试支持的设备

型号 名称
L06A 小爱音箱
L07A Redmi小爱音箱 Play
S12/S12A/MDZ-25-DA 小米AI音箱
LX5A 小爱音箱 万能遥控版
LX05 小爱音箱Play(2019款)
L16A Xiaomi Sound
L17A Xiaomi Sound Pro
LX06 小爱音箱Pro
LX01 小爱音箱mini
L05B 小爱音箱Play
L05C 小米小爱音箱Play 增强版

型号与产品名称对照可以在这里查询 https://home.miot-spec.com/s/xiaomi.wifispeaker

如果你的设备支持播放,请反馈给我添加到支持列表里,谢谢。 目前应该所有设备类型都已经支持播放,有问题随时反馈。

支持音乐格式

本地音乐会搜索目录下上面格式的文件,下载的歌曲是 mp3 格式的。 已知 L05B L05C 不支持 flac 格式。

在 Docker 里使用

docker run -e MI_USER='your-xiaomi-account' \
    -e MI_PASS='your-xiaomi-password' \
    -e MI_DID='your-xiaomi-speaker-mid' \
    -e MI_HARDWARE='L07A' \
    -e XIAOMUSIC_PROXY='proxy-for-yt-dlp' \
    -e XIAOMUSIC_HOSTNAME=192.168.2.5 \
    -e XIAOMUSIC_SEARCH='bilisearch:' \
    -p 8090:8090 \
    -v ./music:/app/music hanxi/xiaomusic

XIAOMUSIC_PROXY 参数格式参考 yt-dlp 文档说明:

Use the specified HTTP/HTTPS/SOCKS proxy. To
enable SOCKS proxy, specify a proper scheme,
e.g. socks5://user:pass@127.0.0.1:1080/.
Pass in an empty string (--proxy "") for
direct connection

https://github.com/hanxi/xiaomusic/issues/2https://github.com/hanxi/xiaomusic/issues/11

本地编译Docker Image

docker build -t xiaomusic .

docker compose 示例

使用哔哩哔哩下载歌曲:

version: '3'

services:
  xiaomusic:
    image: hanxi/xiaomusic
    container_name: xiaomusic
    restart: unless-stopped
    ports:
      - 8090:8090
    volumes:
      - ./music:/app/music
    environment:
      MI_USER: '小米账号'
      MI_PASS: '小米密码'
      MI_DID: 00000
      MI_HARDWARE: 'L07A'
      XIAOMUSIC_SEARCH: 'bilisearch:'
      XIAOMUSIC_HOSTNAME: '192.168.2.5'

使用 youtobe 下载歌曲:

version: '3'

services:
  xiaomusic:
    image: hanxi/xiaomusic
    container_name: xiaomusic
    restart: unless-stopped
    ports:
      - 8090:8090
    volumes:
      - ./music:/app/music
    environment:
      MI_USER: '小米账号'
      MI_PASS: '小米密码'
      MI_DID: 00000
      MI_HARDWARE: 'L07A'
      XIAOMUSIC_SEARCH: 'ytsearch:'
      XIAOMUSIC_PROXY: 'http://192.168.2.5:8080'
      XIAOMUSIC_HOSTNAME: '192.168.2.5'

如果想让 setting.json 文件不存储到 music 目录,可以这样配,下面的示例会把 setting.json 文件放到容器的 /app/conf 目录且映射到本地的 ./conf 目录:

services:
  xiaomusic:
    image: hanxi/xiaomusic
    container_name: xiaomusic
    restart: unless-stopped
    ports:
      - 8090:8090
    volumes:
      - ./music:/app/music
      - ./conf:/app/conf
    environment:
      MI_USER: '小米账号'
      MI_PASS: '小米密码'
      XIAOMUSIC_HOSTNAME: 'docker 主机 ip'
      XIAOMUSIC_CONF_PATH: '/app/conf'

简易的控制面板

浏览器进入 http://192.168.2.5:8090

采用新的设置页面之后,必须在启动前配置的环境变量只剩下:

其他的这些可以在网页里配置:

网络歌单功能

可以配置一个 json 格式的歌单,支持电台和歌曲,也可以直接用别人分享的链接,同时配备了 m3u 文件格式转换工具,可以很方便的把 m3u 电台文件转换成网络歌单格式的 json 文件,具体用法见 https://github.com/hanxi/xiaomusic/issues/78

欢迎有想法的朋友们制作更多的歌单转换工具。

更多其他可选配置

高级篇

讨论区

感谢

Star History

Star History Chart

赞赏