|
| 1 | +# 导入API SDK Client类 |
| 2 | +import json |
| 3 | + |
| 4 | +from tikhub.http_client.api_client import APIClient |
| 5 | + |
| 6 | + |
| 7 | +class NetEaseCloudMusicAppV1: |
| 8 | + |
| 9 | + # 初始化 | Initialize |
| 10 | + def __init__(self, client: APIClient): |
| 11 | + self.client = client |
| 12 | + |
| 13 | + # 获取单一歌曲信息V1(信息更全)| Fetch one music information V1 (more information) |
| 14 | + async def fetch_one_music_v1(self, music_id: str): |
| 15 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_one_music_v1" |
| 16 | + data = await self.client.fetch_get_json(f"{endpoint}?music_id={music_id}") |
| 17 | + return data |
| 18 | + |
| 19 | + # 获取单一歌曲信息V2(信息更少)| Fetch one music information V2 (less information) |
| 20 | + async def fetch_one_music_v2(self, music_id: str): |
| 21 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_one_music_v2" |
| 22 | + data = await self.client.fetch_get_json(f"{endpoint}?music_id={music_id}") |
| 23 | + return data |
| 24 | + |
| 25 | + # 获取单一歌曲歌词/Fetch one music lyric |
| 26 | + async def fetch_one_music_lyric(self, music_id: str): |
| 27 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_one_music_lyric" |
| 28 | + data = await self.client.fetch_get_json(f"{endpoint}?music_id={music_id}") |
| 29 | + return data |
| 30 | + |
| 31 | + # 获取单一歌曲播放地址V1(只能返回MP3格式,支持参数较少)/Fetch one music URL V1 (only MP3 format is supported, with fewer parameters) |
| 32 | + async def fetch_one_music_url_v1(self, music_id: str, br: str = "192000"): |
| 33 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_one_music_url_v1" |
| 34 | + data = await self.client.fetch_get_json(f"{endpoint}?music_id={music_id}&br={br}") |
| 35 | + return data |
| 36 | + |
| 37 | + # 获取单一歌曲播放地址V2(支持更多参数)/Fetch one music URL V2 (support more parameters) |
| 38 | + async def fetch_one_music_url_v2(self, music_id: str, level: str = "exhigh", encodeType: str = "mp3"): |
| 39 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_one_music_url_v2" |
| 40 | + data = await self.client.fetch_get_json(f"{endpoint}?music_id={music_id}&level={level}&encodeType={encodeType}") |
| 41 | + return data |
| 42 | + |
| 43 | + # Mlog(音乐视频)播放地址/Mlog (music video) playback address |
| 44 | + async def fetch_music_log_video_url(self, mlogId: str, resolution: str = "1080"): |
| 45 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_music_log_video_url" |
| 46 | + data = await self.client.fetch_get_json(f"{endpoint}?mlogId={mlogId}&resolution={resolution}") |
| 47 | + return data |
| 48 | + |
| 49 | + # 获取歌曲评论/Fetch music comment |
| 50 | + async def fetch_music_comment(self, resource_id: str, beforeTime: str = "0", limit: str = "30"): |
| 51 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_music_comment" |
| 52 | + data = await self.client.fetch_get_json( |
| 53 | + f"{endpoint}?resource_id={resource_id}&beforeTime={beforeTime}&limit={limit}") |
| 54 | + return data |
| 55 | + |
| 56 | + # 搜索接口V1/Search interface V1 |
| 57 | + async def search_v1(self, keywords: str, offset: str = "0", limit: str = "20", _type: str = "1"): |
| 58 | + endpoint = "/api/v1/net_ease_cloud_music/app/search_v1" |
| 59 | + data = await self.client.fetch_get_json( |
| 60 | + f"{endpoint}?keywords={keywords}&offset={offset}&limit={limit}&type={_type}") |
| 61 | + return data |
| 62 | + |
| 63 | + # 获取用户歌单/Get user playlist |
| 64 | + async def fetch_user_playlist(self, uid: str, offset: str = "0", limit: str = "20"): |
| 65 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_user_playlist" |
| 66 | + data = await self.client.fetch_get_json(f"{endpoint}?uid={uid}&offset={offset}&limit={limit}") |
| 67 | + return data |
| 68 | + |
| 69 | + # 获取用户信息/Get user information |
| 70 | + async def fetch_user_info(self, uid: str): |
| 71 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_user_info" |
| 72 | + data = await self.client.fetch_get_json(f"{endpoint}?uid={uid}") |
| 73 | + return data |
| 74 | + |
| 75 | + # 获取用户动态/Fetch user event |
| 76 | + async def fetch_user_event(self, uid: str, _time: str = "-1", limit: str = "10"): |
| 77 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_user_event" |
| 78 | + data = await self.client.fetch_get_json(f"{endpoint}?uid={uid}&time={_time}&limit={limit}") |
| 79 | + return data |
| 80 | + |
| 81 | + # 获取用户粉丝列表/Fetch user followers |
| 82 | + async def fetch_user_followers(self, uid: str, lasttime: str = "0", pagesize: str = "20"): |
| 83 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_user_followers" |
| 84 | + data = await self.client.fetch_get_json(f"{endpoint}?uid={uid}&lasttime={lasttime}&pagesize={pagesize}") |
| 85 | + return data |
| 86 | + |
| 87 | + # 获取用户关注列表/Fetch user follows |
| 88 | + async def fetch_user_follows(self, uid: str, offset: str = "0", limit: str = "20"): |
| 89 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_user_follows" |
| 90 | + data = await self.client.fetch_get_json(f"{endpoint}?uid={uid}&offset={offset}&limit={limit}") |
| 91 | + return data |
| 92 | + |
| 93 | + # 获取歌手信息/Fetch artist detail |
| 94 | + async def fetch_artist_detail(self, artist_id: str): |
| 95 | + endpoint = "/api/v1/net_ease_cloud_music/app/fetch_artist_detail" |
| 96 | + data = await self.client.fetch_get_json(f"{endpoint}?artist_id={artist_id}") |
| 97 | + return data |
| 98 | + |
| 99 | + # 解密POST请求中的16进制payload/Decrypt the 16-bit payload in the POST request |
| 100 | + async def decrypt_post_payload(self, payload: str): |
| 101 | + endpoint = "/api/v1/net_ease_cloud_music/app/decrypt_post_payload" |
| 102 | + data = await self.client.fetch_post_json(endpoint, data=payload) |
| 103 | + return data |
| 104 | + |
| 105 | + # 加密POST请求中的payload并且返回16进制/Encrypt the payload in the POST request and return 16 hexadecimal |
| 106 | + async def encrypt_post_payload(self, uri: str, payload: dict, add_variable: bool = False): |
| 107 | + endpoint = "/api/v1/net_ease_cloud_music/app/encrypt_post_payload" |
| 108 | + endpoint = f"{endpoint}?uri={uri}&add_variable={add_variable}" |
| 109 | + data = await self.client.fetch_post_json(endpoint, data=json.dumps(payload)) |
| 110 | + return data |
0 commit comments