2023-06-14 14:31:21 +00:00
|
|
|
|
from core.builtins import Bot, Plain, Image
|
|
|
|
|
from core.component import module
|
|
|
|
|
from core.utils.http import get_url
|
|
|
|
|
|
2023-07-20 13:20:26 +00:00
|
|
|
|
|
2023-06-14 14:51:37 +00:00
|
|
|
|
ncmusic = module('ncmusic',
|
2023-06-14 14:31:21 +00:00
|
|
|
|
developers=['bugungu', 'DoroWolf'],
|
|
|
|
|
support_languages=['zh_cn'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ncmusic.handle('search <keyword> {{ncmusic.help.search}}')
|
|
|
|
|
async def search(msg: Bot.MessageSession, keyword: str):
|
2023-07-13 04:26:10 +00:00
|
|
|
|
url = f"https://autumnfish.cn/search?keywords={keyword}"
|
2023-06-14 14:31:21 +00:00
|
|
|
|
result = await get_url(url, 200, fmt='json')
|
|
|
|
|
|
|
|
|
|
if result['result']['songCount'] == 0:
|
|
|
|
|
await msg.finish(msg.locale.t('ncmusic.message.search.not_found'))
|
|
|
|
|
|
|
|
|
|
songs = result['result']['songs'][:10]
|
|
|
|
|
send_msg = msg.locale.t('ncmusic.message.search.result') + '\n'
|
|
|
|
|
|
|
|
|
|
for i, song in enumerate(songs, start=1):
|
|
|
|
|
send_msg += f"{i}. {song['name']}"
|
|
|
|
|
if 'transNames' in song:
|
|
|
|
|
send_msg += f"({' / '.join(song['transNames'] )})"
|
|
|
|
|
send_msg += f"——{' / '.join(artist['name'] for artist in song['artists'])}"
|
|
|
|
|
send_msg += f"《{song['album']['name']}》"
|
|
|
|
|
if 'transNames' in song['album']:
|
|
|
|
|
send_msg += f"({' / '.join(song['album']['transNames'])})"
|
|
|
|
|
send_msg += f"({song['id']})\n"
|
|
|
|
|
|
|
|
|
|
if len(result['result']['songs']) > 10:
|
2023-06-14 14:46:03 +00:00
|
|
|
|
send_msg += msg.locale.t('ncmusic.message.search.collapse')
|
2023-06-14 14:31:21 +00:00
|
|
|
|
|
2023-06-23 17:38:11 +00:00
|
|
|
|
await msg.finish(send_msg)
|
2023-06-14 14:31:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ncmusic.handle('info <sid> {{ncmusic.help.info}}')
|
|
|
|
|
async def info(msg: Bot.MessageSession, sid: str):
|
2023-07-13 04:26:10 +00:00
|
|
|
|
url = f"https://autumnfish.cn/song/detail?ids={sid}"
|
2023-06-14 14:31:21 +00:00
|
|
|
|
result = await get_url(url, 200, fmt='json')
|
|
|
|
|
|
|
|
|
|
info = result['songs'][0]
|
2023-06-14 14:51:37 +00:00
|
|
|
|
artist = ' / '.join([ar['name'] for ar in info['ar']])
|
2023-06-14 14:31:21 +00:00
|
|
|
|
song_page = f"https://music.163.com/#/song?id={info['id']}"
|
|
|
|
|
|
2023-06-14 14:51:37 +00:00
|
|
|
|
send_msg = msg.locale.t('ncmusic.message.info',
|
|
|
|
|
name=info['name'], id=info['id'],
|
|
|
|
|
album=info['al']['name'], album_id=info['al']['id'],
|
2023-06-14 14:31:21 +00:00
|
|
|
|
artists=artist, detail=song_page)
|
|
|
|
|
|
|
|
|
|
await msg.finish([Image(info['al']['picUrl']), Plain(send_msg)])
|