Telegram-Custom-Artwork-Api/services/netease.py

23 lines
656 B
Python
Raw Normal View History

2022-09-25 14:08:06 +00:00
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