Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加锂API对接功能 #124

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mod/args/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
parser.add_argument('--auth', type=str, default='', help='用于验证Header.Authentication字段,建议纯ASCII字符')
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
parser.add_argument('--ip', type=str, default='*', help='服务器监听IP,默认*')
parser.add_argument('--token', type=str, default='', help='用于翻译歌词的API Token')
parser.add_argument('--token', type=str, default='', help='锂API接口的Token')
parser.add_argument('--ai-type', type=str, default='openai', help='AI类型,默认openai')
parser.add_argument('--ai-model', type=str, default='gpt-4o-mini', help='AI模型,默认gpt-4o-mini')
parser.add_argument('--ai-base-url', type=str, default='https://api.openai.com/v1', help='AI基础URL,默认https://api.openai.com/v1')
Expand Down Expand Up @@ -181,6 +181,7 @@ def __load_yaml() -> dict|None:
def __load_env(self):
auth = os.environ.get('API_AUTH', None)
port = os.environ.get('API_PORT', None)
api_token = os.environ.get('API_TOKEN', None)
ai_type = os.environ.get('API_AI_TYPE', None)
ai_model = os.environ.get('API_AI_MODEL', None)
ai_base_url = os.environ.get('API_AI_BASE', None)
Expand All @@ -191,6 +192,8 @@ def __load_env(self):
if not isinstance(self.__data.get("server"), dict):
self.__data["server"] = {"ip": "*"}
self.__data["server"]["port"] = port
if api_token:
self.__data["token"] = api_token
if not isinstance(self.__data.get("ai"), dict):
self.__data["ai"] = {}
if ai_type:
Expand All @@ -206,6 +209,7 @@ def __load_arg(self):
auth = kw_args.auth
port = kw_args.port
ip = kw_args.ip
token = kw_args.token
ai_type = kw_args.ai_type
ai_model = kw_args.ai_model
ai_base_url = kw_args.ai_base_url
Expand All @@ -221,6 +225,8 @@ def __load_arg(self):
if not isinstance(self.__data.get("server"), dict):
self.__data["server"] = {"ip": "*"}
self.__data["server"]["ip"] = ip
if token:
self.__data["token"] = token
if not isinstance(self.__data.get("ai"), dict):
self.__data["ai"] = {}
if ai_type:
Expand Down Expand Up @@ -253,7 +259,8 @@ def __call__(self, *args):
"ip": "*",
"port": 28883
},
"auth": {}
"auth": {},
"token": ""
}
config = Args(default=default)
~config
Expand Down
19 changes: 16 additions & 3 deletions mod/searchx/api.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import requests
import logging
from mod.args import args


logger = logging.getLogger(__name__)


headers = {
"Host": "127.0.0.1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 LrcAPI"
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 LrcAPI",
"Authorization": args("token")
}


def search(title='', artist='', album='') -> list:
try:
url = f"https://api.lrc.cx/jsonapi?title={title}&artist={artist}&album={album}&path=None&limit=1&api=lrcapi"
response = requests.get(url, headers=headers)
return response.json()
if response.status_code == 200:
return response.json()
elif response.status_code == 401:
logger.warning("锂API接口的Token无效,请检查配置")
return []
else:
logger.warning(f"锂API接口请求失败,状态码:{response.status_code}")
return []
except Exception as e:
print(f"LrcAPI Server - Request failed: {e}")
logger.error(f"锂API接口请求失败,错误:{e}")
return []


Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h3>合作伙伴支持</h3>
<div class="partner-links">
<a href="https://my.yecaoyun.com/aff.php?aff=3296" class="partner-link" target="_blank">年付99元-香港服务器</a>
<a href="https://duck2api.com/register?aff=DvUO" class="partner-link" target="_blank">低价ChatGPT/Claude/Gemini API</a>
<a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ" class="partner-link" target="_blank">Neo笛子舞高清完整版</a>
<a href="https://syyn.1.passwallwall.life/#/register?code=Ijz3jX5v" class="partner-link" target="_blank">299元终身无限流量-流媒体专线</a>
</div>
</div>
</div>
Expand Down