Telegram-Custom-Artwork-Api/services/netease.py
2022-09-25 22:08:06 +08:00

23 lines
656 B
Python

import contextlib
from typing import List
from pyncm import GetCurrentSession, apis
from defs import Music
class Netease:
@staticmethod
async def get(keyword: str) -> List[Music]:
# 海外用户
GetCurrentSession().headers["X-Real-IP"] = "118.88.88.88"
try:
req = apis.cloudsearch.GetSearchResult(keyword)
songs = req["result"]["songs"]
except Exception:
return []
results = []
for i in songs:
with contextlib.suppress(Exception):
results.append(Music(i["name"], i["al"]["picUrl"].replace("http:", "https:")))
return results