mirror of
https://github.com/hanxi/xiaomusic.git
synced 2025-12-07 15:02:55 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77ece713dc | ||
|
|
4436cc3a15 | ||
|
|
c875350112 | ||
|
|
d6df2f6bfe | ||
|
|
03e3312218 |
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "xiaomusic"
|
||||
version = "0.1.73"
|
||||
version = "0.1.75"
|
||||
description = "Play Music with xiaomi AI speaker"
|
||||
authors = [
|
||||
{name = "涵曦", email = "im.hanxi@gmail.com"},
|
||||
|
||||
@@ -1 +1 @@
|
||||
__version__ = "0.1.73"
|
||||
__version__ = "0.1.75"
|
||||
|
||||
@@ -79,6 +79,7 @@ class Config:
|
||||
use_music_api: bool = (
|
||||
os.getenv("XIAOMUSIC_USE_MUSIC_API", "false").lower() == "true"
|
||||
)
|
||||
log_file: str = os.getenv("XIAOMUSIC_MUSIC_LOG_FILE", "/tmp/xiaomusic.txt")
|
||||
|
||||
def append_keyword(self, keys, action):
|
||||
for key in keys.split(","):
|
||||
|
||||
@@ -3,6 +3,7 @@ SUPPORT_MUSIC_TYPE = [
|
||||
".flac",
|
||||
".wav",
|
||||
".ape",
|
||||
".ogg",
|
||||
]
|
||||
|
||||
LATEST_ASK_API = "https://userprofile.mina.mi.com/device_profile/v2/conversation?source=dialogu&hardware={hardware}×tamp={timestamp}&limit=2"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os
|
||||
from threading import Thread
|
||||
|
||||
from flask import Flask, request, send_from_directory
|
||||
from flask import Flask, request, send_from_directory, send_file
|
||||
from flask_httpauth import HTTPBasicAuth
|
||||
from waitress import serve
|
||||
|
||||
@@ -162,6 +162,10 @@ def downloadjson():
|
||||
"content": content,
|
||||
}
|
||||
|
||||
@app.route("/downloadlog", methods=["GET"])
|
||||
@auth.login_required
|
||||
def downloadlog():
|
||||
return send_file(xiaomusic.config.log_file, as_attachment=True)
|
||||
|
||||
def static_path_handler(filename):
|
||||
log.debug(filename)
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
<hr>
|
||||
|
||||
<a href="/static/m3u.html" target="_blank">m3u文件转换工具</a>
|
||||
<a href="/downloadlog" download="xiaomusic.txt">下载日志文件</a>
|
||||
|
||||
<footer>
|
||||
<p>Powered by <a href="https://github.com/hanxi/xiaomusic" target="_blank">xiaomusic</a></p>
|
||||
|
||||
@@ -10,7 +10,9 @@ import time
|
||||
import traceback
|
||||
import urllib.parse
|
||||
from pathlib import Path
|
||||
import copy
|
||||
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from aiohttp import ClientSession, ClientTimeout
|
||||
from miservice import MiAccount, MiIOService, MiNAService
|
||||
|
||||
@@ -91,14 +93,8 @@ class XiaoMusic:
|
||||
# 关机定时器
|
||||
self._stop_timer = None
|
||||
|
||||
# setup logger
|
||||
logging.basicConfig(
|
||||
format=f"%(asctime)s [{__version__}] [%(levelname)s] %(message)s",
|
||||
datefmt="[%X]",
|
||||
)
|
||||
self.log = logging.getLogger("xiaomusic")
|
||||
self.log.setLevel(logging.DEBUG if config.verbose else logging.INFO)
|
||||
self.log.debug(config)
|
||||
# 初始化日志
|
||||
self.setup_logger()
|
||||
|
||||
# 尝试从设置里加载配置
|
||||
self.try_init_setting()
|
||||
@@ -109,7 +105,28 @@ class XiaoMusic:
|
||||
# 启动时初始化获取声音
|
||||
self.set_last_record("get_volume#")
|
||||
|
||||
self.log.info("ffmpeg_location: %s", self.ffmpeg_location)
|
||||
def setup_logger(self):
|
||||
logging.basicConfig(
|
||||
format=f"%(asctime)s [{__version__}] [%(levelname)s] %(message)s",
|
||||
datefmt="[%X]",
|
||||
)
|
||||
|
||||
log_file = self.config.log_file
|
||||
log_path = os.path.dirname(log_file)
|
||||
if not os.path.exists(log_path):
|
||||
os.makedirs(log_path)
|
||||
if os.path.exists(log_file):
|
||||
os.remove(log_file)
|
||||
handler = RotatingFileHandler(self.config.log_file, maxBytes=10*1024*1024, backupCount=1)
|
||||
self.log = logging.getLogger("xiaomusic")
|
||||
self.log.addHandler(handler)
|
||||
self.log.setLevel(logging.DEBUG if self.config.verbose else logging.INFO)
|
||||
debug_config = copy.deepcopy(self.config)
|
||||
debug_config.account = '******'
|
||||
debug_config.password = '******'
|
||||
debug_config.httpauth_username = '******'
|
||||
debug_config.httpauth_password = '******'
|
||||
self.log.info(debug_config)
|
||||
|
||||
async def poll_latest_ask(self):
|
||||
async with ClientSession() as session:
|
||||
|
||||
Reference in New Issue
Block a user